30 #include "Portability.h" 34 #ifndef DOXYGEN_SHOULD_SKIP_THIS 100 : left{0}, top{0}, width{0}, height{0}
116 constexpr
Rect(
T rectLeft,
T rectTop,
T rectWidth,
T rectHeight) noexcept
117 : left{rectLeft}, top{rectTop}, width{rectWidth}, height{rectHeight}
132 : left(position.x), top(position.y), width(size.width), height(size.height)
145 Rect& operator=(
const Rect&) =
default;
154 return { left, top };
175 return { width, height };
186 height = size.height;
198 return width == 0 || height == 0;
207 return { left + width / 2, top + height / 2 };
216 return { left, top };
225 return { left + width, top };
234 return { left, top + height };
243 return { left + width, top + height };
255 return left <= point.x && point.x < left + width && top <= point.y && point.y < top + height;
266 return left <= other.left && other.left + other.width <= left + width
267 && top <= other.top && other.top + other.height <= top + height;
278 return left + width > other.left && left < other.left + other.width
279 && top + height > other.top && top < other.top + other.height;
294 if (!intersects(other)) {
299 T resultLeft = std::max(left, other.left);
300 T resultTop = std::max(top, other.top);
301 T resultRight = std::min(left + width, other.left + other.width);
302 T resultBottom = std::min(top + height, other.top + other.height);
304 result =
Rect<T>(resultLeft, resultTop, resultRight - resultLeft, resultBottom - resultTop);
316 return Rect<T>(left - value, top - value, width + 2 * value, height + 2 * value);
327 return Rect<T>(left + value, top + value, width - 2 * value, height - 2 * value);
395 return !(lhs == rhs);
398 #ifndef DOXYGEN_SHOULD_SKIP_THIS T top
Top coordinate of the rectangle.
Definition: Rect.h:89
constexpr Vector< T, 2 > getBottomLeft() const noexcept
Get the bottom left corner.
Definition: Rect.h:233
bool operator!=(const Rect< T > &lhs, const Rect< T > &rhs)
Inequality operator.
Definition: Rect.h:394
constexpr bool isEmpty() const noexcept
Check if the rectangle is empty.
Definition: Rect.h:197
bool intersects(const Rect< T > &other, Rect< T > &result) const noexcept
Check the intersection between two rectangles.
Definition: Rect.h:293
constexpr Vector< T, 2 > getPosition() const noexcept
Get the position of the rectangle.
Definition: Rect.h:153
constexpr Rect< T > grow(T value) const noexcept
Grow the rectangle.
Definition: Rect.h:315
constexpr void setPosition(Vector< T, 2 > position) noexcept
Set the position of the rectangle.
Definition: Rect.h:163
constexpr bool intersects(const Rect< T > &other) const noexcept
Check the intersection between two rectangles.
Definition: Rect.h:277
constexpr void setSize(Vector< T, 2 > size) noexcept
Set the size of the rectangle.
Definition: Rect.h:184
constexpr bool contains(const Rect< T > &other) const noexcept
Check if a rectangle is inside the rectangle's area.
Definition: Rect.h:265
constexpr Vector< T, 2 > getTopRight() const noexcept
Get the top right corner.
Definition: Rect.h:224
T width
Width of the rectangle.
Definition: Rect.h:90
Utility class for manipulating 2D axis aligned rectangles.
Definition: Rect.h:87
The namespace for gf classes.
Definition: Action.h:34
constexpr Rect< T > shrink(T value) const noexcept
Shrink the rectangle.
Definition: Rect.h:326
constexpr Vector< T, 2 > getCenter() const noexcept
Get the center of the rectangle.
Definition: Rect.h:206
A 2D vector.
Definition: Vector.h:316
constexpr Rect() noexcept
Default constructor.
Definition: Rect.h:99
constexpr Vector< T, 2 > getTopLeft() const noexcept
Get the top left corner.
Definition: Rect.h:215
T left
Left coordinate of the rectangle.
Definition: Rect.h:88
T height
Height of the rectangle.
Definition: Rect.h:91
constexpr Vector< T, 2 > getBottomRight() const noexcept
Get the bottom right corner.
Definition: Rect.h:242
constexpr bool contains(const Vector< T, 2 > &point) const noexcept
Check if a point is inside the rectangle's area.
Definition: Rect.h:254
constexpr Vector< T, 2 > getSize() const noexcept
Get the size of the rectangle.
Definition: Rect.h:174
constexpr Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) noexcept
Construct the rectangle from its coordinates.
Definition: Rect.h:116
bool operator==(const Rect< T > &lhs, const Rect< T > &rhs)
Equality operator.
Definition: Rect.h:380
Rect(const Vector< T, 2 > &position, const Vector< T, 2 > &size) noexcept
Construct the rectangle from position and size.
Definition: Rect.h:131