From f2db7ecbe495d77768a2d021dda5fb26bed75acd Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 16 Jul 2019 05:08:29 -0700 Subject: [PATCH] Partial revert of 1a7cef2950a89959e76dc7b5de259b3b022a7f2e The referenced commit broke the unit tests, creating invalid connectivity for polygon fills. --- common/geometry/shape_poly_set.cpp | 34 ++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/common/geometry/shape_poly_set.cpp b/common/geometry/shape_poly_set.cpp index 95c1590509..ba52e63e0b 100644 --- a/common/geometry/shape_poly_set.cpp +++ b/common/geometry/shape_poly_set.cpp @@ -1195,18 +1195,28 @@ bool SHAPE_POLY_SET::PointOnEdge( const VECTOR2I& aP ) const bool SHAPE_POLY_SET::Collide( const SEG& aSeg, int aClearance ) const { - // We are going to check to see if the segment crosses an external boundary. However, if - // the full segment is inside the polyset, this will not be true. So we first test to see - // if one of the points is inside. If true, then we collide. Use an accuracy of "1" to - // indicate that a collision with the edge should be treated the same as inside. - if( Collide( aSeg.A, 1 ) ) + + SHAPE_POLY_SET polySet = SHAPE_POLY_SET( *this ); + + // Inflate the polygon if necessary. + if( aClearance > 0 ) + { + // fixme: the number of arc segments should not be hardcoded + polySet.Inflate( aClearance, 8 ); + } + + // We are going to check to see if the segment crosses an external + // boundary. However, if the full segment is inside the polyset, this + // will not be true. So we first test to see if one of the points is + // inside. If true, then we collide + if( polySet.Contains( aSeg.A ) ) return true; for( SEGMENT_ITERATOR it = ( (SHAPE_POLY_SET*) this )->IterateSegmentsWithHoles(); it; it++ ) { SEG polygonEdge = *it; - if( polygonEdge.Collide( aSeg, aClearance ) ) + if( polygonEdge.Intersect( aSeg, true ) ) return true; } @@ -1216,7 +1226,17 @@ bool SHAPE_POLY_SET::Collide( const SEG& aSeg, int aClearance ) const bool SHAPE_POLY_SET::Collide( const VECTOR2I& aP, int aClearance ) const { - return Contains( aP, -1, aClearance ); + SHAPE_POLY_SET polySet = SHAPE_POLY_SET( *this ); + + // Inflate the polygon if necessary. + if( aClearance > 0 ) + { + // fixme: the number of arc segments should not be hardcoded + polySet.Inflate( aClearance, 8 ); + } + + // There is a collision if and only if the point is inside of the polygon. + return polySet.Contains( aP ); }