@codexo/exojs-pathfinding 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/esm/Pathfinder.d.ts +50 -0
- package/dist/esm/Pathfinder.d.ts.map +1 -0
- package/dist/esm/Pathfinder.js +151 -0
- package/dist/esm/Pathfinder.js.map +1 -0
- package/dist/esm/core/BinaryHeap.d.ts +2 -0
- package/dist/esm/core/BinaryHeap.d.ts.map +1 -0
- package/dist/esm/core/BinaryHeap.js +90 -0
- package/dist/esm/core/BinaryHeap.js.map +1 -0
- package/dist/esm/core/SearchState.d.ts +2 -0
- package/dist/esm/core/SearchState.d.ts.map +1 -0
- package/dist/esm/core/SearchState.js +66 -0
- package/dist/esm/core/SearchState.js.map +1 -0
- package/dist/esm/core/search.d.ts +2 -0
- package/dist/esm/core/search.d.ts.map +1 -0
- package/dist/esm/core/search.js +106 -0
- package/dist/esm/core/search.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/public.d.ts +7 -0
- package/dist/esm/public.d.ts.map +1 -0
- package/dist/esm/spaces/GridJumpExpansion.d.ts +2 -0
- package/dist/esm/spaces/GridJumpExpansion.d.ts.map +1 -0
- package/dist/esm/spaces/GridJumpExpansion.js +137 -0
- package/dist/esm/spaces/GridJumpExpansion.js.map +1 -0
- package/dist/esm/spaces/GridSpace.d.ts +131 -0
- package/dist/esm/spaces/GridSpace.d.ts.map +1 -0
- package/dist/esm/spaces/GridSpace.js +296 -0
- package/dist/esm/spaces/GridSpace.js.map +1 -0
- package/dist/esm/spaces/WaypointGraph.d.ts +79 -0
- package/dist/esm/spaces/WaypointGraph.d.ts.map +1 -0
- package/dist/esm/spaces/WaypointGraph.js +167 -0
- package/dist/esm/spaces/WaypointGraph.js.map +1 -0
- package/dist/esm/spaces/gridGeometry.d.ts +3 -0
- package/dist/esm/spaces/gridGeometry.d.ts.map +1 -0
- package/dist/esm/spaces/gridGeometry.js +40 -0
- package/dist/esm/spaces/gridGeometry.js.map +1 -0
- package/dist/esm/types.d.ts +182 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region src/core/search.ts
|
|
2
|
+
/**
|
|
3
|
+
* A* over a {@link NavigationSpace}, with an optional pruned expansion.
|
|
4
|
+
*
|
|
5
|
+
* Successors come either from `space.neighbors` or, when `expansion` is given,
|
|
6
|
+
* from a parent-dependent pruned generator. Both feed the same relaxation, so
|
|
7
|
+
* jump-point search is not a second solver: it is the same A* over a smaller
|
|
8
|
+
* successor set.
|
|
9
|
+
*
|
|
10
|
+
* `endNode` is the goal on success and otherwise the reachable node with the
|
|
11
|
+
* lowest heuristic, which is what makes both a budget-exceeded result and a
|
|
12
|
+
* snapped result a real path rather than an empty one.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
const runSearch = (state, space, start, goal, agentSize, maxExpandedNodes, expansion) => {
|
|
17
|
+
const { gScore, parent, closed, neighborNodes, neighborCosts, heap } = state;
|
|
18
|
+
state.begin();
|
|
19
|
+
state.touch(start);
|
|
20
|
+
gScore[start] = 0;
|
|
21
|
+
let bestNode = start;
|
|
22
|
+
let bestHeuristic = space.heuristic(start, goal);
|
|
23
|
+
let expandedNodes = 0;
|
|
24
|
+
heap.push(start, bestHeuristic);
|
|
25
|
+
while (heap.size > 0) {
|
|
26
|
+
const node = heap.pop();
|
|
27
|
+
if (closed[node] === 1) continue;
|
|
28
|
+
closed[node] = 1;
|
|
29
|
+
expandedNodes++;
|
|
30
|
+
if (node === goal) return {
|
|
31
|
+
status: "found",
|
|
32
|
+
endNode: goal,
|
|
33
|
+
cost: gScore[goal],
|
|
34
|
+
expandedNodes
|
|
35
|
+
};
|
|
36
|
+
const heuristic = space.heuristic(node, goal);
|
|
37
|
+
if (heuristic < bestHeuristic) {
|
|
38
|
+
bestHeuristic = heuristic;
|
|
39
|
+
bestNode = node;
|
|
40
|
+
}
|
|
41
|
+
if (maxExpandedNodes > 0 && expandedNodes >= maxExpandedNodes) return {
|
|
42
|
+
status: "budget-exceeded",
|
|
43
|
+
endNode: bestNode,
|
|
44
|
+
cost: gScore[bestNode],
|
|
45
|
+
expandedNodes
|
|
46
|
+
};
|
|
47
|
+
const count = expansion === null ? space.neighbors(node, agentSize, neighborNodes, neighborCosts) : expansion.successors(node, parent[node], goal, neighborNodes, neighborCosts);
|
|
48
|
+
const nodeCost = gScore[node];
|
|
49
|
+
for (let i = 0; i < count; i++) {
|
|
50
|
+
const next = neighborNodes[i];
|
|
51
|
+
state.touch(next);
|
|
52
|
+
if (closed[next] === 1) continue;
|
|
53
|
+
const tentative = nodeCost + neighborCosts[i];
|
|
54
|
+
if (tentative >= gScore[next]) continue;
|
|
55
|
+
gScore[next] = tentative;
|
|
56
|
+
parent[next] = node;
|
|
57
|
+
heap.push(next, tentative + space.heuristic(next, goal));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
status: "unreachable",
|
|
62
|
+
endNode: bestNode,
|
|
63
|
+
cost: gScore[bestNode],
|
|
64
|
+
expandedNodes
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Dijkstra flood from `origin`, appending every settled node and its cost to
|
|
69
|
+
* the output arrays in settle order.
|
|
70
|
+
*
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
const runFlood = (state, space, origin, agentSize, maxCost, maxExpandedNodes, outNodes, outCosts) => {
|
|
74
|
+
const { gScore, closed, neighborNodes, neighborCosts, heap } = state;
|
|
75
|
+
state.begin();
|
|
76
|
+
state.touch(origin);
|
|
77
|
+
gScore[origin] = 0;
|
|
78
|
+
heap.push(origin, 0);
|
|
79
|
+
let expandedNodes = 0;
|
|
80
|
+
while (heap.size > 0) {
|
|
81
|
+
const node = heap.pop();
|
|
82
|
+
if (closed[node] === 1) continue;
|
|
83
|
+
const cost = gScore[node];
|
|
84
|
+
if (cost > maxCost) break;
|
|
85
|
+
closed[node] = 1;
|
|
86
|
+
expandedNodes++;
|
|
87
|
+
outNodes.push(node);
|
|
88
|
+
outCosts.push(cost);
|
|
89
|
+
if (maxExpandedNodes > 0 && expandedNodes >= maxExpandedNodes) break;
|
|
90
|
+
const count = space.neighbors(node, agentSize, neighborNodes, neighborCosts);
|
|
91
|
+
for (let i = 0; i < count; i++) {
|
|
92
|
+
const next = neighborNodes[i];
|
|
93
|
+
state.touch(next);
|
|
94
|
+
if (closed[next] === 1) continue;
|
|
95
|
+
const tentative = cost + neighborCosts[i];
|
|
96
|
+
if (tentative >= gScore[next] || tentative > maxCost) continue;
|
|
97
|
+
gScore[next] = tentative;
|
|
98
|
+
heap.push(next, tentative);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return expandedNodes;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
export { runFlood, runSearch };
|
|
106
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","names":[],"sources":["../../../src/core/search.ts"],"sourcesContent":["import type { NavigationSpace, PathStatus, PrunedExpansion } from '../types';\nimport type { SearchState } from './SearchState';\n\n/** What a completed search leaves behind for path reconstruction. @internal */\nexport interface SearchOutcome {\n status: PathStatus;\n /** Goal node when the goal was reached, otherwise the best node seen. */\n endNode: number;\n cost: number;\n expandedNodes: number;\n}\n\n/**\n * A* over a {@link NavigationSpace}, with an optional pruned expansion.\n *\n * Successors come either from `space.neighbors` or, when `expansion` is given,\n * from a parent-dependent pruned generator. Both feed the same relaxation, so\n * jump-point search is not a second solver: it is the same A* over a smaller\n * successor set.\n *\n * `endNode` is the goal on success and otherwise the reachable node with the\n * lowest heuristic, which is what makes both a budget-exceeded result and a\n * snapped result a real path rather than an empty one.\n *\n * @internal\n */\nexport const runSearch = (\n state: SearchState,\n space: NavigationSpace,\n start: number,\n goal: number,\n agentSize: number,\n maxExpandedNodes: number,\n expansion: PrunedExpansion | null,\n): SearchOutcome => {\n const { gScore, parent, closed, neighborNodes, neighborCosts, heap } = state;\n\n state.begin();\n state.touch(start);\n gScore[start] = 0;\n\n let bestNode = start;\n let bestHeuristic = space.heuristic(start, goal);\n let expandedNodes = 0;\n\n heap.push(start, bestHeuristic);\n\n while (heap.size > 0) {\n const node = heap.pop();\n\n if (closed[node] === 1) continue;\n\n closed[node] = 1;\n expandedNodes++;\n\n if (node === goal) {\n return { status: 'found', endNode: goal, cost: gScore[goal]!, expandedNodes };\n }\n\n const heuristic = space.heuristic(node, goal);\n\n if (heuristic < bestHeuristic) {\n bestHeuristic = heuristic;\n bestNode = node;\n }\n\n if (maxExpandedNodes > 0 && expandedNodes >= maxExpandedNodes) {\n return { status: 'budget-exceeded', endNode: bestNode, cost: gScore[bestNode]!, expandedNodes };\n }\n\n const count =\n expansion === null\n ? space.neighbors(node, agentSize, neighborNodes, neighborCosts)\n : expansion.successors(node, parent[node]!, goal, neighborNodes, neighborCosts);\n const nodeCost = gScore[node]!;\n\n for (let i = 0; i < count; i++) {\n const next = neighborNodes[i]!;\n\n state.touch(next);\n\n if (closed[next] === 1) continue;\n\n const tentative = nodeCost + neighborCosts[i]!;\n\n if (tentative >= gScore[next]!) continue;\n\n gScore[next] = tentative;\n parent[next] = node;\n heap.push(next, tentative + space.heuristic(next, goal));\n }\n }\n\n return { status: 'unreachable', endNode: bestNode, cost: gScore[bestNode]!, expandedNodes };\n};\n\n/**\n * Dijkstra flood from `origin`, appending every settled node and its cost to\n * the output arrays in settle order.\n *\n * @internal\n */\nexport const runFlood = (\n state: SearchState,\n space: NavigationSpace,\n origin: number,\n agentSize: number,\n maxCost: number,\n maxExpandedNodes: number,\n outNodes: number[],\n outCosts: number[],\n): number => {\n const { gScore, closed, neighborNodes, neighborCosts, heap } = state;\n\n state.begin();\n state.touch(origin);\n gScore[origin] = 0;\n heap.push(origin, 0);\n\n let expandedNodes = 0;\n\n while (heap.size > 0) {\n const node = heap.pop();\n\n if (closed[node] === 1) continue;\n\n const cost = gScore[node]!;\n\n if (cost > maxCost) break;\n\n closed[node] = 1;\n expandedNodes++;\n outNodes.push(node);\n outCosts.push(cost);\n\n if (maxExpandedNodes > 0 && expandedNodes >= maxExpandedNodes) break;\n\n const count = space.neighbors(node, agentSize, neighborNodes, neighborCosts);\n\n for (let i = 0; i < count; i++) {\n const next = neighborNodes[i]!;\n\n state.touch(next);\n\n if (closed[next] === 1) continue;\n\n const tentative = cost + neighborCosts[i]!;\n\n if (tentative >= gScore[next]! || tentative > maxCost) continue;\n\n gScore[next] = tentative;\n heap.push(next, tentative);\n }\n }\n\n return expandedNodes;\n};\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,aACX,OACA,OACA,OACA,MACA,WACA,kBACA,cACkB;CAClB,MAAM,EAAE,QAAQ,QAAQ,QAAQ,eAAe,eAAe,SAAS;CAEvE,MAAM,MAAM;CACZ,MAAM,MAAM,KAAK;CACjB,OAAO,SAAS;CAEhB,IAAI,WAAW;CACf,IAAI,gBAAgB,MAAM,UAAU,OAAO,IAAI;CAC/C,IAAI,gBAAgB;CAEpB,KAAK,KAAK,OAAO,aAAa;CAE9B,OAAO,KAAK,OAAO,GAAG;EACpB,MAAM,OAAO,KAAK,IAAI;EAEtB,IAAI,OAAO,UAAU,GAAG;EAExB,OAAO,QAAQ;EACf;EAEA,IAAI,SAAS,MACX,OAAO;GAAE,QAAQ;GAAS,SAAS;GAAM,MAAM,OAAO;GAAQ;EAAc;EAG9E,MAAM,YAAY,MAAM,UAAU,MAAM,IAAI;EAE5C,IAAI,YAAY,eAAe;GAC7B,gBAAgB;GAChB,WAAW;EACb;EAEA,IAAI,mBAAmB,KAAK,iBAAiB,kBAC3C,OAAO;GAAE,QAAQ;GAAmB,SAAS;GAAU,MAAM,OAAO;GAAY;EAAc;EAGhG,M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Aa,OAAO,SAAU,YAAY,SAAS;GAEvD,OAAO,QAAQ;GACf,KAAK,KAAK,MAAM,SAAS;EAC3B;CACF;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Pathfinder } from './Pathfinder';
|
|
2
|
+
export type { DiagonalPolicy, GridSpaceOptions } from './spaces/GridSpace';
|
|
3
|
+
export { GridSpace } from './spaces/GridSpace';
|
|
4
|
+
export type { WaypointEdgeOptions } from './spaces/WaypointGraph';
|
|
5
|
+
export { WaypointGraph } from './spaces/WaypointGraph';
|
|
6
|
+
export type { FindPathOptions, FloodOptions, FloodRegion, NavigationSpace, PathEdge, PathResult, PathStatus, PrunedExpansion } from './types';
|
|
7
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/public.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GridJumpExpansion.d.ts","sourceRoot":"","sources":["../../../src/spaces/GridJumpExpansion.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { DIRECTION_X, DIRECTION_Y, runLength } from "./gridGeometry.js";
|
|
2
|
+
|
|
3
|
+
//#region src/spaces/GridJumpExpansion.ts
|
|
4
|
+
/**
|
|
5
|
+
* Jump-point search over a uniform-cost grid with corner cutting disallowed.
|
|
6
|
+
*
|
|
7
|
+
* Instead of every walkable neighbour, a node reports only the *jump points*
|
|
8
|
+
* reachable from it: the first cell along each surviving direction where the
|
|
9
|
+
* obstacle layout makes a turn worth considering. Everything between two jump
|
|
10
|
+
* points is a forced straight or diagonal run, so the search skips it entirely
|
|
11
|
+
* and expands orders of magnitude fewer nodes for the same optimal path.
|
|
12
|
+
*
|
|
13
|
+
* The pruning rules below are the corner-cutting-free ones and differ from the
|
|
14
|
+
* textbook formulation, which assumes a diagonal may pass between two blocked
|
|
15
|
+
* cells. Under the stricter rule the step into a node guarantees that both
|
|
16
|
+
* cells beside its predecessor are walkable, so a diagonal step has no forced
|
|
17
|
+
* neighbours at all, and a straight step gains them from the cell diagonally
|
|
18
|
+
* *behind* it being blocked rather than the one beside it.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
var GridJumpExpansion = class {
|
|
23
|
+
costs;
|
|
24
|
+
width;
|
|
25
|
+
height;
|
|
26
|
+
constructor(costs, width, height) {
|
|
27
|
+
this.costs = costs;
|
|
28
|
+
this.width = width;
|
|
29
|
+
this.height = height;
|
|
30
|
+
}
|
|
31
|
+
successors(node, parent, goal, outNodes, outCosts) {
|
|
32
|
+
const { width } = this;
|
|
33
|
+
const x = node % width;
|
|
34
|
+
const y = node / width | 0;
|
|
35
|
+
const goalX = goal % width;
|
|
36
|
+
const goalY = goal / width | 0;
|
|
37
|
+
let count = 0;
|
|
38
|
+
if (parent < 0) {
|
|
39
|
+
for (let direction = 0; direction < 8; direction++) count = this.emit(x, y, DIRECTION_X[direction], DIRECTION_Y[direction], goalX, goalY, outNodes, outCosts, count);
|
|
40
|
+
return count;
|
|
41
|
+
}
|
|
42
|
+
const stepX = Math.sign(x - parent % width);
|
|
43
|
+
const stepY = Math.sign(y - (parent / width | 0));
|
|
44
|
+
if (stepX !== 0 && stepY !== 0) {
|
|
45
|
+
count = this.emit(x, y, stepX, 0, goalX, goalY, outNodes, outCosts, count);
|
|
46
|
+
count = this.emit(x, y, 0, stepY, goalX, goalY, outNodes, outCosts, count);
|
|
47
|
+
return this.emit(x, y, stepX, stepY, goalX, goalY, outNodes, outCosts, count);
|
|
48
|
+
}
|
|
49
|
+
if (stepY === 0) {
|
|
50
|
+
count = this.emit(x, y, stepX, 0, goalX, goalY, outNodes, outCosts, count);
|
|
51
|
+
if (!this.walkable(x - stepX, y + 1)) {
|
|
52
|
+
count = this.emit(x, y, 0, 1, goalX, goalY, outNodes, outCosts, count);
|
|
53
|
+
count = this.emit(x, y, stepX, 1, goalX, goalY, outNodes, outCosts, count);
|
|
54
|
+
}
|
|
55
|
+
if (!this.walkable(x - stepX, y - 1)) {
|
|
56
|
+
count = this.emit(x, y, 0, -1, goalX, goalY, outNodes, outCosts, count);
|
|
57
|
+
count = this.emit(x, y, stepX, -1, goalX, goalY, outNodes, outCosts, count);
|
|
58
|
+
}
|
|
59
|
+
return count;
|
|
60
|
+
}
|
|
61
|
+
count = this.emit(x, y, 0, stepY, goalX, goalY, outNodes, outCosts, count);
|
|
62
|
+
if (!this.walkable(x + 1, y - stepY)) {
|
|
63
|
+
count = this.emit(x, y, 1, 0, goalX, goalY, outNodes, outCosts, count);
|
|
64
|
+
count = this.emit(x, y, 1, stepY, goalX, goalY, outNodes, outCosts, count);
|
|
65
|
+
}
|
|
66
|
+
if (!this.walkable(x - 1, y - stepY)) {
|
|
67
|
+
count = this.emit(x, y, -1, 0, goalX, goalY, outNodes, outCosts, count);
|
|
68
|
+
count = this.emit(x, y, -1, stepY, goalX, goalY, outNodes, outCosts, count);
|
|
69
|
+
}
|
|
70
|
+
return count;
|
|
71
|
+
}
|
|
72
|
+
expand(from, to, out) {
|
|
73
|
+
const { width } = this;
|
|
74
|
+
const targetX = to % width;
|
|
75
|
+
const targetY = to / width | 0;
|
|
76
|
+
let x = from % width;
|
|
77
|
+
let y = from / width | 0;
|
|
78
|
+
const stepX = Math.sign(targetX - x);
|
|
79
|
+
const stepY = Math.sign(targetY - y);
|
|
80
|
+
while (x !== targetX || y !== targetY) {
|
|
81
|
+
x += stepX;
|
|
82
|
+
y += stepY;
|
|
83
|
+
out.push(y * width + x);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
walkable(x, y) {
|
|
87
|
+
if (x < 0 || y < 0 || x >= this.width || y >= this.height) return false;
|
|
88
|
+
return this.costs[y * this.width + x] > 0;
|
|
89
|
+
}
|
|
90
|
+
emit(x, y, stepX, stepY, goalX, goalY, outNodes, outCosts, count) {
|
|
91
|
+
const jump = this.jump(x, y, stepX, stepY, goalX, goalY);
|
|
92
|
+
if (jump < 0) return count;
|
|
93
|
+
outNodes[count] = jump;
|
|
94
|
+
outCosts[count] = runLength(Math.abs(jump % this.width - x), Math.abs((jump / this.width | 0) - y));
|
|
95
|
+
return count + 1;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Runs from `(x, y)` in one direction until it hits the goal, a cell with a
|
|
99
|
+
* forced neighbour, or a wall. Returns the node it stopped on, or `-1` when
|
|
100
|
+
* the run died against an obstacle without passing anything worth expanding.
|
|
101
|
+
*/
|
|
102
|
+
jump(x, y, stepX, stepY, goalX, goalY) {
|
|
103
|
+
const { width } = this;
|
|
104
|
+
let currentX = x;
|
|
105
|
+
let currentY = y;
|
|
106
|
+
for (;;) {
|
|
107
|
+
const nextX = currentX + stepX;
|
|
108
|
+
const nextY = currentY + stepY;
|
|
109
|
+
if (!this.walkable(nextX, nextY)) return -1;
|
|
110
|
+
if (stepX !== 0 && stepY !== 0 && (!this.walkable(nextX, currentY) || !this.walkable(currentX, nextY))) return -1;
|
|
111
|
+
if (nextX === goalX && nextY === goalY) return nextY * width + nextX;
|
|
112
|
+
if (stepY === 0) {
|
|
113
|
+
if (this.forcedBeside(currentX, nextX, nextY, 1) || this.forcedBeside(currentX, nextX, nextY, -1)) return nextY * width + nextX;
|
|
114
|
+
} else if (stepX === 0) {
|
|
115
|
+
if (this.forcedAbove(currentY, nextY, nextX, 1) || this.forcedAbove(currentY, nextY, nextX, -1)) return nextY * width + nextX;
|
|
116
|
+
} else if (this.jump(nextX, nextY, stepX, 0, goalX, goalY) >= 0 || this.jump(nextX, nextY, 0, stepY, goalX, goalY) >= 0) return nextY * width + nextX;
|
|
117
|
+
currentX = nextX;
|
|
118
|
+
currentY = nextY;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Horizontal run: the cell beside the node is only worth turning into when
|
|
123
|
+
* the cell diagonally behind it is blocked, because otherwise the predecessor
|
|
124
|
+
* reaches it at least as cheaply without passing through this node.
|
|
125
|
+
*/
|
|
126
|
+
forcedBeside(previousX, x, y, side) {
|
|
127
|
+
return !this.walkable(previousX, y + side) && this.walkable(x, y + side);
|
|
128
|
+
}
|
|
129
|
+
/** Vertical run; the mirror of {@link forcedBeside}. */
|
|
130
|
+
forcedAbove(previousY, y, x, side) {
|
|
131
|
+
return !this.walkable(x + side, previousY) && this.walkable(x + side, y);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
export { GridJumpExpansion };
|
|
137
|
+
//# sourceMappingURL=GridJumpExpansion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GridJumpExpansion.js","names":[],"sources":["../../../src/spaces/GridJumpExpansion.ts"],"sourcesContent":["import type { PrunedExpansion } from '../types';\nimport { DIRECTION_X, DIRECTION_Y, runLength } from './gridGeometry';\n\n/**\n * Jump-point search over a uniform-cost grid with corner cutting disallowed.\n *\n * Instead of every walkable neighbour, a node reports only the *jump points*\n * reachable from it: the first cell along each surviving direction where the\n * obstacle layout makes a turn worth considering. Everything between two jump\n * points is a forced straight or diagonal run, so the search skips it entirely\n * and expands orders of magnitude fewer nodes for the same optimal path.\n *\n * The pruning rules below are the corner-cutting-free ones and differ from the\n * textbook formulation, which assumes a diagonal may pass between two blocked\n * cells. Under the stricter rule the step into a node guarantees that both\n * cells beside its predecessor are walkable, so a diagonal step has no forced\n * neighbours at all, and a straight step gains them from the cell diagonally\n * *behind* it being blocked rather than the one beside it.\n *\n * @internal\n */\nexport class GridJumpExpansion implements PrunedExpansion {\n private readonly costs: Float32Array;\n private readonly width: number;\n private readonly height: number;\n\n public constructor(costs: Float32Array, width: number, height: number) {\n this.costs = costs;\n this.width = width;\n this.height = height;\n }\n\n public successors(node: number, parent: number, goal: number, outNodes: Int32Array, outCosts: Float64Array): number {\n const { width } = this;\n const x = node % width;\n const y = (node / width) | 0;\n const goalX = goal % width;\n const goalY = (goal / width) | 0;\n\n let count = 0;\n\n if (parent < 0) {\n for (let direction = 0; direction < 8; direction++) {\n count = this.emit(x, y, DIRECTION_X[direction]!, DIRECTION_Y[direction]!, goalX, goalY, outNodes, outCosts, count);\n }\n\n return count;\n }\n\n const stepX = Math.sign(x - (parent % width));\n const stepY = Math.sign(y - ((parent / width) | 0));\n\n if (stepX !== 0 && stepY !== 0) {\n count = this.emit(x, y, stepX, 0, goalX, goalY, outNodes, outCosts, count);\n count = this.emit(x, y, 0, stepY, goalX, goalY, outNodes, outCosts, count);\n\n return this.emit(x, y, stepX, stepY, goalX, goalY, outNodes, outCosts, count);\n }\n\n // The side loops below are unrolled rather than iterated: this runs once per\n // expanded node, and a `for...of` over a two-element array would allocate a\n // fresh iterator every time.\n if (stepY === 0) {\n count = this.emit(x, y, stepX, 0, goalX, goalY, outNodes, outCosts, count);\n\n if (!this.walkable(x - stepX, y + 1)) {\n count = this.emit(x, y, 0, 1, goalX, goalY, outNodes, outCosts, count);\n count = this.emit(x, y, stepX, 1, goalX, goalY, outNodes, outCosts, count);\n }\n\n if (!this.walkable(x - stepX, y - 1)) {\n count = this.emit(x, y, 0, -1, goalX, goalY, outNodes, outCosts, count);\n count = this.emit(x, y, stepX, -1, goalX, goalY, outNodes, outCosts, count);\n }\n\n return count;\n }\n\n count = this.emit(x, y, 0, stepY, goalX, goalY, outNodes, outCosts, count);\n\n if (!this.walkable(x + 1, y - stepY)) {\n count = this.emit(x, y, 1, 0, goalX, goalY, outNodes, outCosts, count);\n count = this.emit(x, y, 1, stepY, goalX, goalY, outNodes, outCosts, count);\n }\n\n if (!this.walkable(x - 1, y - stepY)) {\n count = this.emit(x, y, -1, 0, goalX, goalY, outNodes, outCosts, count);\n count = this.emit(x, y, -1, stepY, goalX, goalY, outNodes, outCosts, count);\n }\n\n return count;\n }\n\n public expand(from: number, to: number, out: number[]): void {\n const { width } = this;\n const targetX = to % width;\n const targetY = (to / width) | 0;\n\n let x = from % width;\n let y = (from / width) | 0;\n\n const stepX = Math.sign(targetX - x);\n const stepY = Math.sign(targetY - y);\n\n while (x !== targetX || y !== targetY) {\n x += stepX;\n y += stepY;\n out.push(y * width + x);\n }\n }\n\n private walkable(x: number, y: number): boolean {\n if (x < 0 || y < 0 || x >= this.width || y >= this.height) return false;\n\n return this.costs[y * this.width + x]! > 0;\n }\n\n private emit(\n x: number,\n y: number,\n stepX: number,\n stepY: number,\n goalX: number,\n goalY: number,\n outNodes: Int32Array,\n outCosts: Float64Array,\n count: number,\n ): number {\n const jump = this.jump(x, y, stepX, stepY, goalX, goalY);\n\n if (jump < 0) return count;\n\n outNodes[count] = jump;\n outCosts[count] = runLength(Math.abs((jump % this.width) - x), Math.abs(((jump / this.width) | 0) - y));\n\n return count + 1;\n }\n\n /**\n * Runs from `(x, y)` in one direction until it hits the goal, a cell with a\n * forced neighbour, or a wall. Returns the node it stopped on, or `-1` when\n * the run died against an obstacle without passing anything worth expanding.\n */\n private jump(x: number, y: number, stepX: number, stepY: number, goalX: number, goalY: number): number {\n const { width } = this;\n\n let currentX = x;\n let currentY = y;\n\n for (;;) {\n const nextX = currentX + stepX;\n const nextY = currentY + stepY;\n\n if (!this.walkable(nextX, nextY)) return -1;\n if (stepX !== 0 && stepY !== 0 && (!this.walkable(nextX, currentY) || !this.walkable(currentX, nextY))) return -1;\n if (nextX === goalX && nextY === goalY) return nextY * width + nextX;\n\n if (stepY === 0) {\n if (this.forcedBeside(currentX, nextX, nextY, 1) || this.forcedBeside(currentX, nextX, nextY, -1)) return nextY * width + nextX;\n } else if (stepX === 0) {\n if (this.forcedAbove(currentY, nextY, nextX, 1) || this.forcedAbove(currentY, nextY, nextX, -1)) return nextY * width + nextX;\n } else if (this.jump(nextX, nextY, stepX, 0, goalX, goalY) >= 0 || this.jump(nextX, nextY, 0, stepY, goalX, goalY) >= 0) {\n return nextY * width + nextX;\n }\n\n currentX = nextX;\n currentY = nextY;\n }\n }\n\n /**\n * Horizontal run: the cell beside the node is only worth turning into when\n * the cell diagonally behind it is blocked, because otherwise the predecessor\n * reaches it at least as cheaply without passing through this node.\n */\n private forcedBeside(previousX: number, x: number, y: number, side: number): boolean {\n return !this.walkable(previousX, y + side) && this.walkable(x, y + side);\n }\n\n /** Vertical run; the mirror of {@link forcedBeside}. */\n private forcedAbove(previousY: number, y: number, x: number, side: number): boolean {\n return !this.walkable(x + side, previousY) && this.walkable(x + side, y);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,oBAAb,MAA0D;CACxD,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAO,YAAY,OAAqB,OAAe,QAAgB;EACrE,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,SAAS;CAChB;CAEA,AAAO,WAAW,MAAc,QAAgB,MAAc,UAAsB,UAAgC;EAClH,MAAM,EAAE,UAAU;EAClB,MAAM,IAAI,OAAO;EACjB,MAAM,IAAK,OAAO,QAAS;EAC3B,MAAM,QAAQ,OAAO;EACrB,MAAM,QAAS,OAAO,QAAS;EAE/B,IAAI,QAAQ;EAEZ,IAAI,SAAS,GAAG;GACd,KAAK,IAA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
|
1
|
+
import type { Vector } from '@codexo/exojs';
|
|
2
|
+
import type { NavigationSpace, PrunedExpansion } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* How diagonal steps are allowed on a {@link GridSpace}.
|
|
5
|
+
*
|
|
6
|
+
* - `never` - four-connected movement only.
|
|
7
|
+
* - `no-corner-cutting` - a diagonal step needs both cells it passes between to
|
|
8
|
+
* be walkable, which is what stops an agent from clipping through the corner
|
|
9
|
+
* where two walls meet.
|
|
10
|
+
* - `always` - eight-connected movement with no such restriction.
|
|
11
|
+
*/
|
|
12
|
+
export type DiagonalPolicy = 'never' | 'no-corner-cutting' | 'always';
|
|
13
|
+
/** Construction options for {@link GridSpace}. */
|
|
14
|
+
export interface GridSpaceOptions {
|
|
15
|
+
/** Cell x of the window's left column. Defaults to `0`. */
|
|
16
|
+
readonly originX?: number | undefined;
|
|
17
|
+
/** Cell y of the window's top row. Defaults to `0`. */
|
|
18
|
+
readonly originY?: number | undefined;
|
|
19
|
+
/** Defaults to `'no-corner-cutting'`. */
|
|
20
|
+
readonly diagonals?: DiagonalPolicy | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* World size of one cell. The distance metric assumes square cells, so a
|
|
23
|
+
* tilemap with non-square tiles has to pick one axis. Defaults to `1`.
|
|
24
|
+
*/
|
|
25
|
+
readonly cellSize?: number | undefined;
|
|
26
|
+
/** World x of cell `0`'s left edge, before the window origin. Defaults to `0`. */
|
|
27
|
+
readonly cellOriginX?: number | undefined;
|
|
28
|
+
/** World y of cell `0`'s top edge, before the window origin. Defaults to `0`. */
|
|
29
|
+
readonly cellOriginY?: number | undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A rectangular window of weighted, optionally blocked cells.
|
|
33
|
+
*
|
|
34
|
+
* The window is finite by construction: everything outside it is blocked, so a
|
|
35
|
+
* search always terminates and an infinite or streamed world is served by
|
|
36
|
+
* sizing the window to the region the actors are in, then feeding chunk changes
|
|
37
|
+
* back through {@link setCost}. Coordinates in the public API are absolute cell
|
|
38
|
+
* coordinates - the same numbers a tilemap uses - not offsets into the window.
|
|
39
|
+
*
|
|
40
|
+
* Cost `0` blocks a cell, `1` is ordinary ground and larger values are terrain
|
|
41
|
+
* an agent will route around when it is cheaper to do so. Diagonal steps cost
|
|
42
|
+
* their length, so the metric stays consistent with the octile heuristic.
|
|
43
|
+
*
|
|
44
|
+
* The space carries no scene node and no rendering: it is data plus a neighbour
|
|
45
|
+
* relation, and it is built and mutated entirely by the application.
|
|
46
|
+
*/
|
|
47
|
+
export declare class GridSpace implements NavigationSpace {
|
|
48
|
+
readonly width: number;
|
|
49
|
+
readonly height: number;
|
|
50
|
+
readonly originX: number;
|
|
51
|
+
readonly originY: number;
|
|
52
|
+
readonly cellSize: number;
|
|
53
|
+
readonly cellOriginX: number;
|
|
54
|
+
readonly cellOriginY: number;
|
|
55
|
+
readonly diagonals: DiagonalPolicy;
|
|
56
|
+
readonly maxDegree: number;
|
|
57
|
+
private readonly costs;
|
|
58
|
+
private clearance;
|
|
59
|
+
private jumpExpansion;
|
|
60
|
+
private weightedCells;
|
|
61
|
+
private minCost;
|
|
62
|
+
private currentRevision;
|
|
63
|
+
constructor(width: number, height: number, options?: GridSpaceOptions);
|
|
64
|
+
/**
|
|
65
|
+
* Builds a window and fills it from a cost callback, which receives absolute
|
|
66
|
+
* cell coordinates. This is the tilemap bridge: return `0` for a solid tile
|
|
67
|
+
* and the terrain's cost for a walkable one, and the grid never learns what a
|
|
68
|
+
* tilemap is.
|
|
69
|
+
*
|
|
70
|
+
* Values that are not finite and positive are stored as blocked.
|
|
71
|
+
*/
|
|
72
|
+
static from(width: number, height: number, cost: (x: number, y: number) => number, options?: GridSpaceOptions): GridSpace;
|
|
73
|
+
get nodeCapacity(): number;
|
|
74
|
+
get revision(): number;
|
|
75
|
+
/**
|
|
76
|
+
* `true` while every walkable cell costs exactly `1`. Jump-point search is
|
|
77
|
+
* only available on such a grid.
|
|
78
|
+
*/
|
|
79
|
+
get uniformCost(): boolean;
|
|
80
|
+
/** The node at absolute cell coordinates, or `-1` outside the window. */
|
|
81
|
+
nodeAt(x: number, y: number): number;
|
|
82
|
+
/** Absolute cell x of a node. */
|
|
83
|
+
nodeX(node: number): number;
|
|
84
|
+
/** Absolute cell y of a node. */
|
|
85
|
+
nodeY(node: number): number;
|
|
86
|
+
/** Traversal cost of a cell; `0` for blocked cells and everything outside the window. */
|
|
87
|
+
costAt(x: number, y: number): number;
|
|
88
|
+
isWalkable(x: number, y: number): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Sets a cell's cost and bumps {@link revision}. Values that are not finite
|
|
91
|
+
* and positive block the cell. Coordinates outside the window are ignored.
|
|
92
|
+
*/
|
|
93
|
+
setCost(x: number, y: number, cost: number): void;
|
|
94
|
+
/**
|
|
95
|
+
* Largest agent width that fits with its top-left corner on this cell, or `0`
|
|
96
|
+
* for a blocked cell. Recomputed lazily after the first edit that follows a
|
|
97
|
+
* query.
|
|
98
|
+
*/
|
|
99
|
+
clearanceAt(x: number, y: number): number;
|
|
100
|
+
neighbors(node: number, agentSize: number, outNodes: Int32Array, outCosts: Float64Array): number;
|
|
101
|
+
heuristic(node: number, goal: number): number;
|
|
102
|
+
nodeToPoint(node: number, out: Vector): void;
|
|
103
|
+
pointToNode(x: number, y: number): number;
|
|
104
|
+
nearestNode(x: number, y: number): number;
|
|
105
|
+
pruning(agentSize: number): PrunedExpansion | null;
|
|
106
|
+
/**
|
|
107
|
+
* String-pulls the path: keeps a node only when the straight line past it is
|
|
108
|
+
* blocked, so the result is the same route with its staircase removed.
|
|
109
|
+
*
|
|
110
|
+
* The returned nodes are no longer adjacent - the guarantee is that the
|
|
111
|
+
* straight segment between two consecutive ones stays inside walkable cells
|
|
112
|
+
* an agent of `agentSize` fits through, and never crosses terrain more
|
|
113
|
+
* expensive than the section it replaces.
|
|
114
|
+
*/
|
|
115
|
+
smoothPath(nodes: readonly number[], agentSize: number): number[];
|
|
116
|
+
private fits;
|
|
117
|
+
/**
|
|
118
|
+
* Walks the cells a centre-to-centre segment passes through and reports
|
|
119
|
+
* whether all of them are traversable within `budget`. A segment that leaves
|
|
120
|
+
* a cell exactly through its corner counts as a diagonal step and is subject
|
|
121
|
+
* to the same corner rule as movement.
|
|
122
|
+
*/
|
|
123
|
+
private lineOfSight;
|
|
124
|
+
/**
|
|
125
|
+
* Brushfire clearance: how far the walkable block anchored at a cell extends
|
|
126
|
+
* down and to the right. Filling it bottom-right to top-left makes it one
|
|
127
|
+
* pass, because a cell only ever depends on the three cells after it.
|
|
128
|
+
*/
|
|
129
|
+
private ensureClearance;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=GridSpace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GridSpace.d.ts","sourceRoot":"","sources":["../../../src/spaces/GridSpace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIjE;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,mBAAmB,GAAG,QAAQ,CAAC;AAEtE,kDAAkD;AAClD,MAAM,WAAW,gBAAgB;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,uDAAuD;IACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,yCAAyC;IACzC,QAAQ,CAAC,SAAS,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAChD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,kFAAkF;IAClF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,iFAAiF;IACjF,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAA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