Add closed-shape handling to SHAPE_LINE_CHAIN collision routines.

This commit is contained in:
Jeff Young 2020-10-04 10:40:33 +01:00
parent 10bc96840a
commit f4f578b755
2 changed files with 30 additions and 3 deletions

View File

@ -266,6 +266,12 @@ static inline bool Collide( const SHAPE_LINE_CHAIN_BASE& aA, const SHAPE_LINE_CH
}
}
if( aB.IsClosed() && aA.GetPointCount() > 0 && aB.PointInside( aA.GetPoint( 0 ) ) )
{
closest_dist = 0;
nearest = aA.GetPoint( 0 );
}
if( closest_dist < aClearance )
{
if( aLocation )

View File

@ -88,12 +88,21 @@ void SHAPE_LINE_CHAIN::convertArc( ssize_t aArcIndex )
bool SHAPE_LINE_CHAIN_BASE::Collide( const VECTOR2I& aP, int aClearance, int* aActual,
VECTOR2I* aLocation ) const
{
if( IsClosed() && PointInside( aP, aClearance ) )
{
if( aLocation )
*aLocation = aP;
if( aActual )
*aActual = 0;
return true;
}
SEG::ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
SEG::ecoord clearance_sq = SEG::Square( aClearance );
VECTOR2I nearest;
// fixme: why this only checks open curves?
for( int i = 0; i < GetSegmentCount(); i++ )
{
const SEG& s = GetSegment( i );
@ -142,6 +151,17 @@ void SHAPE_LINE_CHAIN::Rotate( double aAngle, const VECTOR2I& aCenter )
bool SHAPE_LINE_CHAIN_BASE::Collide( const SEG& aSeg, int aClearance, int* aActual,
VECTOR2I* aLocation ) const
{
if( IsClosed() && PointInside( aSeg.A ) )
{
if( aLocation )
*aLocation = aSeg.A;
if( aActual )
*aActual = 0;
return true;
}
SEG::ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
SEG::ecoord clearance_sq = SEG::Square( aClearance );
VECTOR2I nearest;
@ -628,7 +648,8 @@ int SHAPE_LINE_CHAIN::PathLength( const VECTOR2I& aP ) const
}
bool SHAPE_LINE_CHAIN_BASE::PointInside( const VECTOR2I& aPt, int aAccuracy, bool aUseBBoxCache ) const
bool SHAPE_LINE_CHAIN_BASE::PointInside( const VECTOR2I& aPt, int aAccuracy,
bool aUseBBoxCache ) const
{
/*
* Don't check the bounding box unless it's cached. Building it is about the same speed as