geometry: SHAPE_LINE_CHAIN::PathLength() now can accept the maximum index of the segment to calculate the length to
This commit is contained in:
parent
7553b7b092
commit
2d8264124d
|
@ -610,7 +610,7 @@ public:
|
||||||
* belonging to our line.
|
* belonging to our line.
|
||||||
* @return: path length in Euclidean metric or -1 if aP does not belong to the line chain.
|
* @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()
|
* Function CheckClearance()
|
||||||
|
|
|
@ -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;
|
int sum = 0;
|
||||||
|
|
||||||
|
@ -851,7 +851,21 @@ int SHAPE_LINE_CHAIN::PathLength( const VECTOR2I& aP ) const
|
||||||
const SEG seg = CSegment( i );
|
const SEG seg = CSegment( i );
|
||||||
int d = seg.Distance( aP );
|
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();
|
sum += ( aP - seg.A ).EuclideanNorm();
|
||||||
return sum;
|
return sum;
|
||||||
|
|
Loading…
Reference in New Issue