@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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +172 -0
  3. package/dist/esm/Pathfinder.d.ts +50 -0
  4. package/dist/esm/Pathfinder.d.ts.map +1 -0
  5. package/dist/esm/Pathfinder.js +151 -0
  6. package/dist/esm/Pathfinder.js.map +1 -0
  7. package/dist/esm/core/BinaryHeap.d.ts +2 -0
  8. package/dist/esm/core/BinaryHeap.d.ts.map +1 -0
  9. package/dist/esm/core/BinaryHeap.js +90 -0
  10. package/dist/esm/core/BinaryHeap.js.map +1 -0
  11. package/dist/esm/core/SearchState.d.ts +2 -0
  12. package/dist/esm/core/SearchState.d.ts.map +1 -0
  13. package/dist/esm/core/SearchState.js +66 -0
  14. package/dist/esm/core/SearchState.js.map +1 -0
  15. package/dist/esm/core/search.d.ts +2 -0
  16. package/dist/esm/core/search.d.ts.map +1 -0
  17. package/dist/esm/core/search.js +106 -0
  18. package/dist/esm/core/search.js.map +1 -0
  19. package/dist/esm/index.d.ts +2 -0
  20. package/dist/esm/index.d.ts.map +1 -0
  21. package/dist/esm/index.js +5 -0
  22. package/dist/esm/public.d.ts +7 -0
  23. package/dist/esm/public.d.ts.map +1 -0
  24. package/dist/esm/spaces/GridJumpExpansion.d.ts +2 -0
  25. package/dist/esm/spaces/GridJumpExpansion.d.ts.map +1 -0
  26. package/dist/esm/spaces/GridJumpExpansion.js +137 -0
  27. package/dist/esm/spaces/GridJumpExpansion.js.map +1 -0
  28. package/dist/esm/spaces/GridSpace.d.ts +131 -0
  29. package/dist/esm/spaces/GridSpace.d.ts.map +1 -0
  30. package/dist/esm/spaces/GridSpace.js +296 -0
  31. package/dist/esm/spaces/GridSpace.js.map +1 -0
  32. package/dist/esm/spaces/WaypointGraph.d.ts +79 -0
  33. package/dist/esm/spaces/WaypointGraph.d.ts.map +1 -0
  34. package/dist/esm/spaces/WaypointGraph.js +167 -0
  35. package/dist/esm/spaces/WaypointGraph.js.map +1 -0
  36. package/dist/esm/spaces/gridGeometry.d.ts +3 -0
  37. package/dist/esm/spaces/gridGeometry.d.ts.map +1 -0
  38. package/dist/esm/spaces/gridGeometry.js +40 -0
  39. package/dist/esm/spaces/gridGeometry.js.map +1 -0
  40. package/dist/esm/types.d.ts +182 -0
  41. package/dist/esm/types.d.ts.map +1 -0
  42. package/package.json +46 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gridGeometry.js","names":[],"sources":["../../../src/spaces/gridGeometry.ts"],"sourcesContent":["/** Grid step geometry shared by the neighbour expansion and the jump search. @internal */\n\nexport const SQRT2 = Math.SQRT2;\n\n/**\n * Orthogonal directions first, then diagonals: a four-connected grid is the\n * same table truncated to four entries, and the fixed order is half of what\n * makes equal-cost searches reproducible (the heap tie-break is the other half).\n *\n * @internal\n */\nexport const DIRECTION_X: readonly number[] = [1, -1, 0, 0, 1, 1, -1, -1];\n\n/** @internal */\nexport const DIRECTION_Y: readonly number[] = [0, 0, 1, -1, 1, -1, 1, -1];\n\n/** Octile length of a straight or diagonal run between two cells. @internal */\nexport const runLength = (spanX: number, spanY: number): number => {\n const diagonal = Math.min(spanX, spanY);\n\n return spanX + spanY - 2 * diagonal + diagonal * SQRT2;\n};\n"],"mappings":";;AAEA,MAAa,QAAQ,KAAK;;;;;;;;AAS1B,MAAa,cAAiC;CAAC;CAAG;CAAI;CAAG;CAAG;CAAG;CAAG;CAAI;AAAE;;AAGxE,MAAa,cAAiC;CAAC;CAAG;CAAG;CAAG;CAAI;CAAG;CAAI;CAAG;AAAE;;AAGxE,MAAa,aAAa,OAAe,UAA0B;CACjE,MAAM,WAAW,KAAK,IAAI,OAAO,KAAK;CAEtC,OAAO,QAAQ,QAAQ,IAAI,WAAW,WAAW;AACnD"}
