mirror of
https://github.com/felt/tippecanoe.git
synced 2026-12-05 06:41:41 +01:00
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:
@@ -48,6 +48,7 @@
|
||||
#include "attribute.hpp"
|
||||
#include "thread.hpp"
|
||||
#include "shared_borders.hpp"
|
||||
#include "polygon.hpp"
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "plugin.hpp"
|
||||
|
||||
@@ -675,6 +676,16 @@ static void *simplification_worker(void *v) {
|
||||
int out_detail = (*features)[i]->extra_detail;
|
||||
|
||||
drawvec geom = (*features)[i]->geometry;
|
||||
|
||||
// Before rounding to tile coordinates, find any parts of the polygon
|
||||
// that are too narrow to survive the rounding, so they can be
|
||||
// restored as one-pixel-wide strips after cleaning.
|
||||
drawvec strips;
|
||||
// (Not when the geometry has been stairstepped onto a grid, which the strips would not follow.)
|
||||
if (t == VT_POLYGON && !prevent[P_SPINDLES] && !(additional[A_GRID_LOW_ZOOMS] && z < (*features)[i]->maxzoom)) {
|
||||
strips = thin_polygon_strips(geom, z, out_detail);
|
||||
}
|
||||
|
||||
to_tile_scale(geom, z, out_detail);
|
||||
|
||||
if (t == VT_POLYGON) {
|
||||
@@ -685,6 +696,7 @@ static void *simplification_worker(void *v) {
|
||||
|
||||
// we can try scaling up because this is now tile scale
|
||||
coalesce_polygon(geom, true);
|
||||
geom = union_polygon_strips(geom, strips);
|
||||
if (additional[A_DEBUG_POLYGON]) {
|
||||
check_polygon(geom);
|
||||
}
|
||||
@@ -1758,7 +1770,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
||||
|
||||
key_pool key_pool;
|
||||
|
||||
std::vector<std::atomic<bool> > within(child_shards);
|
||||
std::vector<std::atomic<bool>> within(child_shards);
|
||||
std::vector<long long> start_geompos(child_shards);
|
||||
for (size_t i = 0; i < (size_t) child_shards; i++) {
|
||||
within[i] = false;
|
||||
@@ -2159,7 +2171,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
||||
bool prevent_tiny = prevent[P_TINY_POLYGON_REDUCTION] ||
|
||||
(prevent[P_TINY_POLYGON_REDUCTION_AT_MAXZOOM] && z == maxzoom);
|
||||
if (!prevent_tiny && !additional[A_GRID_LOW_ZOOMS]) {
|
||||
sf.geometry = reduce_tiny_poly(sf.geometry, z, line_detail, &still_need_simplification_after_reduction, &simplified_away_by_reduction, &accum_area, tiny_polygon_size);
|
||||
sf.geometry = reduce_tiny_poly(sf.geometry, z, line_detail, &still_need_simplification_after_reduction, &simplified_away_by_reduction, &accum_area, tiny_polygon_size, !prevent[P_SPINDLES]);
|
||||
if (simplified_away_by_reduction) {
|
||||
strategy.tiny_polygons++;
|
||||
}
|
||||
@@ -3299,7 +3311,7 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *global_stringpool, std::
|
||||
|
||||
std::vector<compressor> compressors(TEMP_FILES);
|
||||
std::vector<compressor *> sub(TEMP_FILES);
|
||||
std::vector<std::atomic<long long> > subpos(TEMP_FILES);
|
||||
std::vector<std::atomic<long long>> subpos(TEMP_FILES);
|
||||
std::vector<int> subfd(TEMP_FILES);
|
||||
for (size_t j = 0; j < TEMP_FILES; j++) {
|
||||
std::string geomname = std::string(tmpdir) + "/geom" + std::to_string(j) + ".XXXXXXXX";
|
||||
|
||||
Reference in New Issue
Block a user