This union represents four floating point values or a float point rectangle.
Point is considered inside (in is_inside()
and is_outside()
methods) if its X coordinate is in range [Left, Right) and its Y coordinate is in range [Top, Bottom). It means if point lies directly on Left or Top border it is considered to be inside rectangle but if it lies on Right or Bottom border it is considered to be outside of rectangle.
You can find more information in comments below.
union RectF
{
struct
{
float Left;
float Top;
float Right;
float Bottom;
};
struct
{
PointF LeftTop;
PointF RightBottom;
};
float Data[4];
float operator[](const int index) const; // Return element
float &operator[](const int index); // Return element
bool is_valid(const float tolerance = ntl::Tolerance<float>) const; // Return whether right border isn't less than left and bottom isn't less than top
bool is_empty(const float tolerance = ntl::Tolerance<float>) const; // Return whether right border is same as left and bottom is same as top
bool is_zero(const float tolerance = ntl::Tolerance<float>) const; // Return whether either right border is same to left or bottom is same to top
bool has_negative(const float tolerance = ntl::Tolerance<float>) const; // Whether there is a negative element
bool has_positive(const float tolerance = ntl::Tolerance<float>) const; // Whether there is a positive element
bool has_area(const float tolerance = ntl::Tolerance<float>) const; // Return whether rectangle has positive area
float width() const; // Rectangle width
float height() const; // Rectangle height
void validate(const float tolerance = ntl::Tolerance<float>); // Make width and height not negative
bool is_inside(const PointF &p, const float tolerance = ntl::Tolerance<float>) const; // Return whether point is inside of the rectangle
bool is_outside(const PointF &p, const float tolerance = ntl::Tolerance<float>) const; // Return whether point is outside of the rectangle
};
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
RectF operator*(const RectF &a, const PointF &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
RectF &operator*=(RectF &a, const PointF &shift); // Scale rect in shift direction
std::wostream &operator<<(std::wostream &stream, const RectF &a); // Output as source code
Namespace: | nitisa |
Include: | Nitisa/Math/RectF.h |