3#include <Infinity/api.h>
4#include <Infinity/Types/Core/Value.hpp>
5#include <Infinity/Types/Containers/Array.hpp>
6#include <Infinity/Types/Math/Vector2.hpp>
69 struct INFINITY_API_PUBLIC
Rect
82 l(0.0f), r(0.0f), t(0.0f), b(0.0f)
91 l(r.l), r(r.r), t(r.t), b(r.b)
110 constexpr Rect(
float l,
float r,
float t,
float b) :
111 l(l), r(r), t(t), b(b)
147 return Rect(0.0f, 0.0f, 0.0f, 0.0f);
158 void set(
float in_l,
float in_r,
float in_t,
float in_b);
335 explicit operator bool() const noexcept;
345 constexpr
bool operator==(const
Rect& lhs, const
Rect& rhs)
347 return lhs.l == rhs.l && lhs.r == rhs.r && lhs.t == rhs.t && lhs.b == rhs.b;
357 constexpr bool operator!=(
const Rect& lhs,
const Rect& rhs)
359 return lhs.
l != rhs.
l || lhs.
r != rhs.
r || lhs.
t != rhs.
t || lhs.
b != rhs.
b;
373 return Rect(lhs.
l - rhs.
l, lhs.
r - rhs.
r, lhs.
t - rhs.
t, lhs.
b - rhs.
b);
386 return Rect(-v.
l, -v.
r, -v.
t, -v.
b);
400 return Rect(lhs.
l + rhs.
l, lhs.
r + rhs.
r, lhs.
t + rhs.
t, lhs.
b + rhs.
b);
412 inline std::ostream& operator<<(std::ostream& out,
const Rect& r)
414 out << r.
l <<
" " << r.
r <<
" " << r.
t <<
" " << r.
b;
427 inline std::istream& operator>>(std::istream& in,
Rect& r)
429 in >> r.
l >> r.
r >> r.
t >> r.
b;
Dynamic contiguous container for homogeneous elements in the Infinity type system.
Definition Array.hpp:77
Template wrapper for primitive types to integrate with the Infinity type system.
Definition Value.hpp:89
constexpr Rect operator-(const Rect &lhs, const Rect &rhs)
Rectangle subtraction operator.
Definition Rect.hpp:371
constexpr Rect operator+(const Rect &lhs, const Rect &rhs)
Rectangle addition operator.
Definition Rect.hpp:398
Axis-aligned rectangle defined by left, right, top, and bottom edges.
Definition Rect.hpp:70
constexpr Rect()
Default constructor.
Definition Rect.hpp:81
float area() const
Computes the area of the rectangle.
Vector2 center() const
Computes the center point of the rectangle.
Rect & operator+=(const Vector2 &rhs)
Addition assignment with a vector.
Rect & operator+=(const Rect &rhs)
Addition assignment with another rectangle.
float b
Bottom edge position.
Definition Rect.hpp:74
static Rect fromSize(float x, float y, float width, float height)
Creates a rectangle from position and size.
constexpr Rect(const Rect &r)
Copy constructor.
Definition Rect.hpp:90
float height() const
Computes the height of the rectangle.
float t
Top edge position.
Definition Rect.hpp:73
Vector2 bottomLeft() const
Gets the bottom-left corner position.
Rect scaled(float factor) const
Creates a scaled copy of this rectangle.
constexpr Rect & operator=(const Rect &)=default
Copy assignment operator.
float width() const
Computes the width of the rectangle.
constexpr Rect(float l, float r, float t, float b)
Constructs a rectangle from edge positions.
Definition Rect.hpp:110
Vector2 bottomRight() const
Gets the bottom-right corner position.
Rect translated(const Vector2 &offset) const
Creates a translated copy of this rectangle.
float r
Right edge position.
Definition Rect.hpp:72
bool contains(const Vector2 &p) const
Tests if a point is contained within the rectangle.
static constexpr Rect zero()
Creates a zero-sized rectangle at the origin.
Definition Rect.hpp:145
float l
Left edge position.
Definition Rect.hpp:71
Vector2 size() const
Gets the size of the rectangle as a vector.
Vector2 topRight() const
Gets the top-right corner position.
void set(float in_l, float in_r, float in_t, float in_b)
Sets all four edge positions.
Rect & operator-=(const Rect &rhs)
Subtraction assignment with another rectangle.
Vector2 topLeft() const
Gets the top-left corner position.
Rect & operator-=(const Vector2 &rhs)
Subtraction assignment with a vector.
Template structure representing a 2-component vector.
Definition Vector2.hpp:75