From 8b14f399c1455e489a08fdef5ecd9fd3ab445eec Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 3 Nov 2020 18:42:04 +0100 Subject: [PATCH] csg2d - fix bug in getNonIntersectionVertex() If a loop has no non-intersecting vertex, a new one is inserted -> set all vertex properties correctly (info, spline) --- libsrc/geom2d/csg2d.cpp | 33 +++++++++++++++++++++++++++++++++ libsrc/geom2d/csg2d.hpp | 26 +++++--------------------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/libsrc/geom2d/csg2d.cpp b/libsrc/geom2d/csg2d.cpp index a96986b8..01e20981 100644 --- a/libsrc/geom2d/csg2d.cpp +++ b/libsrc/geom2d/csg2d.cpp @@ -1565,6 +1565,39 @@ Solid2d ClipSolids ( Solid2d && s1, Solid2d && s2, char op) return std::move(res); } +Vertex* Loop :: getNonIntersectionVertex() + { + for (Vertex* v : Vertices(ALL)) + if (!v->is_intersection) + return(v); + + // no non-intersection vertex found -> generate and return temporary vertex + for (Vertex* v : Vertices(ALL)) + // make sure that edge from V to V->next is not collinear with other polygon + if ( (v->next->neighbour != v->neighbour->prev) && (v->next->neighbour != v->neighbour->next) ) + { + // add edge midpoint as temporary vertex + if(v->spline) + { + auto p = v->spline->GetPoint(0.5); + auto s = *v->spline; + v->spline = Split(s, 0, 0.5); + auto vnew = v->Insert(p); + vnew->info = v->info; + vnew->spline = Split(s, 0.5, 1.0); + return vnew; + } + else + { + auto p = Center(*v, *v->next); + auto vnew = v->Insert(p); + vnew->info = v->info; + return vnew; + } + } + return(NULL); + } + bool Loop :: IsInside( Point<2> r ) const { int w = 0; diff --git a/libsrc/geom2d/csg2d.hpp b/libsrc/geom2d/csg2d.hpp index 118060f8..42c44a89 100644 --- a/libsrc/geom2d/csg2d.hpp +++ b/libsrc/geom2d/csg2d.hpp @@ -29,10 +29,10 @@ enum IntersectionType T_INTERSECTION_Q, T_INTERSECTION_P, V_INTERSECTION, - X_OVERLAP, - T_OVERLAP_Q, - T_OVERLAP_P, - V_OVERLAP + X_OVERLAP, // Q0 -- P1 -- Q1 -- P0 (different direction) + T_OVERLAP_Q, // same direction or P inside Q + T_OVERLAP_P, // same direction or Q inside P + V_OVERLAP // one common point }; enum IntersectionLabel @@ -588,23 +588,7 @@ struct Loop // // return and insert a non-intersection vertex // - Vertex* getNonIntersectionVertex() - { - for (Vertex* v : Vertices(ALL)) - if (!v->is_intersection) - return(v); - - // no non-intersection vertex found -> generate and return temporary vertex - for (Vertex* v : Vertices(ALL)) - // make sure that edge from V to V->next is not collinear with other polygon - if ( (v->next->neighbour != v->neighbour->prev) && (v->next->neighbour != v->neighbour->next) ) - { - // add edge midpoint as temporary vertex - auto p = Center(*v, *v->next); - return v->Insert(p); - } - return(NULL); - } + Vertex* getNonIntersectionVertex(); void SetBC(string bc) {