distanceField

Single-source distance field: for each passable cell, the shortest-path cost from source to that cell. Unreachable cells are absent from the result map. Useful when many agents share the same goal; compute the field once via multi-source distanceField, then look up distances per-cell in O(1).

Implemented as a multi-source Dijkstra over source alone.


Multi-source distance field: for each passable cell, the shortest-path cost from the nearest source in sources. The canonical use case is "distance from any exit cell" for evacuation models — compute once at setup, then every agent follows the gradient toward zero in O(1) per step.

Sources themselves have distance 0. Unreachable cells are absent from the result map.