Commit Graph
4 Commits
Author SHA1 Message Date
Claude c062c4a240 Identify features for shared-edge detection by layer, segment, and seq
Features don't necessarily have IDs, and sequence numbers are only unique
within a layer and a reading segment: the flatgeobuf, geobuf, and CSV
readers start every segment's sequence at the same offset and parse in
parallel, so two different features can have the same seq. Record all
three in each vertex record, and only count an edge as shared if it is
part of polygons that differ in any of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQ6vQUJtmGZnqz7RmVYQaJ
2026-11-30 21:38:40 +00:00
Claude 4352b1498f 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
2026-11-30 21:31:47 +00:00
Claude 1963076817 Fall back instead of exiting when wagyu fails on a spindle strip union
On arm64, clang contracts floating point multiply-adds into FMA
instructions, which changes wagyu's intersection arithmetic enough that
it can fail on some strip unions with "Trying to find intersection of
lines that do not intersect" (seen with ne_10m_admin_0_countries at
-D10 -d10 -zg; reproducible on x86 with -mfma -ffp-contract=fast, where
2 of 4426 unions failed).

The strips are only an improvement on an already-valid cleaned polygon,
so if the union fails at 16x resolution, retry it at tile resolution,
and if that fails too, keep the cleaned polygon without strips. The
re-cleaning of the union after rounding it back to tile resolution also
no longer goes through clean_or_clip_poly(), which exits on failure, but
does the same thing (16x if the result is exact, otherwise 1x) with the
same fallbacks. Output where wagyu doesn't fail is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQ6vQUJtmGZnqz7RmVYQaJ
2026-11-30 20:52:29 +00:00
Claude 957b1cd9b9 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
2026-11-30 20:03:31 +00:00