Browse Source

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

6.0.7
Tomasz Wlostowski 5 years ago
parent
commit
2d8264124d
  1. 2
      libs/kimath/include/geometry/shape_line_chain.h
  2. 18
      libs/kimath/src/geometry/shape_line_chain.cpp

2
libs/kimath/include/geometry/shape_line_chain.h

@ -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()

18
libs/kimath/src/geometry/shape_line_chain.cpp

@ -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;

Loading…
Cancel
Save