Skip to main content

Module graph_cleanup

Module graph_cleanup 

Source
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:

  1. Asymmetry. The per-direction “best candidate” selection at each node can leave A.Right = B without B.Left = A (B found a better Left candidate elsewhere).
  2. Non-straight axis chains. At a true grid node C, the vectors C→Right and C→Left must be nearly antiparallel (and similarly Up/Down). A false edge inserted on one side bends the chain.
  3. 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→B whose reverse B→A is 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 true iff 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.