Afficher : Delphi C++
Préférences d'affichage

System.Types.TPointF

De XE2 API Documentation

Delphi

  TPointF = record
    X: Single;
    Y: Single;
  public
    constructor Create(const P: TPointF); overload;
    constructor Create(const X, Y: Single); overload;
    constructor Create(P: TPoint); overload;
    class operator Equal(const Lhs, Rhs: TPointF): Boolean;
    class operator NotEqual(const Lhs, Rhs: TPointF): Boolean;
    class operator Add(const Lhs, Rhs: TPointF): TPointF;
    class operator Subtract(const Lhs, Rhs: TPointF): TPointF;
    function Distance(const P2: TPointF): Double;
    procedure SetLocation(const X, Y: Single); overload;
    procedure SetLocation(const P: TPointF); overload;
    procedure SetLocation(const P: TPoint); overload;
    procedure Offset(const DX, DY: Single); overload;
    procedure Offset(const Point: TPointF); overload;
    procedure Offset(const Point: TPoint); overload;
    function Add(const Point: TPointF): TPointF; overload;
    function Add(const Point: TPoint): TPointF; overload;
    function Subtract(const Point: TPointF): TPointF; overload;
    function Subtract(const Point: TPoint): TPointF; overload;
    function IsZero: Boolean;
    function Ceiling: TPoint;
    function Truncate: TPoint;
    function Round: TPoint;
  end;

C++

struct TPointF: public POINTF{
TPointF() { x = y = 0; }
TPointF(float _x, float _y) { x=_x; y=_y; }
TPointF(const POINT& pt)
{
x = pt.x;
y = pt.y;
}
TPointF(const TPointF& pt)
{
x = pt.x;
y = pt.y;
}
bool operator ==(const TPointF& pt) const
{
return _sameValue(x, pt.x) && _sameValue(y, pt.y);
}
bool operator !=(const TPointF& pt) const
{
return !(pt == *this);
}
TPointF operator +(const TPointF& rhs) const
{
return TPointF(rhs.x + this->x, rhs.y + this->y);
}
TPointF operator -(const TPointF& rhs) const
{
return TPointF(this->x - rhs.x, this->y - rhs.y);
}
TPointF& operator +=(const TPointF& rhs)
{
this->x += rhs.x;
this->y += rhs.y;
return *this;
}
TPointF& operator -=(const TPointF& rhs)
{
this->x -= rhs.x;
this->y -= rhs.y;
return *this;
}
bool IsZero() const
{
return _sameValue(x, 0.0F) && _sameValue(y, 0.0F);
}
bool IsEmpty() const
{
return IsZero();
}
void Offset(float DX, float DY)
{
x += DX;
y += DY;
}
void SetLocation(float nX, float nY)
{
x = nX;
y = nY;
}
void SetLocation(const TPointF& p)
{
x = p.x;
y = p.y;
}
double Distance(const TPointF& p2) const
{
return hypot(p2.x - this->x, p2.y - this->y);
}
TPoint Ceiling() const {
return TPoint((int32_t)ceil(this->x), (int32_t)ceil(this->y));
}
TPoint Truncate() const {
return TPoint((int32_t)floor(this->x), (int32_t)floor(this->y));
}
TPoint Round() const {
return TPoint((int32_t)floor(this->x + 0.5), (int32_t)floor(this->y + 0.5));
}
bool PtInCircle(const TPointF& CircleCenter, float Radius) const
{
return (Radius > 0.0F) && ((_sqrf(CircleCenter.x-x)+_sqrf(CircleCenter.y-y)) < _sqrf(Radius));
}
static float __fastcall _sqrf(float i)
{
return i*i;
}
static bool __fastcall _sameValue(float a, float b)
{
const float SINGLE_RESOLUTION = 1.25E-6f;
const float SINGLE_ZERO =6.25E-37f;
float _epsilon = (float) ((fabs(a) > fabs(b)) ? fabs(a): fabs(b)) * SINGLE_RESOLUTION;
if (_epsilon == 0)
_epsilon = SINGLE_ZERO; // both a and b are very little, _epsilon was 0 because of normalization
return (a > b) ? ((a - b) <= _epsilon): ((b - a) <= _epsilon);
}
__property float X = { read=x,   write=x  };
__property float Y = { read=y,   write=y  };
};

Sommaire

Propriétés

Type Visibilité  Source Unité  Parent
struct
class
public
System.Types.pas
System.Types.hpp
System.Types System.Types

Description

Définit un emplacement sur l'écran exprimé en pixels.

Le type TPointF définit un emplacement sur l'écran exprimé en pixels, avec l'origine dans le coin supérieur gauche. X et Y spécifient respectivement la coordonnée horizontale et la coordonnée verticale du point.

Le type de X et Y est Single.

Voir aussi

Exemples de code

Versions précédentes
Traductions