Treat hot pixels as half-open when snapping to a layer's common set

With consistent snapping, edges are snapped to every hot pixel they touch,
including those whose corners they only touch. But with closed pixels, an
edge passing diagonally through a lattice point touches the corners of the
two pixels beside it as well, and is snapped into a zigzag through all four.
Two edges from different polygons that cross at a pixel corner zigzag
through the same pixels in different orders, and the zigzags cross each
other. (In Dane County tile 10/258/376, this left a quarter-pixel gap and a
quarter-pixel overlap between two blocks on either side of a sliver.)

Hobby's snap rounding, whose guarantee that snapped edges don't cross is
what makes snapping to a common set of hot pixels work, uses half-open
pixels, [x - 0.5, x + 0.5) by [y - 0.5, y + 0.5), consistent with rounding
halves up, which is how wagyu rounds intersection points. So when snapping
to a common set of hot pixels, find the range of pixels an edge passes
through in each row that way, so that a point on a pixel boundary belongs
to only one pixel.

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 00:58:29 +00:00
parent 162cb1c1b0
commit b8e8542dfa
6 changed files with 141 additions and 11 deletions
+5 -1
View File
@@ -44,7 +44,11 @@
them and not the other, leaving a shard gap or overlap between them. Now the
hot pixels of all the polygons in the layer are found first, and each polygon
is snapped to the ones near it as well as its own, so shared borders are
snapped identically. For Dane County Census blocks at -D8 -d8 -pt -pn, this
snapped identically. In this mode the hot pixels are treated as half-open,
[x - 0.5, x + 0.5) by [y - 0.5, y + 0.5), as in Hobby's snap rounding,
rather than as closed squares, because edges passing diagonally through
pixel corners otherwise zigzagged through the same pixels in different
orders in different polygons, and could cross each other. 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.