Preserve spindle polygons as one-pixel-wide strips instead of letting them collapse

A polygon (or part of a polygon) narrower than a tile pixel, like a
1-meter buffer around a long linestring, used to collapse away to nothing
at most zoom levels when it was rounded to tile coordinates, except for
scattered fragments wherever the rounding happened to keep its two sides
apart.

Now, before the geometry is rounded, thin_polygon_strips() looks for edges
that have an oppositely-directed edge less than sqrt(2) tile units away
(the most that rounding can move two boundaries toward each other) and
that is not just the other side of a corner (the two points must also be
far apart along the ring). Candidate pairs are found with a sweep over the
edges' bounding boxes, so polygons without narrow parts cost little more
than sorting their edges. Each narrow edge gets a one-unit-wide strip, one
side of which is the edge as it will be rounded and the other side of which
is offset one unit toward the polygon's interior, so the strips lie within
the polygon wherever it is already thick enough, and they are unioned with
the cleaned polygon. The union is done at 16x resolution, because the
strips from the two sides of a spindle are nearly coincident and wagyu's
own snap rounding would otherwise collapse them in places.

Long, narrow polygons whose perimeter is more than 8 times the tiny polygon
size are also no longer combined into tiny-polygon squares, so a spindle
stays visible down to the zoom level where it is shorter than that.

--no-spindle-preservation restores the old behavior.

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 20:03:31 +00:00
parent a888304b19
commit 957b1cd9b9
79 changed files with 10076 additions and 9090 deletions
+22 -2
View File
@@ -1045,7 +1045,19 @@ static drawvec simplify_lines_basic(drawvec &geom, int z, int detail, double sim
return geom;
}
drawvec reduce_tiny_poly(drawvec const &geom, int z, int detail, bool *still_needs_simplification, bool *reduced_away, double *accum_area, double tiny_polygon_size) {
// A ring whose perimeter is more than this many times the tiny polygon size is long enough
// to be visible as a line even if its area is too small to be visible as a polygon
#define SPINDLE_PERIMETER 8
static double get_perimeter(drawvec const &geom, size_t i, size_t j) {
double perimeter = 0;
for (size_t k = i; k + 1 < j; k++) {
perimeter += std::hypot((double) geom[k + 1].x - geom[k].x, (double) geom[k + 1].y - geom[k].y);
}
return perimeter;
}
drawvec reduce_tiny_poly(drawvec const &geom, int z, int detail, bool *still_needs_simplification, bool *reduced_away, double *accum_area, double tiny_polygon_size, bool keep_spindles) {
drawvec out;
const double pixel = (1LL << (32 - detail - z)) * (double) tiny_polygon_size;
@@ -1080,7 +1092,15 @@ drawvec reduce_tiny_poly(drawvec const &geom, int z, int detail, bool *still_nee
// OR it is an inner ring and we haven't output an outer ring for it to be
// cut out of, so we are just subtracting its area from the tiny polygon
// rather than trying to deal with it geometrically
if ((area > 0 && area <= pixel * pixel) || (area < 0 && !included_last_outer)) {
//
// But a long, narrow outer ring is not tiny even if its area is small,
// so if we are preserving spindles, let it represent itself.
bool tiny = (area > 0 && area <= pixel * pixel);
if (tiny && keep_spindles && get_perimeter(geom, i, j) > SPINDLE_PERIMETER * pixel) {
tiny = false;
}
if (tiny || (area < 0 && !included_last_outer)) {
*accum_area += area;
*reduced_away = true;