System.Types.TSizeF

提供: RAD Studio API Documentation
移動先: 案内検索

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

プロパティ

種類 可視性 ソース ユニット
record
struct
public
System.Types.pas
SystemTypes.h
System.Types System.Types

説明

オブジェクトのwidthおよびheightを、浮動小数点で表します。

TSizeF は、Width および Height プロパティを使用して、オブジェクトの浮動小数点サイズを表します:

  • Width は、cx フィールドに保有されます。
  • Height は、cy フィールドに保有されます。

オブジェクトは、四角形、フォーム、ボタン、などです。 大抵の場合、暗黙の測定単位はピクセルです。

プロパティ WidthHeight の型は Single です。

関連項目