TRect


This template represents 4-element object. It may be interpreted as rectangle in 2D space, border widths, etc. Arithmetical operators with scalars are per component. All arithmetical operators are available for arithmetic data types only. Comparison operators are available for non-float data types only.

You can find more information in comments below.

template<class TYPE>
union TRect
{
    struct // As borders
    {
        TYPE Left;
        TYPE Top;
        TYPE Right;
        TYPE Bottom;
    };
    struct // As vector
    {
        TYPE X;
        TYPE Y;
        TYPE Z;
        TYPE W;
    };
    struct // As components
    {
        TYPE A;
        TYPE B;
        TYPE C;
        TYPE D;
    };
    struct // As parts
    {
        TYPE First;
        TYPE Second;
        TYPE Third;
        TYPE Fourth;
    };
    struct // As color
    {
        TYPE Red;
        TYPE Green;
        TYPE Blue;
        TYPE Alpha;
    };
    struct // As elements
    {
        TYPE _1;
        TYPE _2;
        TYPE _3;
        TYPE _4;
    };
    struct // As corners
    {
        TPoint<TYPE> LeftTop;
        TPoint<TYPE> RightBottom;
    };
    struct // As points
    {
        TPoint<TYPE> _12;
        TPoint<TYPE> _34;
    };
    TYPE Data[4]; // Array of elements
    TMatrix<TYPE, 1, 4> M; // As matrix
    TVec4<TYPE> V4; // As TVec4
    TQuaternion<TYPE> Q; // As TQuaternion

    TYPE operator[](const size_t index) const; // Return element by index. Only 0, 1, 2 and 3 are accepted as indices. Used only when TRect object is a constant object
    TYPE &operator[](const size_t index); // Return element by index. Only 0, 1, 2 and 3 are accepted as indices
};

Additionally following operators exists.

template<class TYPE>
bool operator==(const TRect<TYPE> &a, const TRect<TYPE> &b); // Check whether rectangles are equal. Can be used for non-float data types only
template<class TYPE>
bool operator!=(const TRect<TYPE> &a, const TRect<TYPE> &b); // Check whether rectangles aren't equal. Can be used for non-float data types only
template<class TYPE>
TRect<TYPE> operator+(const TRect<TYPE> &r, const TYPE val); // Add rect and scalar
template<class TYPE>
TRect<TYPE> operator-(const TRect<TYPE> &r, const TYPE val); // Subtract rect and scalar
template<class TYPE>
TRect<TYPE> operator*(const TRect<TYPE> &r, const TYPE val); // Multiply rect and scalar
template<class TYPE>
TRect<TYPE> operator/(const TRect<TYPE> &r, const TYPE val); // Divide rect and scalar
template<class TYPE>
TRect<TYPE> operator+(const TYPE val, const TRect<TYPE> &r); // Add scalar and rect
template<class TYPE>
TRect<TYPE> operator-(const TYPE val, const TRect<TYPE> &r); // Subtract scalar and rect
template<class TYPE>
TRect<TYPE> operator*(const TYPE val, const TRect<TYPE> &r); // Multiply scalar and rect
template<class TYPE>
TRect<TYPE> operator/(const TYPE val, const TRect<TYPE> &r); // Divide scalar and rect
template<class TYPE>
TRect<TYPE> &operator+=(TRect<TYPE> &r, const TYPE val); // Add scalar to rect
template<class TYPE>
TRect<TYPE> &operator-=(TRect<TYPE> &r, const TYPE val); // Subtract scalar from rect
template<class TYPE>
TRect<TYPE> &operator*=(TRect<TYPE> &r, const TYPE val); // Multiply rect by scalar
template<class TYPE>
TRect<TYPE> &operator/=(TRect<TYPE> &r, const TYPE val); // Divide rect by scalar
template<class TYPE>
TRect<TYPE> operator+(const TRect<TYPE> &r, const TPoint<TYPE> &p); // Return rect shifted by point
template<class TYPE>
TRect<TYPE> operator-(const TRect<TYPE> &r, const TPoint<TYPE> &p); // Return rect shifted by point opposite direction
template<class TYPE>
TRect<TYPE> operator*(const TRect<TYPE> &r, const TPoint<TYPE> &p); // Return rect scaled by point
template<class TYPE>
TRect<TYPE> operator/(const TRect<TYPE> &r, const TPoint<TYPE> &p); // Return rect scaled by inversed point
template<class TYPE>
TRect<TYPE> &operator+=(TRect<TYPE> &r, const TPoint<TYPE> &p); // Shift rect by point
template<class TYPE>
TRect<TYPE> &operator-=(TRect<TYPE> &r, const TPoint<TYPE> &p); // Shift rect by point opposite direction
template<class TYPE>
TRect<TYPE> &operator*=(TRect<TYPE> &r, const TPoint<TYPE> &p); // Scale rect by point
template<class TYPE>
TRect<TYPE> &operator/=(TRect<TYPE> &r, const TPoint<TYPE> &p); // Scale rect by inversed point
template<class TYPE>
TRect<TYPE> operator+(const TRect<TYPE> &a, const TRect<TYPE> &b); // Return intersection of rects
template<class TYPE>
TRect<TYPE> operator*(const TRect<TYPE> &a, const TRect<TYPE> &b); // Return bounding rectangle for two rects
template<class TYPE>
TRect<TYPE> &operator+=(TRect<TYPE> &a, const TRect<TYPE> &b); // Makes rect equal to intersection with another one
template<class TYPE>
TRect<TYPE> &operator*=(TRect<TYPE> &a, const TRect<TYPE> &b); // Makes rect equal to bounding rectangle of this and another one

Also there are some functions which can be used with TRect template. Here they are.

Namespace: ntl
Include: NTL/Core/Rect.h