4#include <SDL3/SDL_rect.h>
19 Vec2 operator+(T scalar) {
20 return {x + scalar, y + scalar};
23 Vec2 operator+(
const Vec2 &other)
const {
24 return {x + other.x, y + other.y};
27 Vec2 operator-(T scalar) {
28 return {x - scalar, y - scalar};
31 Vec2 operator-(
const Vec2 &other)
const {
32 return {x - other.x, y - other.y};
35 Vec2 operator*(T scalar)
const {
36 return {x * scalar, y * scalar};
39 Vec2 operator*(
const Vec2 &other)
const {
40 return {x * other.x, y * other.y};
43 Vec2 operator/(T scalar)
const {
44 return {x / scalar, y / scalar};
47 Vec2 operator/(
const Vec2 &other)
const {
48 return {x / other.x, y / other.y};
51 Vec2 &operator+=(
const Vec2 &other) {
57 Vec2 &operator-=(
const Vec2 &other) {
63 Vec2 &operator*=(T scalar) {
69 Vec2 &operator/=(T scalar) {
75 bool operator==(
const Vec2 &other)
const =
default;
112 Rect(T x, T y, T w, T h)
131 if (x2 > x1 && y2 > y1) {
157 if constexpr (std::is_same_v<T, int>) {
159 static_cast<int>(
size.x),
static_cast<int>(
size.y)};
171 if constexpr (std::is_same_v<T, int>) {
178 {
static_cast<T
>(rect.x),
static_cast<T
>(rect.y)},
179 {
static_cast<T
>(rect.w),
static_cast<T
>(rect.h)}
197 using IntRect = Rect<int>;
198 using FloatRect = Rect<float>;
auto toNative() const
Convert to the corresponding SDL rectangle type.
std::optional< Rect< T > > findIntersection(const Rect< T > &other) const
Compute the intersection with another rectangle.
std::optional< Rect > getGlobalBounds() const
Return this rect as an optional, or nullopt if it has zero/negative area.
static auto fromNative(const SDL_Rect &rect)
Construct a Rect from an SDL_Rect.
Rect(Vec2< T > position, Vec2< T > size)
Construct a Rect from explicit position and size.
bool contains(const Vec2< T > &point) const
Test whether point lies inside the rectangle (half-open interval).
Generic axis-aligned rectangle defined by a position and size.
Generic 2-D vector with arithmetic operators.