System.Types.TSizeF

De RAD Studio API Documentation
Aller à : navigation, rechercher

Delphi

  TSizeF = record
    cx: Single;
    cy: Single;
  public
    constructor Create(P: TSizeF); overload;
    constructor Create(const X, Y: Single); overload;
    class operator Equal(const Lhs, Rhs: TSizeF): Boolean;
    class operator NotEqual(const Lhs, Rhs: TSizeF): Boolean;
    class operator Add(const Lhs, Rhs: TSizeF): TSizeF;
    class operator Subtract(const Lhs, Rhs: TSizeF): TSizeF;
    class operator Implicit(const Size: TSizeF): TPointF;
    class operator Implicit(const Point: TPointF): TSizeF;
    class operator Implicit(const Size: TSize): TSizeF;
    function Ceiling: TSize;
    function Truncate: TSize;
    function Round: TSize;
    function Add(const Point: TSizeF): TSizeF;
    function Subtract(const Point: TSizeF): TSizeF;
    function Distance(const P2: TSizeF): Double;
    function IsZero: Boolean;
    function SwapDimensions: TSizeF;
    property Width: Single read cx write cx;
    property Height: Single read cy write cy;
  end;

C++

struct TSizeF
{
  float cx;
  float cy;
public:
  TSizeF() _ALWAYS_INLINE {
    cx = cy = 0;
  }
  TSizeF(float w, float h) _ALWAYS_INLINE {
    cx = w;
    cy = h;
  }
  TSizeF(const TSize& s) _ALWAYS_INLINE {
    cx = s.cx;
    cy = s.cy;
  }
  bool operator ==(const TSizeF& sf) const {
    return _sameValue(cx, sf.cx) && _sameValue(cy, sf.cy);
  }
  bool operator !=(const TSizeF& sf) const {
    return !(sf == *this);
  }
  TSizeF operator +(const TSizeF& rhs) const {
    return TSizeF(rhs.cx + this->cx, rhs.cy + this->cy);
  }
  TSizeF operator -(const TSizeF& rhs) const {
    return TSizeF(this->cx - rhs.cx, this->cy - rhs.cy);
  }
  TSizeF& operator +=(const TSizeF& rhs) {
    this->cx += rhs.cx;
    this->cy += rhs.cy;
    return *this;
  }
  TSizeF& operator -=(const TSizeF& rhs) {
    this->cx -= rhs.cx;
    this->cy -= rhs.cy;
    return *this;
  }
  bool IsZero() const _ALWAYS_INLINE {
    return _sameValue(cx, 0.0F) && _sameValue(cy, 0.0F);
  }
  double Distance(const TSizeF& s2) const _ALWAYS_INLINE {
  #ifdef _WIN64 // RS-53817
    return System::hypotWA(s2.cx - this->cx, s2.cy - this->cy);
  #else
    return hypot(s2.cx - this->cx, s2.cy - this->cy);
  #endif
  }
  TSize Ceiling() const _ALWAYS_INLINE {
    return TSize((int32_t)ceil(this->cx), (int32_t)ceil(this->cy));
  }
  TSize Truncate() const _ALWAYS_INLINE {
    return TSize((int32_t)floor(this->cx), (int32_t)floor(this->cy));
  }
  TSize Round() const _ALWAYS_INLINE {
    return TSize((int32_t)floor(this->cx + 0.5), (int32_t)floor(this->cy + 0.5));
  }
  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 Width =  { read=cx,   write=cx  };
  __property float Height = { read=cy,   write=cy  };
};

Propriétés

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

Description

Représente la largeur et la hauteur à virgule flottante d'un objet.

TSizeF représente la taille à virgule flottante d'un objet en utilisant les propriétés Width et Height :

  • Width est stockée dans le champ cx.
  • Height est stockée dans le champ cy.

L'objet peut être un rectangle, une fiche, un bouton, et ainsi de suite. Typiquement, les unités de mesure impliquées sont les pixels.

Le type des propriétés Width et Height est Single.

Voir aussi