Add some defensive code for empty polygons.

Fixes https://gitlab.com/kicad/code/kicad/issues/4947
This commit is contained in:
Jeff Young 2020-07-25 17:31:17 +01:00
parent 6f7d5f5e2b
commit 2af6d01fdf
1 changed files with 7 additions and 2 deletions

View File

@ -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;