@@ -360,6 +360,9 @@ namespace PCGExClipper2Lib
360360 static IntersectKind SegsIntersect (const Point64 s1a, const Point64 s1b,
361361 const Point64 s2a, const Point64 s2b)
362362 {
363+ // ignore segments sharing an end-point
364+ if (s1a == s2a || s1b == s2a || s1b == s2b) return IntersectKind::none;
365+
363366 double dy1 = static_cast <double >(s1b.y - s1a.y );
364367 double dx1 = static_cast <double >(s1b.x - s1a.x );
365368 double dy2 = static_cast <double >(s2b.y - s2a.y );
@@ -372,12 +375,9 @@ namespace PCGExClipper2Lib
372375
373376 double t = (static_cast <double >(s1a.x - s2a.x ) * dy2 -
374377 static_cast <double >(s1a.y - s2a.y ) * dx2);
375- // ignore segments that 'intersect' at an end-point
376- if (t == 0 )
377- {
378- return IntersectKind::none;
379- }
380- if (t > 0 )
378+
379+ // nb: testing for t == 0 is unreliable due to float imprecision
380+ if (t >= 0 )
381381 {
382382 if (cp < 0 || t >= cp)
383383 {
@@ -395,11 +395,7 @@ namespace PCGExClipper2Lib
395395 // so far, the *segment* 's1' intersects the *line* through 's2',
396396 // but now make sure it also intersects the *segment* 's2'
397397 t = ((s1a.x - s2a.x ) * dy1 - (s1a.y - s2a.y ) * dx1);
398- if (t == 0 )
399- {
400- return IntersectKind::none;
401- }
402- if (t > 0 )
398+ if (t >= 0 )
403399 {
404400 if (cp > 0 && t < cp)
405401 {
@@ -1539,7 +1535,7 @@ namespace PCGExClipper2Lib
15391535
15401536 TriangulateResult Triangulate (const PathsD& pp, int decPlaces, PathsD& solution, bool useDelaunay)
15411537 {
1542- int ec;
1538+ int ec = 0 ;
15431539 double scale;
15441540 TriangulateResult result;
15451541 if (decPlaces <= 0 )
@@ -1722,7 +1718,7 @@ namespace PCGExClipper2Lib
17221718 return TriangulateResult::no_polygons;
17231719 }
17241720
1725- int ec;
1721+ int ec = 0 ;
17261722 double scale;
17271723 if (decPlaces <= 0 )
17281724 {
@@ -1778,7 +1774,7 @@ namespace PCGExClipper2Lib
17781774 }
17791775
17801776 // Convert to int64 for triangulation
1781- int ec;
1777+ int ec = 0 ;
17821778 Paths64 pathsToTriangulate;
17831779 pathsToTriangulate.reserve (1 + node->Count ());
17841780
0 commit comments