System.Types.TPoint

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

  TPoint = record
    X: FixedInt;
    Y: FixedInt;
  public
    constructor Create(P : TPoint); overload;
    constructor Create(const X, Y : Integer); overload;
    class operator Equal(const Lhs, Rhs : TPoint) : Boolean;
    class operator NotEqual(const Lhs, Rhs : TPoint): Boolean;
    class operator Add(const Lhs, Rhs : TPoint): TPoint;
    class operator Subtract(const Lhs, Rhs : TPoint): TPoint;
    class operator Implicit(Value: TSmallPoint): TPoint;
    class operator Explicit(Value: TPoint): TSmallPoint;
    class function PointInCircle(const Point, Center: TPoint; const Radius: Integer): Boolean; static; inline;
    class function Zero: TPoint; inline; static;
    function Distance(const P2 : TPoint) : Double;
    procedure SetLocation(const X, Y : Integer); overload;
    procedure SetLocation(const P : TPoint); overload;
    procedure Offset(const DX, DY : Integer); overload;
    procedure Offset(const Point: TPoint); overload;
    function Add(const Point: TPoint): TPoint;
    function Subtract(const Point: TPoint): TPoint;
    function IsZero : Boolean;
    function Angle(const APoint: TPoint): Single;
  end;

C++

struct TPoint: public POINT  {
  TPoint() _ALWAYS_INLINE
  { x = y = 0; }
  TPoint(int _x, int _y) _ALWAYS_INLINE
  { x=_x; y=_y; }
  bool operator ==(const TPoint& pt) const _ALWAYS_INLINE {
    return (x == pt.x) && (y == pt.y);
  }
  bool operator !=(const TPoint& pt) const _ALWAYS_INLINE {
    return !(pt == *this);
  }
  TPoint operator +(const TPoint& rhs) const _ALWAYS_INLINE {
    return TPoint(rhs.x + this->x, rhs.y + this->y);
  }
  TPoint operator -(const TPoint& rhs) const _ALWAYS_INLINE {
    return TPoint(this->x - rhs.x, this->y - rhs.y );
  }
  TPoint& operator +=(const TPoint& rhs) _ALWAYS_INLINE {
    this->x += rhs.x;
    this->y += rhs.y;
    return *this;
  }
  TPoint& operator -=(const TPoint& rhs) _ALWAYS_INLINE {
    this->x -= rhs.x;
    this->y -= rhs.y;
    return *this;
  }
  bool IsZero() const _ALWAYS_INLINE {
    return !x && !y;
  }
  bool IsEmpty() const _ALWAYS_INLINE {
    return IsZero();
  }
  void Offset(int DX, int DY) _ALWAYS_INLINE {
    x += DX;
    y += DY;
  }
  void SetLocation(int nX, int nY) _ALWAYS_INLINE {
    x = nX;
    y = nY;
  }
  void SetLocation(const TPoint& p) _ALWAYS_INLINE {
    x = p.x;
    y = p.y;
  }
  double Distance(const TPoint& p2) const _ALWAYS_INLINE {
    return hypot(static_cast<double>(p2.x - this->x), static_cast<double>(p2.y - this->y));
  }
  static int __fastcall _sqr(int i) _ALWAYS_INLINE { // Helper - private?
     return i*i;
  }
  bool PtInCircle(const TPoint& CircleCenter, int Radius) const _ALWAYS_INLINE {
    return (Radius > 0) && ((_sqr(CircleCenter.x-x)+_sqr(CircleCenter.y-y)) < _sqr(Radius));
  }
  float Angle(const TPoint& P) const _ALWAYS_INLINE {
    return atan2((float)y - P.y,(float)x - P.x);
  }
  __property LONG X = { read=x,   write=x  };
  __property LONG Y = { read=y,   write=y  };
};

Properties

Type Visibility Source Unit Parent
record
struct
public
System.Types.pas
SystemTypes.h
System.Types System.Types

Description

Defines a pixel location on-screen.

The TPoint type defines the integer type X and Y coordinates of a pixel location on-screen, with the origin in the upper-left corner. X and Y specify the horizontal and vertical coordinates of a point, respectively.

The type of X and Y is FixedInt.

See Also


Code Examples