With -pn, snap-round each layer's polygons consistently with each other

Wagyu snaps each edge to every "hot pixel" (vertex or rounded intersection)
that it passes through. Each polygon was cleaned on its own, with only its
own hot pixels, so a border shared by two polygons could be bent through a
hot pixel in one of them and not in the other, leaving a shard gap or overlap
between them even though --no-simplification-of-shared-nodes had simplified
and rounded the border identically in both. (In Dane County tile 11/515/751,
rounding moved one of a block's own vertices across its border with a sliver,
and cleaning bent the block's copy of the border through a hot pixel that the
sliver's copy didn't have.)

Wagyu now has hot_pixels(), which returns the hot pixels of the rings added
to it, and add_hot_pixels(), which gives execute() more hot pixels to snap
to. When extra hot pixels are given, edges are snapped to every hot pixel
they touch, including corner touches, so that whether a shared edge is
snapped to a hot pixel can't depend on which polygon it is in.

With -pn, the simplification worker now runs in two passes. The first
simplifies and rounds every feature in the tile. Then the hot pixels of all
the polygons in each layer are found together, which also finds crossings
between features that no single feature would see. The second pass cleans
each polygon with the layer's hot pixels near it as well as its own, so
the borders it shares are snapped identically in each polygon. This is
snap rounding of the whole layer's arrangement at once, so the result is
still free of crossings.

For Dane County Census blocks at -D8 -d8 -pt -pn, tiles 12/1031/1503 and
11/515/751 now have no gaps between blocks (from 10 and 23 pixels), and the
gaps and overlaps at z9 and z10 go from 55/113 and 155/175 to 13/56 and 23/59
pixels, with no self-intersecting polygons. Natural Earth 10m countries at
-z8 -pn take about 7% longer.

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:09:18 +00:00
parent 5e1240b341
commit 162cb1c1b0
12 changed files with 366 additions and 99 deletions
+17 -2
View File
@@ -38,8 +38,23 @@ double unshared_perimeter(drawvec const &geom, size_t i, size_t j, long long ox,
// already cover the space, and *all_shared is set if every edge was shared.
drawvec outline_strips(drawvec const &geom, int z, int detail, double simplification, long long ox, long long oy, bool *all_shared);
// Hot pixels for snap rounding, as (y, x) in tile coordinates, sorted
typedef std::vector<std::pair<long long, long long>> hot_pixel_list;
// Union the strips from thin_polygon_strips() with a cleaned polygon
// (both in tile coordinates)
drawvec union_polygon_strips(drawvec const &geom, drawvec const &strips);
// (both in tile coordinates). If `hot` is provided, the result is snapped
// to those hot pixels as in clean_polygon_with_hot_pixels().
drawvec union_polygon_strips(drawvec const &geom, drawvec const &strips, hot_pixel_list const *hot = NULL);
// The hot pixels (vertices and rounded intersections) of all the polygons in
// `geoms` (in tile coordinates), so that each of them can be cleaned with
// clean_polygon_with_hot_pixels() and edges that they share are snapped
// identically in each, instead of differently depending on which other
// vertices each polygon happens to have.
hot_pixel_list layer_hot_pixels(std::vector<drawvec const *> const &geoms);
// Clean a polygon (in tile coordinates), snapping its edges to the hot pixels
// from layer_hot_pixels() as well as its own. Sets *ok to false if that fails.
drawvec clean_polygon_with_hot_pixels(drawvec const &geom, hot_pixel_list const &hot, bool *ok);
#endif