Fix return type within pointInside2

This commit is contained in:
Marek Roszko 2021-02-20 11:55:55 -05:00
parent 907e282347
commit 6fce39607e
1 changed files with 16 additions and 9 deletions

View File

@ -268,14 +268,21 @@ bool RESTRICT_VERTEX_RANGE_CONSTRAINT::Check( int aVertex1, int aVertex2, const
return true; return true;
} }
/**
// fixme: integrate into SHAPE_LINE_CHAIN, check corner cases against current PointInside implementation * Determine if a point is located within a given polygon
*
* @todo fixme: integrate into SHAPE_LINE_CHAIN, check corner cases against current PointInside implementation
*
* @param aL Polygon
* @param aP Point to check for location within the polygon
*
* @return false if point is not polygon boundary aL, true if within or on the polygon boundary
*/
static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP ) static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
{ {
if( !aL.IsClosed() || aL.SegmentCount() < 3 ) if( !aL.IsClosed() || aL.SegmentCount() < 3 )
return false; return false;
// returns 0 if false, +1 if true, -1 if pt ON polygon boundary
int result = 0; int result = 0;
size_t cnt = aL.PointCount(); size_t cnt = aL.PointCount();
@ -288,7 +295,7 @@ static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
if( ipNext.y == aP.y ) if( ipNext.y == aP.y )
{ {
if( (ipNext.x ==aP.x) || ( ip.y == aP.y && ( (ipNext.x >aP.x) == (ip.x <aP.x) ) ) ) if( (ipNext.x ==aP.x) || ( ip.y == aP.y && ( (ipNext.x >aP.x) == (ip.x <aP.x) ) ) )
return -1; return true; // pt on polyground boundary
} }
if( (ip.y <aP.y) != (ipNext.y <aP.y) ) if( (ip.y <aP.y) != (ipNext.y <aP.y) )
@ -305,7 +312,7 @@ static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
static_cast<double>( ip.y - aP.y ); static_cast<double>( ip.y - aP.y );
if( !d ) if( !d )
return -1; return true; // pt on polyground boundary
if( (d > 0) == (ipNext.y > ip.y) ) if( (d > 0) == (ipNext.y > ip.y) )
result = 1 - result; result = 1 - result;
@ -319,7 +326,7 @@ static bool pointInside2( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aP )
((double)ipNext.x -aP.x) * ((double)ip.y -aP.y); ((double)ipNext.x -aP.x) * ((double)ip.y -aP.y);
if( !d ) if( !d )
return -1; return true; // pt on polyground boundary
if( (d > 0) == (ipNext.y > ip.y) ) if( (d > 0) == (ipNext.y > ip.y) )
result = 1 - result; result = 1 - result;