#include <nCine/Primitives/Rect.h>
template<class T>
Rect class
Rectangle in a two-dimensional space.
Stored as a top-left point (X, Y) and a size (W, H). The size may be negative, in which case X / Y no longer mark the top-left corner; the Min() and Max() helpers normalize this. Provides construction from a center or from minimum and maximum coordinates, containment and overlap tests, and intersection and union operations.
Public static functions
- static auto FromCenterSize(T xx, T yy, T ww, T hh) -> Rect
- Creates a rectangle from a center point and a size.
- static auto FromCenterSize(const Vector2<T>& center, const Vector2<T>& size) -> Rect
- Creates a rectangle from a center point and a size as two Vector2.
- static auto FromMinMax(T minX, T minY, T maxX, T maxY) -> Rect
- Creates a rectangle from minimum and maximum coordinates.
- static auto FromMinMax(const Vector2<T>& min, const Vector2<T>& max) -> Rect
- Creates a rectangle from minimum and maximum coordinates as two Vector2.
Constructors, destructors, conversion operators
- Rect() constexpr noexcept
- Default constructor, all zeros.
- Rect(NoInitT) explicit noexcept
- Rect(T x, T y, T w, T h) constexpr noexcept
- Constructs a rectangle from a top-left point and a size.
- Rect(const Vector2<T>& point, const Vector2<T>& size) constexpr noexcept
- Constructs a rectangle from a top-left point and a size as two Vector2.
Public functions
- auto GetSize() const -> Vector2<T>
- Returns the size as a vector.
- auto GetLocation() const -> Vector2<T>
- Returns the top-left point as a vector.
- auto Center() const -> Vector2<T>
- Returns the center of the rectangle.
- auto Min() const -> Vector2<T>
- Returns the minimum coordinates, accounting for a negative size.
- auto Max() const -> Vector2<T>
- Returns the maximum coordinates, accounting for a negative size.
- void Set(T x, T y, T w, T h)
- Sets the top-left point and the size.
- void Set(const Vector2<T>& point, const Vector2<T>& size)
- Sets the top-left point and the size as two Vector2.
- void SetCenter(float cx, float cy)
- Moves the center to a new position, keeping the size.
- void SetCenter(const Vector2<T>& center)
- Moves the center to a new position as a Vector2, keeping the size.
- void SetSize(float ww, float hh)
- Changes the size, keeping the center.
- void SetSize(const Vector2<T>& size)
- Changes the size as a Vector2, keeping the center.
- void SetCenterSize(T xx, T yy, T ww, T hh)
- Sets the center and the size.
- void SetCenterSize(const Vector2<T>& center, const Vector2<T>& size)
- Sets the center and the size as two Vector2.
- void SetMinMax(T minX, T minY, T maxX, T maxY)
- Sets the minimum and maximum coordinates.
- void SetMinMax(const Vector2<T>& min, const Vector2<T>& max)
- Sets the minimum and maximum coordinates as two Vector2.
-
template<class S>auto As() -> Rect<S>
- Converts the rectangle to a different element type.
- void InvertSize()
- Negates the size while keeping the same covered area, flipping the top-left corner.
- auto Contains(T px, T py) const -> bool
- Returns
trueif the point is inside the rectangle. - auto Contains(const Vector2<T>& p) const -> bool
- Returns
trueif the point vector is inside the rectangle. - auto Contains(const Rect<T>& rect) const -> bool
- Returns
trueif the other rectangle is fully contained within this one. - auto Overlaps(const Rect<T>& rect) const -> bool
- Returns
trueif this rectangle overlaps the other one in any way. - void Intersect(const Rect<T>& rect)
- Clips this rectangle to its intersection with the other rectangle.
- void Union(const Rect<T>& rect)
- Expands this rectangle to the bounding box of both rectangles.
- auto operator==(const Rect& rect) const -> bool
- auto operator!=(const Rect& rect) const -> bool