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
+41
View File
@@ -10,6 +10,8 @@
#include "jsonpull/jsonpull.h"
#include <unistd.h>
#include <limits.h>
#include <tuple>
#include <algorithm>
TEST_CASE("UTF-8 enforcement", "[utf8]") {
REQUIRE(check_utf8("") == std::string(""));
@@ -599,3 +601,42 @@ TEST_CASE("Polygons without narrow parts get no spindle strips", "[spindle]") {
// A shape that is already exact at tile resolution can't collapse
REQUIRE(thin_polygon_strips(world_ring({{100, 100}, {3000, 100}, {3000, 100.2}, {100, 100.2}}, 0), 20, detail).size() == 0);
}
TEST_CASE("Spindle strips are not added where they would overlap a neighboring feature", "[spindle]") {
const int z = 0, detail = 12, shift = 32 - detail - z;
const long long px = 1LL << shift;
// A strip 0.2 pixels wide and 3000 pixels long: a "panhandle"
// if both sides are shared, or a coastal strip if only one is
long long x1 = 100 * px, x2 = 3100 * px;
long long y1 = 1000 * px, y2 = 1000 * px + px / 5;
drawvec geom = world_ring({{100, 1000}, {3100, 1000}, {3100, 1000.2}, {100, 1000.2}}, shift);
REQUIRE(geom[2].y == y2);
auto with_shared = [&](std::vector<shared_edge> edges) {
std::sort(edges.begin(), edges.end(), [](shared_edge const &a, shared_edge const &b) {
return std::make_tuple(a.ay, a.ax, a.by, a.bx) < std::make_tuple(b.ay, b.ax, b.by, b.bx);
});
shared_edges_map = edges.data();
shared_edges_count = edges.size();
drawvec strips = thin_polygon_strips(geom, z, detail);
shared_edges_map = NULL;
shared_edges_count = 0;
return strips;
};
// No shared edges: both long sides get strips
drawvec none = with_shared({});
REQUIRE(none.size() == 2 * 5);
// Both long sides shared with neighbors: no strips at all
REQUIRE(with_shared({{x1, y1, x2, y1}, {x2, y1, x1, y1}, {x1, y2, x2, y2}, {x2, y2, x1, y2}}).size() == 0);
// Only the top side (y1) shared: only the strip along the shared side,
// which extends away from the neighbor, is kept
drawvec one = with_shared({{x1, y1, x2, y1}, {x2, y1, x1, y1}});
REQUIRE(one.size() == 5);
for (auto const &d : one) {
REQUIRE(d.y >= 1000);
}
}