From b324abefe5be7f73ba946fc844b725b866a2c178 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 26 Aug 2022 16:41:04 -0700 Subject: [PATCH] Handle cases where Simplify removes all outlines This could theoretically happen for a fully degenerate polygon Fixes https://gitlab.com/kicad/code/kicad/issues/12120 (cherry picked from commit 5a37211fdb0d565be640ea1c224f68f1b0475ba3) --- bitmap2component/bitmap2component.cpp | 27 +++++++++++---------- libs/kimath/src/geometry/shape_poly_set.cpp | 4 ++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/bitmap2component/bitmap2component.cpp b/bitmap2component/bitmap2component.cpp index 648064953a..74ffb62d13 100644 --- a/bitmap2component/bitmap2component.cpp +++ b/bitmap2component/bitmap2component.cpp @@ -503,21 +503,22 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer ) polyset_areas.BooleanSubtract( polyset_holes, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); // Ensure there are no self intersecting polygons - polyset_areas.NormalizeAreaOutlines(); - - // Convert polygon with holes to a unique polygon - polyset_areas.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); - - // Output current resulting polygon(s) - for( int ii = 0; ii < polyset_areas.OutlineCount(); ii++ ) + if( polyset_areas.NormalizeAreaOutlines() ) { - SHAPE_LINE_CHAIN& poly = polyset_areas.Outline( ii ); - outputOnePolygon( poly, getBoardLayerName( aModLayer )); - } + // Convert polygon with holes to a unique polygon + polyset_areas.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); - polyset_areas.RemoveAllContours(); - polyset_holes.RemoveAllContours(); - main_outline = true; + // Output current resulting polygon(s) + for( int ii = 0; ii < polyset_areas.OutlineCount(); ii++ ) + { + SHAPE_LINE_CHAIN& poly = polyset_areas.Outline( ii ); + outputOnePolygon( poly, getBoardLayerName( aModLayer )); + } + + polyset_areas.RemoveAllContours(); + polyset_holes.RemoveAllContours(); + main_outline = true; + } } paths = paths->next; diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index e58fddfeb2..e1d4bd4341 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -1294,7 +1294,9 @@ int SHAPE_POLY_SET::NormalizeAreaOutlines() BooleanSubtract( holesBuffer, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); } - RemoveNullSegments(); + // In degenerate cases, simplify might return no outlines + if( OutlineCount() > 0 ) + RemoveNullSegments(); return OutlineCount(); }