From f80b48e1b0875fe4fef82d7cce7aa14628acf75f Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Wed, 5 Oct 2022 14:37:50 +0200 Subject: [PATCH] libs/kimath: consider signed distances in parallelity check --- libs/kimath/src/geometry/seg.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/kimath/src/geometry/seg.cpp b/libs/kimath/src/geometry/seg.cpp index 645f4061f7..6b0c78b635 100644 --- a/libs/kimath/src/geometry/seg.cpp +++ b/libs/kimath/src/geometry/seg.cpp @@ -367,8 +367,11 @@ bool SEG::mutualDistance( const SEG& aSeg, ecoord& aD1, ecoord& aD2 ) const ecoord det1 = p * b.A.x + q * b.A.y + r; ecoord det2 = p * b.B.x + q * b.B.y + r; - aD1 = isqrt( rescale( det1, det1, l ) ); - aD2 = isqrt( rescale( det2, det2, l ) ); + ecoord dsq1 = rescale( det1, det1, l ); + ecoord dsq2 = rescale( det2, det2, l ); + + aD1 = sgn( det1 ) * isqrt( dsq1 ); + aD2 = sgn( det2 ) * isqrt( dsq2 ); return true; }