Replace polygons that collapse entirely with their outlines, not rectangles

When a polygon collapsed away to nothing during cleaning, revive_polygon()
replaced it with a rectangle with the polygon's area, centered on the
average of its vertices. That looked bad for two reasons. Most polygons that
collapse are much smaller than a pixel, and the rectangle is at least a
pixel, so it was usually far too big: for Dane County Census blocks at
-D8 -d8 -pt -pn, 88% of the 27,206 revived polygons had less than half a
pixel of area, and the median rectangle had 11 times the area of the polygon
it replaced. And the larger polygons that collapse are almost all long and
narrow, like blocks between roads, so a square at their midpoint looked
nothing like them.

Now a polygon that collapses entirely is first replaced by the union of
one-pixel strips along every edge of its simplified outline, which traces
its shape in the right place. Only if that is empty too, because the whole
polygon is within a pixel or so, is it replaced by the rectangle, which is
then a single pixel. This is part of spindle preservation, so with
--no-spindle-preservation the rectangle is still used.

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-11-30 22:41:12 +00:00
parent 5b35e5dacf
commit 34e1f56bdd
10 changed files with 106 additions and 9 deletions
+11
View File
@@ -22,6 +22,17 @@
part with open space on its far side, like a coastal strip, is still kept.
Since strips are only needed for edges that are already known to be narrow,
the shared edges are only looked up for those, not for every vertex.
* When a polygon collapses away to nothing entirely during cleaning, replace it
with a line one pixel wide along its outline, so it keeps its shape and
location, instead of a rectangle with the polygon's area centered on the
average of its vertices. For long, narrow polygons, like Census blocks
between roads, the rectangle looked nothing like the polygon. Most polygons
that collapse are much smaller than a pixel, so the rectangle was also
usually far too big: for Dane County Census blocks at -pt, the median
rectangle had 11 times the area of the polygon it replaced. Polygons that
are within about a pixel in every direction still get the rectangle, which
is then one pixel. With --no-spindle-preservation, the rectangle is still
used.
* Fix Wagyu's snap rounding so that an edge that intersects no other edge
is no longer snapped to a hot pixel whose corner it only touches, unless
that hot pixel is the rounded location of an intersection. Previously, two