From 33052aa60bedeb0d049fcf9bf856765bfb851859 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Tue, 14 Nov 2023 18:00:03 -0800 Subject: [PATCH] Make polygon scaling its own function --- polygon.cpp | 17 ++++++++++------- polygon.hpp | 3 ++- tile.cpp | 28 ++-------------------------- 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/polygon.cpp b/polygon.cpp index 4515539d..7b323455 100644 --- a/polygon.cpp +++ b/polygon.cpp @@ -40,7 +40,12 @@ struct point { typedef std::pair segment; -bool visible(segment const &seg, long long extent) { +bool spindle_visible(segment const &seg, long long extent) { + if (extent == 0) { + // extent of 0 means no spindle revival + return false; + } + long long minx = std::min(seg.first.x, seg.second.x); long long miny = std::min(seg.first.y, seg.second.y); long long maxx = std::max(seg.first.x, seg.second.x); @@ -77,7 +82,7 @@ bool fix_opposites(std::vector &segs, std::set &affected, long long long dx = segs[i].second.x - segs[i].first.x; long long dy = segs[i].second.y - segs[i].first.y; long long dsq = dx * dx + dy * dy; - if (visible(segs[i], extent) && dsq >= 5 * 5) { + if (spindle_visible(segs[i], extent) && dsq >= 5 * 5) { // alter the segment instead to keep it from collapsing away double ang = atan2(dy, dx) - M_PI / 2; @@ -694,7 +699,7 @@ double triangle_area(drawvec const &geom, size_t base, size_t increment, size_t return area; } -drawvec scale_poly(drawvec const &geom, int z, int detail) { +drawvec scale_polygon(drawvec const &geom, int z, int detail) { double scale = 1LL << (32 - detail - z); drawvec out; @@ -762,9 +767,7 @@ drawvec scale_poly(drawvec const &geom, int z, int detail) { return out; } -drawvec clean_polygon(drawvec geom, int z, int detail) { - geom = scale_poly(geom, z, detail); - +drawvec clean_polygon(drawvec geom, long long extent) { // decompose polygon rings into segments std::vector> segments; @@ -796,7 +799,7 @@ drawvec clean_polygon(drawvec geom, int z, int detail) { // snap-round intersecting segments - snap_round(segments, 1LL << detail); + snap_round(segments, extent); // reassemble segments into rings diff --git a/polygon.hpp b/polygon.hpp index 1f23d3cf..dcb8f490 100644 --- a/polygon.hpp +++ b/polygon.hpp @@ -1 +1,2 @@ -drawvec clean_polygon(drawvec geom, int z, int detail); +drawvec clean_polygon(drawvec geom, long long extent); +drawvec scale_polygon(drawvec const &geom, int z, int detail); diff --git a/tile.cpp b/tile.cpp index b4e62c76..82f360c3 100644 --- a/tile.cpp +++ b/tile.cpp @@ -615,36 +615,12 @@ void *partial_feature_worker(void *v) { drawvec geom = (*partials)[i].geoms[0]; if (t == VT_POLYGON) { - geom = clean_polygon(geom, z, out_detail); - // (*partials)[i].t = t = VT_LINE; + geom = scale_polygon(geom, z, out_detail); + geom = clean_polygon(geom, 1LL << out_detail); } else { to_tile_scale(geom, z, out_detail); } -#if 0 - if (t == VT_POLYGON) { - // Scaling may have made the polygon degenerate. - // Give Clipper a chance to try to fix it. - { - drawvec before = geom; - // we can try scaling up because this is now tile scale - geom = clean_or_clip_poly(geom, 0, 0, false, true); - if (additional[A_DEBUG_POLYGON]) { - check_polygon(geom); - } - - if (geom.size() < 3) { - if (area > 0) { - // area is in world coordinates, calculated before scaling down - geom = revive_polygon(before, area, z, out_detail); - } else { - geom.clear(); - } - } - } - } -#endif - if (t == VT_POLYGON && additional[A_GENERATE_POLYGON_LABEL_POINTS]) { t = (*partials)[i].t = VT_POINT; geom = checkerboard_anchors(from_tile_scale(geom, z, out_detail), (*partials)[i].tx, (*partials)[i].ty, z, (*partials)[i].label_point);