Expand description
Post-build geometric sanity passes on a GridGraph.
A freshly-built 4-connected grid graph can contain edges that pass every per-edge validator in isolation yet violate graph-global invariants of a true chessboard lattice:
- Asymmetry. The per-direction “best candidate” selection at each
node can leave
A.Right = BwithoutB.Left = A(B found a better Left candidate elsewhere). - Non-straight axis chains. At a true grid node
C, the vectorsC→RightandC→Leftmust be nearly antiparallel (and similarlyUp/Down). A false edge inserted on one side bends the chain. - Edge crossings. Edges of a planar grid never cross except at shared endpoints. A spurious cross-cell edge produces a topological X with another real edge.
This module cleans the graph after construction, before connected
components are computed. Each pass takes an &mut GridGraph and removes
offending edges in place. All passes are pure geometry — none need the
pattern-specific PointData that the original validators used.
Functions§
- enforce_
symmetry - Remove every directed edge
A→Bwhose reverseB→Ais missing. - prune_
by_ edge_ straightness - Drop edges at each node whose Right/Left or Up/Down pair fails the straight-line test.
- prune_
crossing_ edges - Drop edges that properly cross another edge in the graph.
- prune_
isolated_ pairs - Drop low-degree dangling edges.
- segments_
properly_ cross - Return
trueiff segments(p1,p2)and(p3,p4)share a strictly interior intersection point. Shared endpoints (within a small tolerance) do not count as a crossing — they are the legitimate meeting points of a planar graph.