mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-09 06:38:15 +02:00
LazUtils/GraphMath: Optimization of Distance function (issue #41104). Add a FloatPoint-FloatPoint overload.
This commit is contained in:
parent
6cdd808d43
commit
7740a84766
@ -67,6 +67,7 @@ procedure Coords2Angles(X, Y, Width, Height : Integer; SX, SY,
|
|||||||
EX, EY : Integer; var Angle1, Angle2 : Extended);
|
EX, EY : Integer; var Angle1, Angle2 : Extended);
|
||||||
|
|
||||||
function Distance(const PT1,Pt2 : TPoint) : Extended; overload; inline;
|
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 Distance(const Pt, SP, EP : TFloatPoint) : Extended; overload;
|
||||||
|
|
||||||
function EccentricAngle(const PT : TPoint; const Rect : TRect) : Extended;
|
function EccentricAngle(const PT : TPoint; const Rect : TRect) : Extended;
|
||||||
@ -661,7 +662,7 @@ end;
|
|||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: Distance
|
Method: Distance
|
||||||
Params: PT1, PT2
|
Params: PT1, PT2: TPoint
|
||||||
Returns: Extended
|
Returns: Extended
|
||||||
|
|
||||||
Use Distance to get the distance between any two Points. It is primarily
|
Use Distance to get the distance between any two Points. It is primarily
|
||||||
@ -673,6 +674,20 @@ begin
|
|||||||
Result := Sqrt(Sqr(Pt2.X - Pt1.X) + Sqr(Pt2.Y - Pt1.Y));
|
Result := Sqrt(Sqr(Pt2.X - Pt1.X) + Sqr(Pt2.Y - Pt1.Y));
|
||||||
end;
|
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
|
Method: Distance
|
||||||
Params: PT, SP,EP
|
Params: PT, SP,EP
|
||||||
@ -693,9 +708,9 @@ var
|
|||||||
Result := (Pt2.Y - Pt1.Y) / (Pt2.X - Pt1.X);
|
Result := (Pt2.Y - Pt1.Y) / (Pt2.X - Pt1.X);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function YIntercept(PT1,Pt2 : TFloatPoint) : Extended;
|
function YIntercept(Pt1: TFloatPoint; ASlope: Extended) : Extended;
|
||||||
begin
|
begin
|
||||||
Result := Pt1.Y - Slope(Pt1,Pt2)*Pt1.X;
|
Result := Pt1.Y - ASlope*Pt1.X;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -710,7 +725,7 @@ begin
|
|||||||
|
|
||||||
A := -Slope(SP,EP);
|
A := -Slope(SP,EP);
|
||||||
B := 1;
|
B := 1;
|
||||||
C := -YIntercept(SP, EP);
|
C := -YIntercept(SP, -A);
|
||||||
Result := ABS(A*Pt.X + B*Pt.Y + C)/Sqrt(Sqr(A) + Sqr(B));
|
Result := ABS(A*Pt.X + B*Pt.Y + C)/Sqrt(Sqr(A) + Sqr(B));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user