From 6ca87f810b49f171947cadb67f935767d5afd845 Mon Sep 17 00:00:00 2001 From: wp_xyz Date: Tue, 27 Aug 2024 22:35:36 +0200 Subject: [PATCH] LazUtils/Graphmath: Fix incorrect Distance() function for vertical lines. Issue #41098 --- components/lazutils/graphmath.pp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/components/lazutils/graphmath.pp b/components/lazutils/graphmath.pp index 87b7da1ef1..6332ef4a72 100644 --- a/components/lazutils/graphmath.pp +++ b/components/lazutils/graphmath.pp @@ -689,10 +689,8 @@ var function Slope(PT1,Pt2 : TFloatPoint) : Extended; begin - If Pt2.X <> Pt1.X then - Result := (Pt2.Y - Pt1.Y) / (Pt2.X - Pt1.X) - else - Result := 1; + // The case Pt1.X = Pt2.X has already been handled. + Result := (Pt2.Y - Pt1.Y) / (Pt2.X - Pt1.X); end; function YIntercept(PT1,Pt2 : TFloatPoint) : Extended; @@ -701,6 +699,15 @@ var end; begin + if SP.X = EP.X then + begin + if SP.Y <> EP.Y then + Result := abs(Pt.X - SP.X) + else + Result := Distance(Pt, SP); + exit; + end; + A := -Slope(SP,EP); B := 1; C := -YIntercept(SP, EP);