Add closed-shape handling to SHAPE_LINE_CHAIN collision routines.
This commit is contained in:
parent
10bc96840a
commit
f4f578b755
|
@ -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( closest_dist < aClearance )
|
||||||
{
|
{
|
||||||
if( aLocation )
|
if( aLocation )
|
||||||
|
|
|
@ -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,
|
bool SHAPE_LINE_CHAIN_BASE::Collide( const VECTOR2I& aP, int aClearance, int* aActual,
|
||||||
VECTOR2I* aLocation ) const
|
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 closest_dist_sq = VECTOR2I::ECOORD_MAX;
|
||||||
SEG::ecoord clearance_sq = SEG::Square( aClearance );
|
SEG::ecoord clearance_sq = SEG::Square( aClearance );
|
||||||
VECTOR2I nearest;
|
VECTOR2I nearest;
|
||||||
|
|
||||||
// fixme: why this only checks open curves?
|
|
||||||
|
|
||||||
for( int i = 0; i < GetSegmentCount(); i++ )
|
for( int i = 0; i < GetSegmentCount(); i++ )
|
||||||
{
|
{
|
||||||
const SEG& s = GetSegment( 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,
|
bool SHAPE_LINE_CHAIN_BASE::Collide( const SEG& aSeg, int aClearance, int* aActual,
|
||||||
VECTOR2I* aLocation ) const
|
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 closest_dist_sq = VECTOR2I::ECOORD_MAX;
|
||||||
SEG::ecoord clearance_sq = SEG::Square( aClearance );
|
SEG::ecoord clearance_sq = SEG::Square( aClearance );
|
||||||
VECTOR2I nearest;
|
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
|
* Don't check the bounding box unless it's cached. Building it is about the same speed as
|
||||||
|
|
Loading…
Reference in New Issue