34template <
typename T>
class Rect {
48 T x()
const {
return _pos.x(); }
51 T y()
const {
return _pos.y(); }
54 T width()
const {
return _size.width(); }
57 T height()
const {
return _size.height(); }
99 bool isValid()
const {
return _size.isValid(); }
106 return p.x() >=
x() && p.x() <
x() +
width() &&
107 p.y() >=
y() && p.y() <
y() +
height();
124 T ix = std::max(
x(), r.
x());
125 T iy = std::max(
y(), r.
y());
136 T ux = std::min(
x(), r.
x());
137 T uy = std::min(
y(), r.
y());
156 return _pos ==
other._pos && _size.width() ==
other._size.width() &&
157 _size.height() ==
other._size.height();
162 return !(*
this ==
other);
Dynamic array container wrapping std::vector.
Definition list.h:40
2D rectangle defined by position and size.
Definition rect.h:34
void setWidth(T val)
Sets the width.
Definition rect.h:66
const Size2DTemplate< T > & size() const
Returns the size.
Definition rect.h:90
Rect adjusted(T dx1, T dy1, T dx2, T dy2) const
Returns a rectangle adjusted by the given deltas.
Definition rect.h:144
void setSize(const Size2DTemplate< T > &s)
Sets the size.
Definition rect.h:96
T height() const
Returns the height.
Definition rect.h:57
bool operator!=(const Rect &other) const
Inequality operator.
Definition rect.h:161
void setPos(const Point< T, 2 > &p)
Sets the position.
Definition rect.h:93
Rect(const Point< T, 2 > &pos, const Size2DTemplate< T > &size)
Constructs a rectangle from position and size.
Definition rect.h:40
void setHeight(T val)
Sets the height.
Definition rect.h:69
Point< T, 2 > bottomLeft() const
Returns the bottom-left position.
Definition rect.h:78
bool operator==(const Rect &other) const
Equality operator.
Definition rect.h:155
T width() const
Returns the width.
Definition rect.h:54
bool intersects(const Rect &r) const
Returns true if the given rectangle overlaps this rectangle.
Definition rect.h:117
bool contains(const Point< T, 2 > &p) const
Returns true if the given point is inside this rectangle.
Definition rect.h:105
void setY(T val)
Sets the Y coordinate.
Definition rect.h:63
bool contains(const Rect &r) const
Returns true if the given rectangle is entirely inside this rectangle.
Definition rect.h:111
Rect translated(T dx, T dy) const
Returns a rectangle translated by dx, dy.
Definition rect.h:150
T x() const
Returns the X coordinate of the left edge.
Definition rect.h:48
bool isValid() const
Returns true if both width and height are greater than zero.
Definition rect.h:99
Point< T, 2 > topLeft() const
Returns the top-left position.
Definition rect.h:72
Rect intersected(const Rect &r) const
Returns the intersection of this rectangle with another.
Definition rect.h:123
Point< T, 2 > center() const
Returns the center point.
Definition rect.h:84
Point< T, 2 > topRight() const
Returns the top-right position.
Definition rect.h:75
T y() const
Returns the Y coordinate of the top edge.
Definition rect.h:51
Rect(T x, T y, T width, T height)
Constructs a rectangle from individual components.
Definition rect.h:44
void setX(T val)
Sets the X coordinate.
Definition rect.h:60
bool isEmpty() const
Returns true if width or height is zero or negative.
Definition rect.h:102
Rect united(const Rect &r) const
Returns the smallest rectangle containing both this and another.
Definition rect.h:133
const Point< T, 2 > & pos() const
Returns the position (top-left).
Definition rect.h:87
Point< T, 2 > bottomRight() const
Returns the bottom-right position.
Definition rect.h:81
Rect()=default
Default constructor. Creates an empty rectangle at origin.
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19