31 #include "Portability.h" 35 #ifndef DOXYGEN_SHOULD_SKIP_THIS 101 : left{0}, top{0}, width{0}, height{0}
117 constexpr
Rect(
T rectLeft,
T rectTop,
T rectWidth,
T rectHeight) noexcept
118 : left{rectLeft}, top{rectTop}, width{rectWidth}, height{rectHeight}
133 : left(position.x), top(position.y), width(size.width), height(size.height)
146 Rect& operator=(
const Rect&) =
default;
155 return { left, top };
176 return { width, height };
187 height = size.height;
199 return width == 0 || height == 0;
205 return { left, top };
207 return { left + width / 2, top };
209 return { left + width, top };
211 return { left, top + height / 2 };
213 return { left + width / 2, top + height / 2 };
215 return { left + width, top + height / 2 };
217 return { left, top + height };
219 return { left + width / 2, top + height };
221 return { left + width, top + height };
224 return { left, top };
281 return left <= point.x && point.x < left + width && top <= point.y && point.y < top + height;
292 return left <= other.left && other.left + other.width <= left + width
293 && top <= other.top && other.top + other.height <= top + height;
304 return left + width > other.left && left < other.left + other.width
305 && top + height > other.top && top < other.top + other.height;
320 if (!intersects(other)) {
325 T resultLeft = std::max(left, other.left);
326 T resultTop = std::max(top, other.top);
327 T resultRight = std::min(left + width, other.left + other.width);
328 T resultBottom = std::min(top + height, other.top + other.height);
330 result =
Rect<T>(resultLeft, resultTop, resultRight - resultLeft, resultBottom - resultTop);
342 return Rect<T>(left - value, top - value, width + 2 * value, height + 2 * value);
353 return Rect<T>(left + value, top + value, width - 2 * value, height - 2 * value);
421 return !(lhs == rhs);
432 template<
typename Archive,
typename T>
438 #ifndef DOXYGEN_SHOULD_SKIP_THIS T top
Top coordinate of the rectangle.
Definition: Rect.h:90
constexpr Vector< T, 2 > getBottomLeft() const noexcept
Get the bottom left corner.
Definition: Rect.h:259
bool operator!=(const Rect< T > &lhs, const Rect< T > &rhs)
Inequality operator.
Definition: Rect.h:420
constexpr bool isEmpty() const noexcept
Check if the rectangle is empty.
Definition: Rect.h:198
constexpr Vector< T, 2 > getPositionFromAnchor(Anchor anchor) const noexcept
Definition: Rect.h:202
Archive & operator|(Archive &ar, Rect< T > &rect)
Serialize a rectangle.
Definition: Rect.h:433
bool intersects(const Rect< T > &other, Rect< T > &result) const noexcept
Check the intersection between two rectangles.
Definition: Rect.h:319
constexpr Vector< T, 2 > getPosition() const noexcept
Get the position of the rectangle.
Definition: Rect.h:154
constexpr Rect< T > grow(T value) const noexcept
Grow the rectangle.
Definition: Rect.h:341
constexpr void setPosition(Vector< T, 2 > position) noexcept
Set the position of the rectangle.
Definition: Rect.h:164
constexpr bool intersects(const Rect< T > &other) const noexcept
Check the intersection between two rectangles.
Definition: Rect.h:303
constexpr void setSize(Vector< T, 2 > size) noexcept
Set the size of the rectangle.
Definition: Rect.h:185
constexpr bool contains(const Rect< T > &other) const noexcept
Check if a rectangle is inside the rectangle's area.
Definition: Rect.h:291
constexpr Vector< T, 2 > getTopRight() const noexcept
Get the top right corner.
Definition: Rect.h:250
T width
Width of the rectangle.
Definition: Rect.h:91
Utility class for manipulating 2D axis aligned rectangles.
Definition: Rect.h:88
The namespace for gf classes.
Definition: Action.h:34
constexpr Rect< T > shrink(T value) const noexcept
Shrink the rectangle.
Definition: Rect.h:352
constexpr Vector< T, 2 > getCenter() const noexcept
Get the center of the rectangle.
Definition: Rect.h:232
A 2D vector.
Definition: Vector.h:316
constexpr Rect() noexcept
Default constructor.
Definition: Rect.h:100
constexpr Vector< T, 2 > getTopLeft() const noexcept
Get the top left corner.
Definition: Rect.h:241
T left
Left coordinate of the rectangle.
Definition: Rect.h:89
T height
Height of the rectangle.
Definition: Rect.h:92
constexpr Vector< T, 2 > getBottomRight() const noexcept
Get the bottom right corner.
Definition: Rect.h:268
Anchor
An anchor of a box.
Definition: Anchor.h:38
constexpr bool contains(const Vector< T, 2 > &point) const noexcept
Check if a point is inside the rectangle's area.
Definition: Rect.h:280
constexpr Vector< T, 2 > getSize() const noexcept
Get the size of the rectangle.
Definition: Rect.h:175
constexpr Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) noexcept
Construct the rectangle from its coordinates.
Definition: Rect.h:117
bool operator==(const Rect< T > &lhs, const Rect< T > &rhs)
Equality operator.
Definition: Rect.h:406
Rect(const Vector< T, 2 > &position, const Vector< T, 2 > &size) noexcept
Construct the rectangle from position and size.
Definition: Rect.h:132