From 7cb7fc4913886059da412cebc0885a3d538cb38a Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 21 Oct 2016 18:00:46 -0700 Subject: [PATCH] Fix where I was inserting the copied ring in backwards order --- tile.cpp | 175 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 111 insertions(+), 64 deletions(-) diff --git a/tile.cpp b/tile.cpp index d7c27687..6d187132 100644 --- a/tile.cpp +++ b/tile.cpp @@ -900,70 +900,6 @@ void find_common_edges(std::vector &partials, int z, int line_detail, d } } - for (size_t i = 0; i < partials.size(); i++) { - for (size_t j = 0; j < partials[i].arc_polygon.size(); j++) { - if (merge_candidates.count(-partials[i].arc_polygon[j]) > 0) { - auto r = merge_candidates.equal_range(-partials[i].arc_polygon[j]); - for (auto a = r.first; a != r.second; ++a) { - if (a->second != i && partials[a->second].arc_polygon.size() > 0) { - // This has to merge the ring that contains the anti-arc to this arc - // into the current ring, and then add whatever other rings were in - // that feature on to the end. - // - // This can't be good for keeping parent-child relationships among - // the rings in order, but Wagyu should sort that out later - - std::vector additions; - std::vector &here = partials[i].arc_polygon; - std::vector &other = partials[a->second].arc_polygon; - for (size_t k = 0; k < other.size(); k++) { - size_t l; - for (l = k; l < other.size(); l++) { - if (other[l] == 0) { - break; - } - } - - size_t m; - for (m = k; m <= l; m++) { - if (other[m] == -partials[i].arc_polygon[j]) { - break; - } - } - - if (m <= k) { - // Found the shared arc - - here.erase(here.begin() + j); - - for (size_t n = m + 1; n < l; n++) { - here.insert(here.begin() + j, other[n]); - } - for (size_t n = k; n < m; n++) { - here.insert(here.begin() + j, other[n]); - } - } else { - // Looking at some other ring - - for (size_t n = k; n <= l; n++) { - additions.push_back(other[n]); - } - } - - k = l; - } - - partials[a->second].arc_polygon.clear(); - - for (size_t k = 0; k < additions.size(); k++) { - partials[i].arc_polygon.push_back(additions[k]); - } - } - } - } - } - } - std::vector simplified_arcs; size_t count = 0; @@ -988,6 +924,117 @@ void find_common_edges(std::vector &partials, int z, int line_detail, d count++; } + for (size_t i = 0; i < partials.size(); i++) { + for (size_t j = 0; j < partials[i].arc_polygon.size(); j++) { + if (merge_candidates.count(-partials[i].arc_polygon[j]) > 0) { + auto r = merge_candidates.equal_range(-partials[i].arc_polygon[j]); + for (auto a = r.first; a != r.second; ++a) { + if (a->second != i && partials[a->second].arc_polygon.size() > 0) { + // This has to merge the ring that contains the anti-arc to this arc + // into the current ring, and then add whatever other rings were in + // that feature on to the end. + // + // This can't be good for keeping parent-child relationships among + // the rings in order, but Wagyu should sort that out later + + std::vector additions; + std::vector &here = partials[i].arc_polygon; + std::vector &other = partials[a->second].arc_polygon; + +#if 0 + printf("seeking %zd\n", partials[i].arc_polygon[j]); + printf("before: "); + for (size_t k = 0; k < here.size(); k++) { + printf("%zd ", here[k]); + } + printf("\n"); + printf("other: "); + for (size_t k = 0; k < other.size(); k++) { + printf("%zd ", other[k]); + } + printf("\n"); +#endif + + for (size_t k = 0; k < other.size(); k++) { + size_t l; + for (l = k; l < other.size(); l++) { + if (other[l] == 0) { + break; + } + } + if (l >= other.size()) { + l--; + } + +#if 0 + for (size_t m = k; m <= l; m++) { + printf("%zd ", other[m]); + } + printf("\n"); +#endif + + size_t m; + for (m = k; m <= l; m++) { + if (other[m] == -partials[i].arc_polygon[j]) { + break; + } + } + + if (m <= l) { + // Found the shared arc + + here.erase(here.begin() + j); + + size_t off = 0; + for (size_t n = m + 1; n < l; n++) { + here.insert(here.begin() + j + off, other[n]); + off++; + } + for (size_t n = k; n < m; n++) { + here.insert(here.begin() + j + off, other[n]); + off++; + } + } else { + // Looking at some other ring + + for (size_t n = k; n <= l; n++) { + additions.push_back(other[n]); + } + } + + k = l; + } + + partials[a->second].arc_polygon.clear(); + + for (size_t k = 0; k < additions.size(); k++) { + partials[i].arc_polygon.push_back(additions[k]); + } + +#if 0 + printf("after: "); + for (size_t k = 0; k < here.size(); k++) { + printf("%zd ", here[k]); + } + printf("\n"); +#endif + +#if 0 + for (size_t k = 0; k + 1 < here.size(); k++) { + if (here[k] != 0 && here[k + 1] != 0) { + if (simplified_arcs[here[k + 1]][0] != simplified_arcs[here[k]][simplified_arcs[here[k]].size() - 1]) { + printf("error from %zd to %zd\n", here[k], here[k + 1]); + } + } + } +#endif + } + } + } + } + } + + for (size_t i = 0; i < partials.size(); i++) { if (partials[i].t == VT_POLYGON) { partials[i].geoms.resize(0);