API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classGridSpace

@codexo/exojs-pathfinding / pathfinding / stable

A rectangular window of weighted, optionally blocked cells. The window is finite by construction: everything outside it is blocked, so a search always terminates and an infinite or streamed world is served by sizing the window to the region the actors are in, then feeding chunk changes back through setCost. Coordinates in the public API are absolute cell coordinates - the same numbers a tilemap uses - not offsets into the window. Cost `0` blocks a cell, `1` is ordinary ground and larger values are terrain an agent will route around when it is cheaper to do so. Diagonal steps cost their length, so the metric stays consistent with the octile heuristic. The space carries no scene node and no rendering: it is data plus a neighbour relation, and it is built and mutated entirely by the application.

12
props
15
methods
0
events
Import
import { GridSpace } from '@codexo/exojs-pathfinding'

A rectangular window of weighted, optionally blocked cells.

The window is finite by construction: everything outside it is blocked, so a search always terminates and an infinite or streamed world is served by sizing the window to the region the actors are in, then feeding chunk changes back through setCost. Coordinates in the public API are absolute cell coordinates - the same numbers a tilemap uses - not offsets into the window.

Cost `0` blocks a cell, `1` is ordinary ground and larger values are terrain an agent will route around when it is cheaper to do so. Diagonal steps cost their length, so the metric stays consistent with the octile heuristic.

The space carries no scene node and no rendering: it is data plus a neighbour relation, and it is built and mutated entirely by the application.

Constructors1
new(width: number, height: number, options: GridSpaceOptionsConstruction options for GridSpace.): GridSpace
Methods15
clearanceAt(x: number, y: number): number
Largest agent width that fits with its top-left corner on this cell, or 0 for a blocked cell. Recomputed lazily after the first edit that follows a query.
costAt(x: number, y: number): number
Traversal cost of a cell; 0 for blocked cells and everything outside the window.
heuristic(node: number, goal: number): number
Estimated remaining cost from node to goal. Must never overestimate, or the result stops being cost-optimal; returning 0 degrades the search to Dijkstra, which is the correct answer for a space without positions.
isWalkable(x: number, y: number): boolean
nearestNode(x: number, y: number): number
The node closest to a point, whether or not it is traversable and whether or not the point lies inside the space. Backs snapToNearest for coordinate queries; without it such a query reports unreachable.
neighbors(node: number, agentSize: number, outNodes: Int32Array, outCosts: Float64Array): number
Writes the neighbours of node and the cost of stepping to each into the buffers, and returns how many were written. The buffers belong to the pathfinder and are reused across nodes and searches, so an implementation must not retain them. Costs must be positive and finite. agentSize is the requested clearance; spaces that do not model clearance ignore it.
nodeAt(x: number, y: number): number
The node at absolute cell coordinates, or -1 outside the window.
nodeX(node: number): number
Absolute cell x of a node.
nodeY(node: number): number
Absolute cell y of a node.
pointToNode(x: number, y: number): number
The node at a point, or -1 when the point lies outside the space.
Returns a pruned expansion valid for a search at this agentSize, or null when the space cannot prune under those conditions. Called once per search, so an implementation may build state here - but not per node.
setCost(x: number, y: number, cost: number): void
Sets a cell's cost and bumps revision. Values that are not finite and positive block the cell. Coordinates outside the window are ignored.
smoothPath(nodes: readonly number[], agentSize: number): number[]
String-pulls the path: keeps a node only when the straight line past it is blocked, so the result is the same route with its staircase removed. The returned nodes are no longer adjacent - the guarantee is that the straight segment between two consecutive ones stays inside walkable cells an agent of agentSize fits through, and never crosses terrain more expensive than the section it replaces.
from(width: number, height: number, cost: (x: number, y: number) => number, options: GridSpaceOptionsConstruction options for GridSpace.): GridSpace
Builds a window and fills it from a cost callback, which receives absolute cell coordinates. This is the tilemap bridge: return 0 for a solid tile and the terrain's cost for a walkable one, and the grid never learns what a tilemap is. Values that are not finite and positive are stored as blocked.
Properties12
cellOriginX: number
cellOriginY: number
cellSize: number
height: number
maxDegree: number
Upper bound on how many neighbours one node can have.
originX: number
originY: number
width: number
nodeCapacity: number
One past the largest node id. Sizes the pathfinder's search buffers.
revision: number
Increments on every mutation that can invalidate a path. Carried into PathResult.revision so callers can detect stale paths.
uniformCost: boolean
true while every walkable cell costs exactly 1. Jump-point search is only available on such a grid.
Source