This union represents four integer values or an integer rectangle.
You can find more information in comments below.
union Rect
{
struct
{
int Left;
int Top;
int Right;
int Bottom;
};
struct
{
Point LeftTop;
Point RightBottom;
};
int Data[4];
int operator[](const int index) const; // Return element
int &operator[](const int index); // Return element
explicit operator RectF() const; // Convert to RectF
bool is_valid() const; // Return whether right border isn't less than left and bottom isn't less than top
bool is_empty() const; // Return whether right border is same as left and bottom is same as top
bool is_zero() const; // Return whether either right border is same to left or bottom is same to top
bool has_negative() const; // Whether there is a negative element
bool has_positive() const; // Whether there is a positive element
int width() const; // Rectangle width
int height() const; // Rectangle height
void validate(); // Make width and height not negative
};
Following operators are also available.
bool operator==(const Rect &a, const Rect &b); // Check if rects are equal
bool operator!=(const Rect &a, const Rect &b); // Check if rects are not equal
Rect operator+(const Rect &a, const int value); // Add rect and value
Rect operator-(const Rect &a, const int value); // Subtract rect and value
Rect operator/(const Rect &a, const int value); // Divide rect and value
Rect operator*(const Rect &a, const int value); // Multiply rect and value
Rect operator+(const int value, const Rect &a); // Add value and rect
Rect operator-(const int value, const Rect &a); // Subtract value and rect
Rect operator/(const int value, const Rect &a); // Divide value and rect
Rect operator*(const int value, const Rect &a); // Multiply value and rect
Rect &operator+=(Rect &a, const int value); // Add value to rect
Rect &operator-=(Rect &a, const int value); // Subtract value from rect
Rect &operator/=(Rect &a, const int value); // Divide rect on value
Rect &operator*=(Rect &a, const int value); // Multiply rect on value
Rect operator+(const Rect &a, const Rect &b); // Find bounding rect for both rects
Rect operator*(const Rect &a, const Rect &b); // Calculate intersection
Rect &operator+=(Rect &a, const Rect &b); // Find bounding rect for both rects and store it in first one
Rect &operator*=(Rect &a, const Rect &b); // Calculate intersection and store it in first one
Rect operator+(const Rect &a, const Point &shift); // Return moved in shift direction rect
Rect operator-(const Rect &a, const Point &shift); // Return moved in opposite to shift direction rect
Rect operator*(const Rect &a, const Point &shift); // Return scaled in shift direction rect
Rect &operator+=(Rect &a, const Point &shift); // Move rect in shift direction
Rect &operator-=(Rect &a, const Point &shift); // Move rect in direction opposite to shift
Rect &operator*=(Rect &a, const Point &shift); // Scale rect in shift direction
std::wostream &operator<<(std::wostream &stream, const Rect &a); // Output as source code
Namespace: | nitisa |
Include: |
Nitisa/Core/Math/Rect.h (For union declaration) Nitisa/Core/Math/RectUtils.h (For standalone operators) |