34 #ifndef DOXYGEN_SHOULD_SKIP_THIS
112 : left{0}, top{0}, width{0}, height{0}
128 constexpr Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight)
noexcept
129 : left{rectLeft}, top{rectTop}, width{rectWidth}, height{rectHeight}
144 : position(rectPosition), size(rectSize)
182 return width == 0 || height == 0;
191 return { left + width / 2, top + height / 2 };
200 return { left, top };
209 return { left + width, top };
218 return { left, top + height };
227 return { left + width, top + height };
239 return left <= point.x && point.x < left + width && top <= point.y && point.y < top + height;
250 return left <= other.left && other.left + other.width <= left + width
251 && top <= other.top && other.top + other.height <= top + height;
262 return left + width > other.left && left < other.left + other.width
263 && top + height > other.top && top < other.top + other.height;
278 if (!intersects(other)) {
283 T resultLeft = std::max(left, other.left);
284 T resultTop = std::max(top, other.top);
285 T resultRight = std::min(left + width, other.left + other.width);
286 T resultBottom = std::min(top + height, other.top + other.height);
288 result =
Rect<T>(resultLeft, resultTop, resultRight - resultLeft, resultBottom - resultTop);
300 return Rect<T>(left - value, top - value, width + 2 * value, height + 2 * value);
311 return Rect<T>(left + value, top + value, width - 2 * value, height - 2 * value);
337 using RectZ =
Rect<std::size_t>;
341 extern template struct Rect<
float>;
342 extern template struct Rect<
int>;
343 extern template struct Rect<
unsigned>;
357 return lhs.position == rhs.position && lhs.size == rhs.size;
371 return lhs.position != rhs.position || lhs.size != rhs.size;
374 #ifndef DOXYGEN_SHOULD_SKIP_THIS
Rect(const Vector< T, 2 > &rectPosition, const Vector< T, 2 > &rectSize) noexcept
Construct the rectangle from position and size.
Definition: Rect.h:143
constexpr Vector< T, 2 > getBottomLeft() const noexcept
Get the bottom left corner.
Definition: Rect.h:217
bool operator!=(const Rect< T > &lhs, const Rect< T > &rhs)
Inequality operator.
Definition: Rect.h:370
constexpr bool isEmpty() const noexcept
Check if the rectangle is empty.
Definition: Rect.h:181
bool intersects(const Rect< T > &other, Rect< T > &result) const noexcept
Check the intersection between two rectangles.
Definition: Rect.h:277
constexpr Vector< T, 2 > getPosition() const noexcept
Get the position of the rectangle.
Definition: Rect.h:157
constexpr Rect< T > extend(T value) const noexcept
Extend the rectangle.
Definition: Rect.h:299
constexpr bool intersects(const Rect< T > &other) const noexcept
Check the intersection between two rectangles.
Definition: Rect.h:261
constexpr bool contains(const Rect< T > &other) const noexcept
Check if a rectangle is inside the rectangle's area.
Definition: Rect.h:249
constexpr Vector< T, 2 > getTopRight() const noexcept
Get the top right corner.
Definition: Rect.h:208
Utility class for manipulating 2D axis aligned rectangles.
Definition: Rect.h:88
constexpr Rect< T > shrink(T value) const noexcept
Shrink the rectangle.
Definition: Rect.h:310
constexpr Vector< T, 2 > getCenter() const noexcept
Get the center of the rectangle.
Definition: Rect.h:190
constexpr Rect() noexcept
Default constructor.
Definition: Rect.h:111
constexpr Vector< T, 2 > getTopLeft() const noexcept
Get the top left corner.
Definition: Rect.h:199
constexpr Vector< T, 2 > getBottomRight() const noexcept
Get the bottom right corner.
Definition: Rect.h:226
constexpr bool contains(const Vector< T, 2 > &point) const noexcept
Check if a point is inside the rectangle's area.
Definition: Rect.h:238
constexpr Vector< T, 2 > getSize() const noexcept
Get the size of the rectangle.
Definition: Rect.h:169
constexpr Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) noexcept
Construct the rectangle from its coordinates.
Definition: Rect.h:128
General purpose math vector.
Definition: Vector.h:60
bool operator==(const Rect< T > &lhs, const Rect< T > &rhs)
Equality operator.
Definition: Rect.h:356