five-on-it / packages/world/src/road-graph
packages/world/src/road-graph
The road graph: what the AI drives on. Built from a level's roads (polylines with lanes) by joining the ones that touch or cross: a node where two centre lines meet (a crossing, or a T where a street ends on another road's centre line or inside its band), a node at every free end and at every bend of a polyline, and between consecutive nodes along a road one directed edge per lane, with the lane's offset to the right of travel (right-hand traffic). A node's height is the road surface's there, so a climbing road meets the flat one at the foot of the hill and a bridge passes over the street below. Pure and deterministic: nodes and edges are numbered in road order, so two builds of the same level are identical. Isomorphic: no DOM, no Node.