@@ -0,0 +1,182 @@
1
+ import type { Vector } from '@codexo/exojs';
2
+ /**
3
+ * Outcome of a path query.
4
+ *
5
+ * - `found` - a complete path from start to goal (or, with `snapToNearest`, to
6
+ * the reachable node closest to the goal).
7
+ * - `unreachable` - the search exhausted the space without reaching the goal.
8
+ * - `budget-exceeded` - `maxExpandedNodes` ran out first. The result still
9
+ * carries the best partial path found so far.
10
+ */
11
+ export type PathStatus = 'found' | 'unreachable' | 'budget-exceeded';
12
+ /**
13
+ * One traversal step of a path, as described by the space it came from.
14
+ *
15
+ * Spaces that model traversal kinds - {@link WaypointGraph} is the one in this
16
+ * package - report them here, so a movement controller can react to a `'jump'`
17
+ * step differently than to a `'walk'` step. Grid spaces describe no edges.
18
+ */
19
+ export interface PathEdge<Payload = unknown> {
20
+ readonly from: number;
21
+ readonly to: number;
22
+ /** Free-form traversal tag defined by whoever authored the space. */
23
+ readonly kind: string;
24
+ /** Payload the author attached to the edge, or `null`. */
25
+ readonly data: Payload | null;
26
+ }
27
+ /** Result of {@link Pathfinder.findPath} and {@link Pathfinder.findPathBetween}. */
28
+ export interface PathResult<Payload = unknown> {
29
+ readonly status: PathStatus;
30
+ /**
31
+ * Node ids from start to goal inclusive. Consecutive entries are adjacent in
32
+ * the space unless the path was smoothed, which removes intermediate nodes by
33
+ * design.
34
+ */
35
+ readonly nodes: readonly number[];
36
+ /** {@link nodes} mapped through the space's node-to-point conversion. */
37
+ readonly points: readonly Vector[];
38
+ /**
39
+ * Traversal steps for spaces that describe them, empty otherwise. Not filled
40
+ * for smoothed paths, whose steps are no longer space edges.
41
+ */
42
+ readonly edges: ReadonlyArray<PathEdge<Payload>>;
43
+ /** Total traversal cost of {@link nodes}. Smoothing does not change it. */
44
+ readonly cost: number;
45
+ /**
46
+ * `space.revision` at search time. Compare it against the space's current
47
+ * revision to detect a path that the world has invalidated since.
48
+ */
49
+ readonly revision: number;
50
+ /** Nodes taken off the open list. Useful for sizing `maxExpandedNodes`. */
51
+ readonly expandedNodes: number;
52
+ }
53
+ /** Result of {@link Pathfinder.floodFrom}: every node reached, with its cost. */
54
+ export interface FloodRegion {
55
+ /** Reached nodes in the order the flood settled them, origin first. */
56
+ readonly nodes: readonly number[];
57
+ /** Traversal cost from the origin to the node at the same index. */
58
+ readonly costs: readonly number[];
59
+ readonly revision: number;
60
+ readonly expandedNodes: number;
61
+ }
62
+ /** Options for {@link Pathfinder.findPath} and {@link Pathfinder.findPathBetween}. */
63
+ export interface FindPathOptions {
64
+ /**
65
+ * Run the space's path smoother over the result. No-op for spaces that
66
+ * implement none. Defaults to `false`.
67
+ */
68
+ readonly smooth?: boolean | undefined;
69
+ /**
70
+ * Agent width in nodes. Spaces that model clearance restrict expansion to
71
+ * nodes where an agent this wide fits; spaces that do not ignore it.
72
+ * Defaults to `1`.
73
+ */
74
+ readonly agentSize?: number | undefined;
75
+ /**
76
+ * Stop after this many expanded nodes and return the best partial path with
77
+ * status `budget-exceeded`. Defaults to `0`, meaning no budget - a search
78
+ * over a finite space terminates regardless.
79
+ */
80
+ readonly maxExpandedNodes?: number | undefined;
81
+ /**
82
+ * When the goal cannot be reached, return the path to the reachable node
83
+ * closest to it instead of `unreachable`. For coordinate queries this also
84
+ * resolves a goal point outside the space to the space's nearest node.
85
+ * Defaults to `false`.
86
+ */
87
+ readonly snapToNearest?: boolean | undefined;
88
+ /**
89
+ * Allow the space to substitute a pruned expansion (jump-point search on
90
+ * uniform grids) for plain neighbour expansion. Both produce a cost-optimal
91
+ * path; pruning expands far fewer nodes. Defaults to `true`.
92
+ */
93
+ readonly pruning?: boolean | undefined;
94
+ }
95
+ /** Options for {@link Pathfinder.floodFrom}. */
96
+ export interface FloodOptions {
97
+ /** Highest traversal cost to include. Defaults to `Infinity`. */
98
+ readonly maxCost?: number | undefined;
99
+ /** Node budget, as in {@link FindPathOptions.maxExpandedNodes}. */
100
+ readonly maxExpandedNodes?: number | undefined;
101
+ /** Agent width in nodes, as in {@link FindPathOptions.agentSize}. */
102
+ readonly agentSize?: number | undefined;
103
+ }
104
+ /**
105
+ * A parent-dependent successor generator that prunes symmetric alternatives
106
+ * without losing optimality - the shape jump-point search takes.
107
+ *
108
+ * Obtained from {@link NavigationSpace.pruning} for the duration of one search.
109
+ */
110
+ export interface PrunedExpansion {
111
+ /**
112
+ * Writes the pruned successors of `node`, reached from `parent` (`-1` for the
113
+ * start node), into the buffers and returns how many were written. The
114
+ * successors may lie several nodes away; `expand` fills in what lies between.
115
+ */
116
+ successors(node: number, parent: number, goal: number, outNodes: Int32Array, outCosts: Float64Array): number;
117
+ /**
118
+ * Appends the nodes strictly between `from` and `to`, then `to` itself, to
119
+ * `out` - turning a path of pruned successors back into a contiguous one.
120
+ */
121
+ expand(from: number, to: number, out: number[]): void;
122
+ }
123
+ /**
124
+ * The search core's view of a world: integer node ids, a neighbour relation and
125
+ * a heuristic. {@link GridSpace} and {@link WaypointGraph} implement it, and so
126
+ * can application code - a space needs no scene node, no renderer and no asset.
127
+ *
128
+ * Implementations must be deterministic: the same query on an unmutated space
129
+ * has to produce the same neighbours in the same order, or paths stop being
130
+ * reproducible across runs and machines.
131
+ */
132
+ export interface NavigationSpace<Payload = unknown> {
133
+ /** One past the largest node id. Sizes the pathfinder's search buffers. */
134
+ readonly nodeCapacity: number;
135
+ /** Upper bound on how many neighbours one node can have. */
136
+ readonly maxDegree: number;
137
+ /**
138
+ * Increments on every mutation that can invalidate a path. Carried into
139
+ * {@link PathResult.revision} so callers can detect stale paths.
140
+ */
141
+ readonly revision: number;
142
+ /**
143
+ * Writes the neighbours of `node` and the cost of stepping to each into the
144
+ * buffers, and returns how many were written. The buffers belong to the
145
+ * pathfinder and are reused across nodes and searches, so an implementation
146
+ * must not retain them.
147
+ *
148
+ * Costs must be positive and finite. `agentSize` is the requested clearance;
149
+ * spaces that do not model clearance ignore it.
150
+ */
151
+ neighbors(node: number, agentSize: number, outNodes: Int32Array, outCosts: Float64Array): number;
152
+ /**
153
+ * Estimated remaining cost from `node` to `goal`. Must never overestimate, or
154
+ * the result stops being cost-optimal; returning `0` degrades the search to
155
+ * Dijkstra, which is the correct answer for a space without positions.
156
+ */
157
+ heuristic(node: number, goal: number): number;
158
+ /** Writes the node's position into `out`. */
159
+ nodeToPoint(node: number, out: Vector): void;
160
+ /** The node at a point, or `-1` when the point lies outside the space. */
161
+ pointToNode(x: number, y: number): number;
162
+ /**
163
+ * The node closest to a point, whether or not it is traversable and whether
164
+ * or not the point lies inside the space. Backs `snapToNearest` for
165
+ * coordinate queries; without it such a query reports `unreachable`.
166
+ */
167
+ nearestNode?(x: number, y: number): number;
168
+ /** Describes the traversal from `from` to `to`, if the space models one. */
169
+ describeEdge?(from: number, to: number): PathEdge<Payload> | null;
170
+ /**
171
+ * Returns a shortened node sequence with the same start and goal that is
172
+ * still traversable for an agent of `agentSize`. Backs `smooth`.
173
+ */
174
+ smoothPath?(nodes: readonly number[], agentSize: number): number[];
175
+ /**
176
+ * Returns a pruned expansion valid for a search at this `agentSize`, or
177
+ * `null` when the space cannot prune under those conditions. Called once per
178
+ * search, so an implementation may build state here - but not per node.
179
+ */
180
+ pruning?(agentSize: number): PrunedExpansion | null;
181
+ }
182
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,aAAa,GAAG,iBAAiB,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ,CAAC,OAAO,GAAG,OAAO;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;CAC/B;AAED,oFAAoF;AACpF,MAAM,WAAW,UAAU,CAAC,OAAO,GAAG,OAAO;IAC3C,Q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WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3C,4EAA4E;IAC5E,YAAY,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAClE;;;OAGG;IACH,UAAU,CAAC,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACnE;;;;OAIG;IACH,OAAO,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAAC;CACrD"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@codexo/exojs-pathfinding",
3
+ "version": "0.16.1",
4
+ "description": "Deterministic, allocation-free 2D pathfinding for ExoJS: A*, jump-point search, weighted grids and waypoint graphs.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Exoridus/ExoJS.git",
8
+ "directory": "packages/exojs-pathfinding"
9
+ },
10
+ "type": "module",
11
+ "sideEffects": false,
12
+ "main": "./dist/esm/index.js",
13
+ "module": "./dist/esm/index.js",
14
+ "types": "./dist/esm/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/esm/index.d.ts",
18
+ "import": "./dist/esm/index.js",
19
+ "default": "./dist/esm/index.js"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "dist/esm/",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsx ../../scripts/build-extension.ts",
30
+ "build:dev": "tsx ../../scripts/build-extension.ts --dev",
31
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
32
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
33
+ "test": "vitest run --root ../.. --project=exojs-pathfinding"
34
+ },
35
+ "peerDependencies": {
36
+ "@codexo/exojs": "0.16.x"
37
+ },
38
+ "devDependencies": {
39
+ "@codexo/exojs": "workspace:*",
40
+ "@codexo/exojs-config": "workspace:*"
41
+ },
42
+ "license": "MIT",
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }