With -pn, don't add spindle strips that would overlap neighboring features

A spindle strip extends one pixel past the far side of the narrow part it
preserves, so a panhandle between two neighboring features (or any narrow
part whose far side borders another feature) would overlap its neighbors
by up to a pixel, which is unfortunate for datasets that are meant to tile
exactly.

With --no-simplification-of-shared-nodes, the vertex pass already sorts every
polygon vertex with its neighbors to find the shared nodes. Each vertex record
now also carries the feature it came from, and the same pass writes out each
edge that is part of two or more different polygon features, as a sorted
table of half-edges. When a narrow edge's strip would extend past an edge
that is in that table, the strip is left out, so the panhandle collapses as
it used to and the features still tile exactly. A narrow part with open space
on its far side, like a coastal strip whose other side is a shared border,
still gets the strip along its shared side, which extends away from the
neighbor.

The table is only searched for edges that have already been found to be
narrow, not for every vertex, and since simplification may have removed
vertices along a shared border, an edge counts as shared if a shared edge
leaves either of its endpoints in its direction, within the simplification
tolerance. On a synthetic tiling (tests/spindle-shared), spindle
preservation with -pn adds no overlapping pixels at all compared to
--no-spindle-preservation, while without -pn the same data overlaps by
several hundred pixels per zoom level. On ne_10m_admin_0_countries -z8 -pn,
the time difference is within noise.

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 21:31:47 +00:00
parent 1963076817
commit 4352b1498f
14 changed files with 546 additions and 21 deletions
+19 -1
View File
@@ -3,10 +3,28 @@
#include "geometry.hpp"
// One direction of a polygon edge that is shared between two or more
// different polygon features, as identified by --no-simplification-of-shared-nodes,
// in world coordinates. The list of these is sorted by `a` (y, then x)
// and then by `b` (y, then x), and is used to avoid adding spindle strips
// along edges that border other features, where they would overlap them.
struct shared_edge {
long long ax, ay;
long long bx, by;
};
extern shared_edge *shared_edges_map;
extern size_t shared_edges_count;
// Find the parts of a polygon (in world coordinates) that are narrower than
// a pixel at zoom level z with the specified tile detail, and return strips
// (in tile coordinates) covering the pixels along them.
drawvec thin_polygon_strips(drawvec const &geom, int z, int detail);
//
// `simplification` is the simplification tolerance, in tile units, that the
// geometry was simplified with, which is how far a simplified shared border
// may have strayed from the original shared edges. (ox, oy) is the world
// coordinate of the tile origin that the geometry is relative to.
drawvec thin_polygon_strips(drawvec const &geom, int z, int detail, double simplification = 1, long long ox = 0, long long oy = 0);
// Union the strips from thin_polygon_strips() with a cleaned polygon
// (both in tile coordinates)