Browse Source

* Some fixes from Ondrej Pokorny (bug ID 29538)

git-svn-id: trunk@33062 -
michael 9 years ago
parent
commit
39c404d342
2 changed files with 23 additions and 7 deletions
  1. 20 6
      rtl/inc/typshrd.inc
  2. 3 1
      rtl/inc/typshrdh.inc

+ 20 - 6
rtl/inc/typshrd.inc

@@ -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;

+ 3 - 1
rtl/inc/typshrdh.inc

@@ -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;