mirror of
https://github.com/felt/tippecanoe.git
synced 2026-12-05 06:41:41 +01:00
Only exempt the unshared length of a ring from tiny polygon reduction
Long, narrow rings were exempted from tiny polygon reduction so that spindle preservation could keep them as lines. But with -pn, no strips are added along borders shared with other features, so a narrow block whose length is mostly shared border was exempted, then collapsed completely in cleaning, and was then replaced by revive_polygon()'s placeholder rectangle, which overlaps its neighbors. (In Dane County census blocks at -D8 -d8 -pn, this raised the number of revived polygons at z12 from 57 to 92.) Now only the part of the ring's length that is not made of shared edges counts toward the exemption, so such blocks are combined into tiny polygons as before. The shared edges can be matched exactly here, because tiny polygon reduction happens before simplification. reduce_tiny_poly() takes the length function as a callback because clip.cpp is also linked into tools that don't include polygon.cpp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CQ6vQUJtmGZnqz7RmVYQaJ
This commit is contained in:
@@ -1045,19 +1045,11 @@ static drawvec simplify_lines_basic(drawvec &geom, int z, int detail, double sim
|
||||
return geom;
|
||||
}
|
||||
|
||||
// A ring whose perimeter is more than this many times the tiny polygon size is long enough
|
||||
// A ring that is longer than this many times the tiny polygon size is long enough
|
||||
// to be visible as a line even if its area is too small to be visible as a polygon
|
||||
#define SPINDLE_PERIMETER 8
|
||||
|
||||
static double get_perimeter(drawvec const &geom, size_t i, size_t j) {
|
||||
double perimeter = 0;
|
||||
for (size_t k = i; k + 1 < j; k++) {
|
||||
perimeter += std::hypot((double) geom[k + 1].x - geom[k].x, (double) geom[k + 1].y - geom[k].y);
|
||||
}
|
||||
return perimeter;
|
||||
}
|
||||
|
||||
drawvec reduce_tiny_poly(drawvec const &geom, int z, int detail, bool *still_needs_simplification, bool *reduced_away, double *accum_area, double tiny_polygon_size, bool keep_spindles) {
|
||||
drawvec reduce_tiny_poly(drawvec const &geom, int z, int detail, bool *still_needs_simplification, bool *reduced_away, double *accum_area, double tiny_polygon_size, std::function<double(drawvec const &, size_t, size_t)> const &spindle_length) {
|
||||
drawvec out;
|
||||
const double pixel = (1LL << (32 - detail - z)) * (double) tiny_polygon_size;
|
||||
|
||||
@@ -1095,8 +1087,11 @@ drawvec reduce_tiny_poly(drawvec const &geom, int z, int detail, bool *still_nee
|
||||
//
|
||||
// But a long, narrow outer ring is not tiny even if its area is small,
|
||||
// so if we are preserving spindles, let it represent itself.
|
||||
// (The length that counts is the length that spindle preservation
|
||||
// can actually preserve, which leaves out borders shared with
|
||||
// other features if --no-simplification-of-shared-nodes is used.)
|
||||
bool tiny = (area > 0 && area <= pixel * pixel);
|
||||
if (tiny && keep_spindles && get_perimeter(geom, i, j) > SPINDLE_PERIMETER * pixel) {
|
||||
if (tiny && spindle_length && spindle_length(geom, i, j) > SPINDLE_PERIMETER * pixel) {
|
||||
tiny = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user