Don't snap polygons a second time when removing overlaps

Removing the area that a polygon shares with an earlier polygon ran wagyu on
geometry that had already been snapped to tile coordinates, and snapping it
again could change it. In Dane County tile 8/64/93, consistent snapping bent
one block's edge into a 45-degree diagonal that left it a half-pixel
triangle, and when that block's overlap with another block was removed, the
diagonal passed through the corner of the hot pixel of the vertex beside it,
so it was snapped again and the triangle collapsed, leaving a hole between
it and its neighbor. Elsewhere in the same tile, two half-pixel overlaps
were left behind the same way.

The polygons' edges no longer cross after consistent snapping, so the
difference needs no new vertices. So compute it at 16 times the tile
resolution, where the vertices are far from each other's hot pixels, and use
the result if all of its vertices are the original ones. Only if they aren't,
fall back to snapping at tile resolution to the layer's hot pixels.

For Dane County at -D8 -d8 -pt -pn -zg, this reduces the overlapping
pixels at z8, z9, and z10 from 7, 8, and 16 to 5, 3, and 3, and removes the
hole and both overlaps in 8/64/93 at -z8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQ6vQUJtmGZnqz7RmVYQaJ
This commit is contained in:
Claude
2026-12-01 02:13:36 +00:00
parent 082487b594
commit 4d761d4307
4 changed files with 168 additions and 31 deletions
+4 -1
View File
@@ -53,7 +53,10 @@
area it covered is covered by both of its neighbors, that area is removed
from all but the earliest of them. These overlaps are found from edges that
two polygons share in the same direction, which neighbors that tile exactly
never do, and from vertices of one polygon strictly inside another. For Dane County Census blocks at -D8 -d8 -pt -pn, this
never do, and from vertices of one polygon strictly inside another. The
overlapping area is removed at a higher resolution than the tile, so that
the polygon isn't snapped to tile coordinates a second time, which could
collapse parts of it that the first snapping had left, and leave holes. For Dane County Census blocks at -D8 -d8 -pt -pn, this
reduces the gaps between blocks at z9 and z10 from 55 and 155 pixels to 13
and 23, and the overlaps from 113 and 175 to 56 and 59, and takes about 7%
longer for Natural Earth countries at -z8 -pn.