diff --git a/libs/kimath/include/geometry/shape_line_chain.h b/libs/kimath/include/geometry/shape_line_chain.h index 2103cd8d41..64e6f1eb9a 100644 --- a/libs/kimath/include/geometry/shape_line_chain.h +++ b/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() diff --git a/libs/kimath/src/geometry/shape_line_chain.cpp b/libs/kimath/src/geometry/shape_line_chain.cpp index 7ef74846a7..1b96e444a3 100644 --- a/libs/kimath/src/geometry/shape_line_chain.cpp +++ b/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;