From 7dd0c67afda30ecca3ed6138e5498fb97cdf664d Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 25 May 2022 13:19:07 -0700 Subject: [PATCH] Handle hand-drawn holes in unfracture We can't know that all holes will be ccw when entering unfracture. Instead, we set the largest polyline to be the outline and the others to be the holes. (cherry picked from commit 1fe956c06961ad7e1364f8e9ea6d6c55218570e1) --- libs/kimath/src/geometry/shape_poly_set.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index c2eae1b368..3ef6b90333 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -1207,6 +1207,7 @@ void SHAPE_POLY_SET::unfractureSingle( SHAPE_POLY_SET::POLYGON& aPoly ) int outline = -1; POLYGON result; + double max_poly; while( queue.size() ) { @@ -1231,10 +1232,13 @@ void SHAPE_POLY_SET::unfractureSingle( SHAPE_POLY_SET::POLYGON& aPoly ) outl.SetClosed( true ); - bool cw = outl.Area() > 0.0; + double area = std::fabs( outl.Area() ); - if( cw ) + if( area > max_poly ) + { outline = n; + max_poly = area; + } result.push_back( outl ); n++;