Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
Flint::Rect< T > Struct Template Reference

Generic axis-aligned rectangle defined by a position and size. More...

#include <flint/math/types.h>

+ Collaboration diagram for Flint::Rect< T >:

Public Member Functions

 Rect (Vec2< T > position, Vec2< T > size)
 Construct a Rect from explicit position and size.
 
 Rect (T x, T y, T w, T h)
 
std::optional< Rect< T > > findIntersection (const Rect< T > &other) const
 Compute the intersection with another rectangle.
 
bool contains (const Vec2< T > &point) const
 Test whether point lies inside the rectangle (half-open interval).
 
auto toNative () const
 Convert to the corresponding SDL rectangle type.
 
std::optional< Rect > getGlobalBounds () const
 Return this rect as an optional, or nullopt if it has zero/negative area.
 

Static Public Member Functions

static auto fromNative (const SDL_Rect &rect)
 Construct a Rect from an SDL_Rect.
 

Public Attributes

union { 
 
   struct { 
 
      Vec2< T >   position 
 
      Vec2< T >   size 
 
   }  
 
   struct { 
 
      T   x 
 
      T   y 
 
      T   w 
 
      T   h 
 
   }  
 
};  
 

Detailed Description

template<typename T>
struct Flint::Rect< T >

Generic axis-aligned rectangle defined by a position and size.

Template Parameters
TElement type (typically int or float).

Definition at line 87 of file types.h.

Constructor & Destructor Documentation

◆ Rect() [1/2]

template<typename T >
Flint::Rect< T >::Rect ( Vec2< T > position,
Vec2< T > size )
inline

Construct a Rect from explicit position and size.

Parameters
positionTop-left corner.
sizeDimensions (width, height).

Definition at line 107 of file types.h.

◆ Rect() [2/2]

template<typename T >
Flint::Rect< T >::Rect ( T x,
T y,
T w,
T h )
inline

Definition at line 112 of file types.h.

Member Function Documentation

◆ contains()

template<typename T >
bool Flint::Rect< T >::contains ( const Vec2< T > & point) const
inline

Test whether point lies inside the rectangle (half-open interval).

Parameters
pointPoint to test.
Returns
true if the point is inside [position, position+size).

Definition at line 146 of file types.h.

◆ findIntersection()

template<typename T >
std::optional< Rect< T > > Flint::Rect< T >::findIntersection ( const Rect< T > & other) const
inline

Compute the intersection with another rectangle.

Parameters
otherRectangle to intersect with.
Returns
The overlapping region, or std::nullopt if the rectangles do not overlap.

Definition at line 125 of file types.h.

◆ fromNative()

template<typename T >
static auto Flint::Rect< T >::fromNative ( const SDL_Rect< T > & rect)
inlinestatic

Construct a Rect from an SDL_Rect.

Parameters
rectSource SDL rectangle.

Definition at line 170 of file types.h.

◆ getGlobalBounds()

template<typename T >
std::optional< Rect > Flint::Rect< T >::getGlobalBounds ( ) const
inline

Return this rect as an optional, or nullopt if it has zero/negative area.

Returns
This rect wrapped in std::optional, or std::nullopt if degenerate.

Definition at line 189 of file types.h.

◆ toNative()

template<typename T >
auto Flint::Rect< T >::toNative ( ) const
inline

Convert to the corresponding SDL rectangle type.

Returns SDL_Rect for int instantiations and SDL_FRect for float.

Definition at line 156 of file types.h.

Member Data Documentation

◆ h

template<typename T >
T Flint::Rect< T >::h

Definition at line 95 of file types.h.

◆ position

template<typename T >
Vec2<T> Flint::Rect< T >::position

Top-left corner of the rectangle.

Definition at line 90 of file types.h.

◆ size

template<typename T >
Vec2<T> Flint::Rect< T >::size

Width (x) and height (y) of the rectangle.

Definition at line 91 of file types.h.

◆ w

template<typename T >
T Flint::Rect< T >::w

Definition at line 95 of file types.h.

◆ x

template<typename T >
T Flint::Rect< T >::x

Definition at line 95 of file types.h.

◆ y

template<typename T >
T Flint::Rect< T >::y

Definition at line 95 of file types.h.


The documentation for this struct was generated from the following file: