From ee9847a904ad984d13e5ecac112c54fff00a05b8 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 23 Dec 2022 13:26:41 +0300 Subject: [PATCH] Fix cg::delaunay for some weird circular cases --- libs/cg/include/psemek/cg/triangulation/delaunay.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/cg/include/psemek/cg/triangulation/delaunay.hpp b/libs/cg/include/psemek/cg/triangulation/delaunay.hpp index f5e46816..af204f2d 100644 --- a/libs/cg/include/psemek/cg/triangulation/delaunay.hpp +++ b/libs/cg/include/psemek/cg/triangulation/delaunay.hpp @@ -4,6 +4,7 @@ #include #include +#include namespace psemek::cg { @@ -12,6 +13,7 @@ namespace psemek::cg auto delaunay(RobustTag robust_tag, InputIterator begin, InputIterator end) { std::vector edge_queue; + std::vector flipped_set; auto at = [&](Index i){ return *(begin + i); }; @@ -62,6 +64,8 @@ namespace psemek::cg // decide if a flip is needed if (in_circle(robust_tag, at(p0.index()), at(p1.index()), at(p2.index()), at(p3.index())) != geom::sign_t::positive) continue; + flipped_set.insert(std::lower_bound(flipped_set.begin(), flipped_set.end(), e.index()), e.index()); + auto f0 = e.face(); auto f1 = twin.face(); @@ -81,15 +85,17 @@ namespace psemek::cg tprev.face(f0); tprev.next(next); next.prev(tprev); + p0.edge(prev); p1.edge(tnext); p2.edge(next); + p3.edge(tprev); f0.edge(e); f1.edge(twin); auto push = [&](auto e) { - if (e.twin().face() != outer_face) + if (e.twin().face() != outer_face && !std::binary_search(flipped_set.begin(), flipped_set.end(), e.index())) edge_queue.push_back(e.index()); }; @@ -98,6 +104,8 @@ namespace psemek::cg push(tnext); push(tprev); } + + flipped_set.clear(); }; return detail::triangulate(robust_tag, begin, end, callback); }