From e04b19916ed2125097a96501f5f7bce9d2ed73a6 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Fri, 8 Sep 2023 15:30:48 -0700 Subject: [PATCH] Self-intersections in the same feature don't count --- tile.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tile.cpp b/tile.cpp index 084c7232..d11a0e9a 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1298,8 +1298,9 @@ struct joint { draw p1; draw mid; draw p2; + size_t ring; - joint(draw one, draw hinge, draw two) { + joint(draw one, draw hinge, draw two, size_t r) { if (one < two) { p1 = one; p2 = two; @@ -1309,6 +1310,7 @@ struct joint { } mid = hinge; + ring = r; } bool operator<(const joint &o) const { @@ -2284,10 +2286,20 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch // j - 1 because we don't want the duplicate last point for (size_t k = i; k < j - 1; k++) { + if (sf.geometry[k] == sf.geometry[(k + 1 - i) % (j - 1 - i) + i]) { + abort(); + } + + if (sf.geometry[(k + 1 - i) % (j - 1 - i) + i] == + sf.geometry[(k + 2 - i) % (j - 1 - i) + i]) { + abort(); + } + shared_joints.emplace_back( sf.geometry[k], sf.geometry[(k + 1 - i) % (j - 1 - i) + i], - sf.geometry[(k + 2 - i) % (j - 1 - i) + i]); + sf.geometry[(k + 2 - i) % (j - 1 - i) + i], + seq); } printf("%lld,%lld ", sf.geometry[i].x, sf.geometry[i].y); @@ -2441,9 +2453,13 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch for (size_t i = 0; i + 1 < shared_joints.size(); i++) { if (shared_joints[i].mid == shared_joints[i + 1].mid) { // printf("%lld,%lld: ", shared_joints[i].mid.x, shared_joints[i].mid.y); - if (shared_joints[i].p1 != shared_joints[i + 1].p1 || - shared_joints[i].p2 != shared_joints[i + 1].p2) { + if ((shared_joints[i].p1 != shared_joints[i + 1].p1 || + shared_joints[i].p2 != shared_joints[i + 1].p2) && + (shared_joints[i].ring != shared_joints[i + 1].ring)) { shared_nodes.push_back(shared_joints[i].mid); + double lon, lat; + tile2lonlat(shared_joints[i].mid.x, shared_joints[i].mid.y, 32, &lon, &lat); + printf("{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[%f,%f]}}\n", lon, lat); // printf("different\n"); } else { // printf("same %lld,%lld to %lld,%lld\n", shared_joints[i].p1.x, shared_joints[i].p1.y, shared_joints[i].p2.x, shared_joints[i].p2.y);