API reference

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

C

classWaypointGraph

@codexo/exojs-pathfinding / pathfinding / stable

A directed graph of hand-placed waypoints. This is the representation for worlds a grid cannot describe: a platformer where traversal is a topology of walk, jump and fall links rather than cell walkability, or a purely abstract graph with no geometry at all. Nodes carry an optional position, edges carry a cost, a WaypointEdgeOptions.kind and an arbitrary payload, and the resulting path reports the edges it took so the game can execute each step in its own way. With positions the search is A* over straight-line distance; without them the heuristic is zero and the same search degrades cleanly to Dijkstra.

4
props
11
methods
0
events
Import
import { WaypointGraph } from '@codexo/exojs-pathfinding'

A directed graph of hand-placed waypoints.

This is the representation for worlds a grid cannot describe: a platformer where traversal is a topology of walk, jump and fall links rather than cell walkability, or a purely abstract graph with no geometry at all. Nodes carry an optional position, edges carry a cost, a WaypointEdgeOptions.kind and an arbitrary payload, and the resulting path reports the edges it took so the game can execute each step in its own way.

With positions the search is A* over straight-line distance; without them the heuristic is zero and the same search degrades cleanly to Dijkstra.

Constructors1
new(): WaypointGraph<Payload>
Methods11
addEdge(from: number, to: number, options: WaypointEdgeOptionsOptions for WaypointGraph.addEdge and WaypointGraph.connect.<Payload>): void
Adds a directed edge. A second edge between the same pair replaces the first.
addNode(x?: number, y?: number): number
Adds a node. Omitting the position puts the graph in Dijkstra mode: the heuristic drops to zero for every query, since a positionless node makes no geometric estimate meaningful.
connect(a: number, b: number, options: WaypointEdgeOptionsOptions for WaypointGraph.addEdge and WaypointGraph.connect.<Payload>): void
Adds the edge in both directions with the same options.
Describes the traversal from from to to, if the space models one.
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.
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.
pointToNode(x: number, y: number): number
The positioned node closest to the point, or -1 when the graph has none. A graph has no cells, so there is no "outside" for a point to fall into.
removeEdge(from: number, to: number): void
removeNode(node: number): void
Removes a node together with every edge touching it. Ids are recycled: a later addNode may hand out the id this call freed, so a node id held across a removal can silently refer to a different node.
Properties4
maxDegree: number
Upper bound on how many neighbours one node can have.
nodeCapacity: number
One past the largest node id. Sizes the pathfinder's search buffers.
nodeCount: number
Number of live nodes.
revision: number
Increments on every mutation that can invalidate a path. Carried into PathResult.revision so callers can detect stale paths.
Source