Adding seg-polyset collision support
This commit is contained in:
parent
b618da1fac
commit
dbfa9093ab
|
@ -1229,6 +1229,37 @@ bool SHAPE_POLY_SET::PointOnEdge( const VECTOR2I& aP ) const
|
|||
}
|
||||
|
||||
|
||||
bool SHAPE_POLY_SET::Collide( const SEG& aSeg, int aClearance ) const
|
||||
{
|
||||
|
||||
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 iterator = polySet.IterateSegmentsWithHoles(); iterator; iterator++ )
|
||||
{
|
||||
SEG polygonEdge = *iterator;
|
||||
|
||||
if( polygonEdge.Intersect( aSeg, true ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SHAPE_POLY_SET::Collide( const VECTOR2I& aP, int aClearance ) const
|
||||
{
|
||||
SHAPE_POLY_SET polySet = SHAPE_POLY_SET( *this );
|
||||
|
|
|
@ -904,8 +904,19 @@ class SHAPE_POLY_SET : public SHAPE
|
|||
*/
|
||||
bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override;
|
||||
|
||||
// fixme: add collision support
|
||||
bool Collide( const SEG& aSeg, int aClearance = 0 ) const override { return false; }
|
||||
/**
|
||||
* Function Collide
|
||||
* Checks whether the segment aSeg collides with the inside of the polygon set; if the
|
||||
* segment touches an edge or a corner of any of the polygons, there is no collision:
|
||||
* the edges do not belong to the polygon itself.
|
||||
* @param aSeg is the SEG segment whose collision with respect to the poly set
|
||||
* will be tested.
|
||||
* @param aClearance is the security distance; if the segment passes closer to the polygon
|
||||
* than aClearance distance, then there is a collision.
|
||||
* @return bool - true if the segment aSeg collides with the polygon;
|
||||
* false in any other case.
|
||||
*/
|
||||
bool Collide( const SEG& aSeg, int aClearance = 0 ) const override;
|
||||
|
||||
/**
|
||||
* Function CollideVertex
|
||||
|
|
Loading…
Reference in New Issue