diff --git a/rtl/inc/typshrd.inc b/rtl/inc/typshrd.inc index 657a100c14..ecf9b6130a 100644 --- a/rtl/inc/typshrd.inc +++ b/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; diff --git a/rtl/inc/typshrdh.inc b/rtl/inc/typshrdh.inc index b6a32e27af..07edfc7a6c 100644 --- a/rtl/inc/typshrdh.inc +++ b/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;