From 5878ac5aaf675ecfad33500d8cd43d0a58ff4c70 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 18 Jan 2024 11:05:45 -0800 Subject: [PATCH] Updated revision of polygon triangulation from 0a67dd3fdd5be0f4e2e6d8cbfdbeb8e7cacaaf11 This maintains the primary goal of ensuring that bad splits do not allow the triangulation process to continue. Instead, we boot this back up to the top-level where we will simplify the polygon before triangulating again. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16624 (cherry picked from commit f1dacf7d922543a4a3c0f76d7762cace4259f93d) --- libs/kimath/include/geometry/polygon_triangulation.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libs/kimath/include/geometry/polygon_triangulation.h b/libs/kimath/include/geometry/polygon_triangulation.h index 53a71aa3f7..9d714fe5ac 100644 --- a/libs/kimath/include/geometry/polygon_triangulation.h +++ b/libs/kimath/include/geometry/polygon_triangulation.h @@ -489,7 +489,7 @@ private: } // If we don't have any NULL triangles left, cut the polygon in two and try again - if ( !splitPolygon( aPoint ) ) + if( !splitPolygon( aPoint ) ) return false; break; @@ -662,9 +662,10 @@ private: * Check if a segment joining two vertices lies fully inside the polygon. * To do this, we first ensure that the line isn't along the polygon edge. * Next, we know that if the line doesn't intersect the polygon, then it is - * either fully inside or fully outside the polygon. Finally, by checking whether - * the segment is enclosed by the local triangles, we distinguish between - * these two cases and no further checks are needed. + * either fully inside or fully outside the polygon. Next, we ensure that + * the proposed split is inside the local area of the polygon at both ends + * and the midpoint. Finally, we check to split creates two new polygons, + * each with positive area. */ bool goodSplit( const Vertex* a, const Vertex* b ) const { @@ -710,9 +711,6 @@ private: */ bool intersects( const Vertex* p1, const Vertex* q1, const Vertex* p2, const Vertex* q2 ) const { - if( ( *p1 == *q1 && *p2 == *q2 ) || ( *p1 == *q2 && *p2 == *q1 ) ) - return true; - int sign1 = sign( area( p1, q1, p2 ) ); int sign2 = sign( area( p1, q1, q2 ) ); int sign3 = sign( area( p2, q2, p1 ) );