mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-08 19:16:45 +02:00
LazUtils/GraphMath: Optimization of Distance function (issue #41104). Add a FloatPoint-FloatPoint overload.
(cherry picked from commit 7740a84766
)
This commit is contained in:
parent
532d607bd6
commit
2e43c26f90
@ -67,6 +67,7 @@ procedure Coords2Angles(X, Y, Width, Height : Integer; SX, SY,
|
||||
EX, EY : Integer; var Angle1, Angle2 : Extended);
|
||||
|
||||
function Distance(const PT1,Pt2 : TPoint) : Extended; overload; inline;
|
||||
function Distance(const PT1,Pt2 : TFloatPoint) : Extended; overload; inline;
|
||||
function Distance(const Pt, SP, EP : TFloatPoint) : Extended; overload;
|
||||
|
||||
function EccentricAngle(const PT : TPoint; const Rect : TRect) : Extended;
|
||||
@ -657,7 +658,7 @@ end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: Distance
|
||||
Params: PT1, PT2
|
||||
Params: PT1, PT2: TPoint
|
||||
Returns: Extended
|
||||
|
||||
Use Distance to get the distance between any two Points. It is primarily
|
||||
@ -669,6 +670,20 @@ begin
|
||||
Result := Sqrt(Sqr(Pt2.X - Pt1.X) + Sqr(Pt2.Y - Pt1.Y));
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: Distance
|
||||
Params: PT1, PT2: TFloatPoint
|
||||
Returns: Extended
|
||||
|
||||
Use Distance to get the distance between any two Points. It is primarily
|
||||
for use in other routines such as EccentricAngle.
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
function Distance(const PT1, Pt2: TFloatPoint): Extended;
|
||||
begin
|
||||
Result := Sqrt(Sqr(Pt2.X - Pt1.X) + Sqr(Pt2.Y - Pt1.Y));
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: Distance
|
||||
Params: PT, SP,EP
|
||||
@ -689,9 +704,9 @@ var
|
||||
Result := (Pt2.Y - Pt1.Y) / (Pt2.X - Pt1.X);
|
||||
end;
|
||||
|
||||
function YIntercept(PT1,Pt2 : TFloatPoint) : Extended;
|
||||
function YIntercept(Pt1: TFloatPoint; ASlope: Extended) : Extended;
|
||||
begin
|
||||
Result := Pt1.Y - Slope(Pt1,Pt2)*Pt1.X;
|
||||
Result := Pt1.Y - ASlope*Pt1.X;
|
||||
end;
|
||||
|
||||
begin
|
||||
@ -706,7 +721,7 @@ begin
|
||||
|
||||
A := -Slope(SP,EP);
|
||||
B := 1;
|
||||
C := -YIntercept(SP, EP);
|
||||
C := -YIntercept(SP, -A);
|
||||
Result := ABS(A*Pt.X + B*Pt.Y + C)/Sqrt(Sqr(A) + Sqr(B));
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user