geometry: SHAPE_LINE_CHAIN::PathLength() now can accept the maximum index of the segment to calculate the length to

This commit is contained in:
Tomasz Wlostowski 2021-05-27 23:40:25 +02:00
parent 7553b7b092
commit 2d8264124d
2 changed files with 17 additions and 3 deletions

View File

@ -610,7 +610,7 @@ public:
* belonging to our line.
* @return: path length in Euclidean metric or -1 if aP does not belong to the line chain.
*/
int PathLength( const VECTOR2I& aP ) const;
int PathLength( const VECTOR2I& aP, int aIndex = -1 ) const;
/**
* Function CheckClearance()

View File

@ -842,7 +842,7 @@ int SHAPE_LINE_CHAIN::Intersect( const SHAPE_LINE_CHAIN& aChain, INTERSECTIONS&
}
int SHAPE_LINE_CHAIN::PathLength( const VECTOR2I& aP ) const
int SHAPE_LINE_CHAIN::PathLength( const VECTOR2I& aP, int aIndex ) const
{
int sum = 0;
@ -851,7 +851,21 @@ int SHAPE_LINE_CHAIN::PathLength( const VECTOR2I& aP ) const
const SEG seg = CSegment( i );
int d = seg.Distance( aP );
if( d <= 1 )
bool indexMatch = true;
if( aIndex >= 0 )
{
if( aIndex == SegmentCount() )
{
indexMatch = ( i == SegmentCount() - 1 );
}
else
{
indexMatch = ( i == aIndex );
}
}
if( indexMatch )
{
sum += ( aP - seg.A ).EuclideanNorm();
return sum;