* Some fixes from Ondrej Pokorny (bug ID 29538)

git-svn-id: trunk@33062 -
This commit is contained in:
michael 2016-02-06 15:03:28 +00:00
parent c5a44f7487
commit 39c404d342
2 changed files with 23 additions and 7 deletions

View File

@ -89,11 +89,12 @@ end;
function TPoint.Add(const apt: TPoint): TPoint;
begin
result.x:=x+apt.x;
result.y:=y+apt.y;
end;
function TPoint.Distance(const apt : TPoint) : Double;
function TPoint.Distance(const apt: TPoint): ValReal;
begin
result:=sqrt(sqr(apt.x-x)+sqr(apt.y-y));
result:=sqrt(sqr(ValReal(apt.x)-ValReal(x))+sqr(ValReal(apt.y)-ValReal(y))); // convert to ValReal to prevent integer overflows
end;
function TPoint.IsZero : Boolean;
@ -104,6 +105,13 @@ end;
function TPoint.Subtract(const apt : TPoint): TPoint;
begin
result.x:=x-apt.x;
result.y:=y-apt.y;
end;
class function TPoint.Zero: TPoint;
begin
Result.x := 0;
Result.y := 0;
end;
procedure TPoint.SetLocation(const apt :TPoint);
@ -117,14 +125,20 @@ end;
procedure TPoint.Offset(const apt :TPoint);
begin
x:=x-apt.x;
y:=y-apt.y;
x:=x+apt.x;
y:=y+apt.y;
end;
class function TPoint.PointInCircle(const apt, acenter: TPoint;
const aradius: Integer): Boolean;
begin
Result := apt.Distance(acenter) <= aradius;
end;
procedure TPoint.Offset(dx,dy : Longint);
begin
x:=x-dx;
y:=y-dy;
x:=x+dx;
y:=y+dy;
end;
class operator TPoint.= (const apt1, apt2 : TPoint) : Boolean;

View File

@ -70,14 +70,16 @@
constructor Create(ax,ay:Longint); overload;
constructor Create(apt :TPoint); overload;
{$endif}
class function Zero: TPoint; static; inline;
function Add(const apt: TPoint): TPoint;
function Distance(const apt : TPoint) : Double;
function Distance(const apt: TPoint) : ValReal;
function IsZero : Boolean;
function Subtract(const apt : TPoint): TPoint;
procedure SetLocation(const apt :TPoint);
procedure SetLocation(ax,ay : Longint);
procedure Offset(const apt :TPoint);
procedure Offset(dx,dy : Longint);
class function PointInCircle(const apt, acenter: TPoint; const aradius: Integer): Boolean; static; inline;
class operator = (const apt1, apt2 : TPoint) : Boolean;
class operator <> (const apt1, apt2 : TPoint): Boolean;
class operator + (const apt1, apt2 : TPoint): TPoint;