From 8d9f1e61639f2c8e8be6a927f79a16eb840d9b24 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Fri, 22 Dec 2023 13:08:35 -0800 Subject: [PATCH] Add special case for collinear verticals --- polygon.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/polygon.cpp b/polygon.cpp index 310a6c1f..bf8f1da9 100644 --- a/polygon.cpp +++ b/polygon.cpp @@ -359,6 +359,7 @@ void snap_round(std::vector &segs, long long extent) { // index by y coordinates std::vector transitions; + std::vector> verticals; for (size_t i = 0; i < segs.size(); i++) { if (segs[i].first.y < segs[i].second.y) { @@ -370,9 +371,24 @@ void snap_round(std::vector &segs, long long extent) { } else { transitions.emplace_back(segs[i].first.y, 0, i); // horizontal } + + if (segs[i].first.x == segs[i].second.x) { + verticals.emplace_back(segs[i].first.x, i); + } } std::sort(transitions.begin(), transitions.end()); + std::sort(verticals.begin(), verticals.end()); + + // Intersect any verticals at the same X coordinate with each other + + for (size_t i = 0; i + 1 < verticals.size(); i++) { + if (verticals[i].first == verticals[i + 1].first) { + if (intersect(segs, verticals[i].second, verticals[i + 1].second)) { + again = true; + } + } + } // do the scan