mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-04 17:35:42 +02:00
Fix placement of label anchors in the tile buffer
The anchor point that `--convert-polygons-to-label-points` computes was stored in `serial_feature` as a single `unsigned long long`, the Morton index of two *unsigned 32-bit* coordinates. That representation cost two things: * `SHIFT_LEFT` can legitimately put an anchor outside the [0, 2^32) plane -- that is exactly what happens for a feature reaching into a tile's buffer -- but `encode_index` only takes 32-bit unsigned values, so the anchor was masked with `& ((1LL << 32) - 1)` on the way in. An anchor just west or north of the plane wrapped around to the far edge of the world rather than staying where it was. This is most visible in the buffer of the z0 tile, whose own bounds are the whole plane, so every buffer anchor is out of range. * Zero was overloaded as "no anchor," but zero is also the index of the legitimate world coordinate (0, 0). Store the anchor as a pair of signed `long long` coordinates with an explicit `has_label_point` flag instead. The serialized form grows from one varint to two, both zigzag-encoded so negative coordinates round-trip; this is the internal geometry temp file, not tile output, so nothing external depends on the layout. `write_tile` now checks the flag rather than relying on the sentinel, and drops the feature when there is no anchor instead of quietly tiling one at (0, 0). `checkerboard_anchors` gains the tile buffer as a parameter and short-circuits: if the real anchor lies within the tile plus its buffer, emit it directly rather than searching the repeating checkerboard for a substitute. Computing `ty2` is what makes that test possible -- it had been commented out because only `tx2` was needed for the label spacing. The one place this changes test output is tests/ne_110m_admin_0_countries/out/-z2_--convert-polygons-to-label-points.json, where Antarctica's anchors move. That fixture is regenerated here. CHANGELOG and version follow this repo's conventions: an entry under a new 2.81.1 heading, patch rather than minor since this only fixes behavior. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NcSXLjtokxioaBCCwGTEv1
This commit is contained in:
+1
-1
@@ -89,7 +89,7 @@ void check_polygon(drawvec &geom);
|
||||
double get_area(const drawvec &geom, size_t i, size_t j);
|
||||
double get_mp_area(drawvec &geom);
|
||||
drawvec polygon_to_anchor(const drawvec &geom);
|
||||
drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigned long long label_point);
|
||||
drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, long long wx, long long wy, int buffer);
|
||||
|
||||
drawvec simple_clip_poly(drawvec &geom, int z, int buffer, drawvec &shared_nodes, bool prevent_simplify_shared_nodes);
|
||||
drawvec simple_clip_poly(drawvec &geom, long long x1, long long y1, long long x2, long long y2, bool prevent_simplify_shared_nodes);
|
||||
|
||||
Reference in New Issue
Block a user