Every geometric algorithm eventually faces the same enemy: floating-point numbers. Coordinates computed by intersecting two line segments are almost never exactly representable in binary. Round them naively and two segments that were just touching can suddenly cross — or a segment that crossed another can jump over it entirely. The output looks fine until a downstream algorithm tries to build a polygon, compute an overlay, or route a wire, and crashes on the inconsistency.
Snap rounding is a principled answer, introduced by Hobby (1993) and Guibas & Marimont (1995), and widely studied since. The idea is elegant: after computing all intersections, move every vertex — original or newly created — to the center of the nearest pixel on a fixed integer grid. The guarantee is the hard part: no matter how you snap, the resulting configuration must have the same combinatorial topology as the exact arrangement. No new crossings can appear, and no existing ones can disappear.
That guarantee sounds simple, but it hides a cascade of subtle problems. When you snap vertex to its nearest pixel, the segment connecting to moves slightly. That moved segment might now pass through a pixel it didn't touch before, which contains another vertex that now must be snapped too — triggering more moves. The algorithm must converge and the result must still be topologically correct.
Comments
Loading comments...