Performance enhancement.
This commit is contained in:
parent
2ba9e07f0f
commit
33c97da0fa
|
@ -378,7 +378,7 @@ private:
|
||||||
bool intersects( const SEG& aSeg, bool aIgnoreEndpoints = false, bool aLines = false,
|
bool intersects( const SEG& aSeg, bool aIgnoreEndpoints = false, bool aLines = false,
|
||||||
VECTOR2I* aPt = nullptr ) const;
|
VECTOR2I* aPt = nullptr ) const;
|
||||||
|
|
||||||
bool mutualDistance( const SEG& aSeg, ecoord& aD1, ecoord& aD2 ) const;
|
bool mutualDistanceSquared( const SEG& aSeg, ecoord& aD1, ecoord& aD2 ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///< index within the parent shape (used when m_is_local == false)
|
///< index within the parent shape (used when m_is_local == false)
|
||||||
|
|
|
@ -358,15 +358,13 @@ int SEG::LineDistance( const VECTOR2I& aP, bool aDetermineSide ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SEG::mutualDistance( const SEG& aSeg, ecoord& aD1, ecoord& aD2 ) const
|
bool SEG::mutualDistanceSquared( const SEG& aSeg, ecoord& aD1, ecoord& aD2 ) const
|
||||||
{
|
{
|
||||||
SEG a( *this );
|
SEG a( *this );
|
||||||
SEG b( aSeg );
|
SEG b( aSeg );
|
||||||
|
|
||||||
if( a.SquaredLength() < b.SquaredLength() )
|
if( a.SquaredLength() < b.SquaredLength() )
|
||||||
{
|
|
||||||
std::swap(a, b);
|
std::swap(a, b);
|
||||||
}
|
|
||||||
|
|
||||||
ecoord p = ecoord{ a.A.y } - a.B.y;
|
ecoord p = ecoord{ a.A.y } - a.B.y;
|
||||||
ecoord q = ecoord{ a.B.x } - a.A.x;
|
ecoord q = ecoord{ a.B.x } - a.A.x;
|
||||||
|
@ -383,31 +381,33 @@ bool SEG::mutualDistance( const SEG& aSeg, ecoord& aD1, ecoord& aD2 ) const
|
||||||
ecoord dsq1 = rescale( det1, det1, l );
|
ecoord dsq1 = rescale( det1, det1, l );
|
||||||
ecoord dsq2 = rescale( det2, det2, l );
|
ecoord dsq2 = rescale( det2, det2, l );
|
||||||
|
|
||||||
aD1 = sgn( det1 ) * isqrt( dsq1 );
|
aD1 = sgn( det1 ) * dsq1;
|
||||||
aD2 = sgn( det2 ) * isqrt( dsq2 );
|
aD2 = sgn( det2 ) * dsq2;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SEG::ApproxCollinear( const SEG& aSeg, int aDistanceThreshold ) const
|
bool SEG::ApproxCollinear( const SEG& aSeg, int aDistanceThreshold ) const
|
||||||
{
|
{
|
||||||
ecoord d1, d2;
|
ecoord thresholdSquared = Square( aDistanceThreshold );
|
||||||
|
ecoord d1_sq, d2_sq;
|
||||||
|
|
||||||
if( ! mutualDistance( aSeg, d1, d2 ) )
|
if( !mutualDistanceSquared( aSeg, d1_sq, d2_sq ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return std::abs( d1 ) <= aDistanceThreshold && std::abs( d2 ) <= aDistanceThreshold;
|
return std::abs( d1_sq ) <= thresholdSquared && std::abs( d2_sq ) <= thresholdSquared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SEG::ApproxParallel( const SEG& aSeg, int aDistanceThreshold ) const
|
bool SEG::ApproxParallel( const SEG& aSeg, int aDistanceThreshold ) const
|
||||||
{
|
{
|
||||||
ecoord d1, d2;
|
ecoord thresholdSquared = Square( aDistanceThreshold );
|
||||||
|
ecoord d1_sq, d2_sq;
|
||||||
|
|
||||||
if( ! mutualDistance( aSeg, d1, d2 ) )
|
if( ! mutualDistanceSquared( aSeg, d1_sq, d2_sq ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return std::abs( d1 - d2 ) <= (ecoord) aDistanceThreshold;
|
return std::abs( d1_sq - d2_sq ) <= thresholdSquared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue