.
This commit is contained in:
16
grid.js
16
grid.js
@@ -97,7 +97,7 @@ Grid = class Grid {
|
||||
}
|
||||
|
||||
findAllIndices(func) {
|
||||
let points = []
|
||||
let points = [].pt
|
||||
this.forEach((e, pt, grid) => func(e, pt, grid) ? points.push(pt) : 0)
|
||||
return points
|
||||
}
|
||||
@@ -130,7 +130,7 @@ Grid = class Grid {
|
||||
static BFS_STOP = 1
|
||||
static BFS_END = 2
|
||||
|
||||
bfs(pt, func, neighbors = "getAdjNeighborsThat", getlimit = 1000) {
|
||||
bfs(pt, func, neighbors = "getAdjNeighborsThat", limit = 1000) {
|
||||
let visited = [].pt
|
||||
let toVisit = [pt].pt
|
||||
let count = 0
|
||||
@@ -144,14 +144,16 @@ Grid = class Grid {
|
||||
toVisit.sort()
|
||||
|
||||
for (let i = 0; i < toVisit.length; i++) {
|
||||
let result = func(this.get(toVisit[i]), toVisit[i], this, visited);
|
||||
let v = toVisit[i]
|
||||
|
||||
if (result == Grid.BFS_CONTINUE) {
|
||||
newToVisit.pushUniq(...this[neighbors](toVisit[i], (pt) => !pt.isIn(visited)).map((pt) => (pt.path = [...toVisit[i].path, pt], pt)))
|
||||
v.result = func(this.get(v), v, this, visited)
|
||||
|
||||
if (v.result == Grid.BFS_CONTINUE) {
|
||||
newToVisit.pushUniq(...this[neighbors](v, (pt) => !pt.isIn(visited)).map((pt) => (pt.path = [...v.path, pt], pt)))
|
||||
}
|
||||
|
||||
if (result == Grid.BFS_END) {
|
||||
end = toVisit[i]
|
||||
if (v.result == Grid.BFS_END) {
|
||||
end = v
|
||||
break out
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user