mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 02:32:51 +02:00
* Add crossproduct and normalize to TPointF
(cherry picked from commit 7bcc949308
)
This commit is contained in:
parent
737aad778f
commit
28d9c6ce56
@ -160,6 +160,8 @@ type
|
||||
class function Zero: TPointF; inline; static;
|
||||
function Angle(const b: TPointF): Single;
|
||||
function AngleCosine(const b: TPointF): single;
|
||||
function CrossProduct(const apt: TPointF): Single;
|
||||
function Normalize: TPointF;
|
||||
|
||||
class function Create(const ax, ay: Single): TPointF; overload; static; inline;
|
||||
class function Create(const apt: TPoint): TPointF; overload; static; inline;
|
||||
@ -1223,6 +1225,29 @@ begin
|
||||
Result.y := apt.Y;
|
||||
end;
|
||||
|
||||
|
||||
function TPointF.CrossProduct(const apt: TPointF): Single;
|
||||
begin
|
||||
Result:=X*apt.Y-Y*apt.X;
|
||||
end;
|
||||
|
||||
function TPointF.Normalize: TPointF;
|
||||
|
||||
var
|
||||
L: Single;
|
||||
|
||||
begin
|
||||
L:=Sqrt(Sqr(X)+Sqr(Y));
|
||||
if SameValue(L,0,Epsilon) then
|
||||
Result:=Self
|
||||
else
|
||||
begin
|
||||
Result.X:=X/L;
|
||||
Result.Y:=Y/L;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ TSizeF }
|
||||
|
||||
function TSizeF.Add(const asz: TSize): TSizeF;
|
||||
|
Loading…
Reference in New Issue
Block a user