From 2af6d01fdfce2e3df68887f98fc58fc7b30e5726 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 25 Jul 2020 17:31:17 +0100 Subject: [PATCH] Add some defensive code for empty polygons. Fixes https://gitlab.com/kicad/code/kicad/issues/4947 --- pcbnew/class_pad.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 63b398ae43..c7bf625f8e 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -801,6 +801,11 @@ bool D_PAD::HitTest( const wxPoint& aPosition, int aAccuracy ) const bool D_PAD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const { + auto getArea = []( const SHAPE_POLY_SET& aPoly ) -> double + { + return aPoly.OutlineCount() ? aPoly.COutline( 0 ).Area() : 0; + }; + EDA_RECT arect = aRect; arect.Normalize(); arect.Inflate( aAccuracy ); @@ -823,8 +828,8 @@ bool D_PAD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) con selRect.BooleanIntersection( *GetEffectivePolygon(), SHAPE_POLY_SET::PM_FAST ); - double padArea = GetEffectivePolygon()->Outline( 0 ).Area(); - double intersection = selRect.Outline( 0 ).Area(); + double padArea = getArea( *GetEffectivePolygon() ); + double intersection = getArea( selRect ); if( intersection > ( padArea * 0.99 ) ) return true;