Skip to main content

Module pathfinding

Module pathfinding 

Source
Expand description

Grid navigation: A* paths, line-of-sight smoothing, path following and distance fields over caller-owned 2D grids.

Searches read cells through NavGrid, so tilemaps, voxel layers and game arrays can be searched in place without copying. PathFinder and DistanceField keep their buffers between queries: once their capacity covers the grid, queries do not allocate. GridLayout maps cells to world positions for PathFollower and collision geometry.

Moving into a cell costs that cell’s NavGrid::cost multiplied by the step length: 1 orthogonally and √2 diagonally. The start cell’s cost is never charged. Results are deterministic for the same grid and inputs.

Structs§

CostGrid
Owned row-major grid of per-cell costs.
DistanceField
Cost from every cell to the nearest of one or more goals (a Dijkstra map).
GridFn
Adapts a size and cost callback to NavGrid without storing cells.
GridLayout
Maps grid cells to world-space cells.
PathFinder
Reusable A* search state for grids up to the largest size seen.
PathFollower
Steers a character through world-space waypoints.
PathOptions
A* search settings.

Enums§

DiagonalRule
Rule for diagonal moves past the two orthogonally adjacent cells.
Neighborhood
Cells reachable in one step.
PathError
Invalid navigation input.
PathStatus
Result of an A* call.

Traits§

NavGrid
Read-only access to a bounded navigation grid.

Functions§

line_of_sight
Whether a straight segment between two cell centers crosses only walkable cells.
smooth_path
Removes waypoints that a straight segment can skip, in place.