mirror of
https://github.com/felt/tippecanoe.git
synced 2026-12-05 06:41:41 +01:00
With -pn, give area covered by more than one polygon to the earliest
Consistent snapping keeps the borders of polygons in a layer from crossing, but where rounding turned a narrow polygon between two others inside out (for example, a Census block thinner than a pixel whose two sides cross when rounded to tile coordinates), the area it covered is covered by both of its neighbors, and snapping can't decide which of them it belongs to. So after cleaning the polygons of each layer, find the ones that overlap: two polygons that share an edge in the same direction both cover the area beside it (neighbors that tile exactly traverse their shared border in opposite directions), and where their borders don't share any edges, a vertex of one is strictly inside the other. Then remove each overlapping area from all but the polygon with the lowest sequence number, using the layer's hot pixels so the result stays consistent with the rest. For Dane County Census blocks at -D8 -d8 -pt -pn, this reduces the overlapping pixels at z8, z9, and z10 from 41, 61, and 61 to 7, 8, and 16, without changing the gaps much or taking noticeably longer, and with no self-intersecting polygons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CQ6vQUJtmGZnqz7RmVYQaJ
This commit is contained in:
@@ -826,3 +826,40 @@ TEST_CASE("Consistent snapping doesn't make neighboring polygons' edges cross",
|
||||
}
|
||||
REQUIRE(crossings == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Overlaps between polygons go to the earlier polygon", "[wagyu]") {
|
||||
auto ring = [](std::vector<std::pair<long long, long long>> pts) {
|
||||
drawvec g;
|
||||
for (size_t i = 0; i < pts.size(); i++) {
|
||||
g.push_back(draw(i == 0 ? VT_MOVETO : VT_LINETO, pts[i].first, pts[i].second));
|
||||
}
|
||||
g.push_back(draw(VT_LINETO, pts[0].first, pts[0].second));
|
||||
if (get_area(g, 0, g.size()) < 0) {
|
||||
std::reverse(g.begin(), g.end());
|
||||
g[0].op = VT_MOVETO;
|
||||
g[g.size() - 1].op = VT_LINETO;
|
||||
}
|
||||
return g;
|
||||
};
|
||||
|
||||
// Two squares that overlap in a 2x10 strip, without sharing any edges
|
||||
drawvec first = ring({{0, 0}, {10, 0}, {10, 10}, {0, 10}});
|
||||
drawvec second = ring({{8, 0}, {20, 0}, {20, 10}, {8, 10}});
|
||||
// and one that shares a border with the first in the same direction,
|
||||
// so that it covers the same triangle beside it
|
||||
drawvec third = ring({{0, 10}, {10, 10}, {5, 5}});
|
||||
|
||||
// Clean them consistently first, as tippecanoe does, which splits
|
||||
// each square's edges where the other's corners touch them
|
||||
hot_pixel_list hot = layer_hot_pixels({&first, &second, &third});
|
||||
bool ok;
|
||||
first = clean_polygon_with_hot_pixels(first, hot, &ok);
|
||||
second = clean_polygon_with_hot_pixels(second, hot, &ok);
|
||||
third = clean_polygon_with_hot_pixels(third, hot, &ok);
|
||||
std::vector<drawvec *> geoms = {&first, &second, &third};
|
||||
|
||||
REQUIRE(remove_overlaps(geoms, &hot) == 2);
|
||||
REQUIRE(get_mp_area(first) == 100);
|
||||
REQUIRE(get_mp_area(second) == 100);
|
||||
REQUIRE(get_mp_area(third) == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user