![]() |
R-Type
2
Doom but in better
|
A generic 2D rectangle class that holds position and size as pairs. More...
#include <Rect.hpp>
Public Member Functions | |
Rect () | |
Default constructor, initializes the rectangle with default values (0, 0) for position and size. | |
Rect (std::pair< T, T > position, std::pair< T, T > size) | |
Constructor. Initializes the Rect component with a specified: | |
template<typename U > | |
constexpr | operator Rect< U > () const |
Converts this rectangle to another type of rectangle. | |
constexpr bool | contains (std::pair< T, T > point) const |
Checks if a point is inside the rectangle (non-inclusive). | |
std::optional< Rect< T > > | findIntersection (const Rect< T > &rect) const |
Finds the intersection between this rectangle and another. | |
std::pair< T, T > | getCenter () const |
Gets the center of the rectangle. | |
Data Fields | |
std::pair< T, T > | position {} |
the position (top and left corner) | |
std::pair< T, T > | size {} |
The size of the rectangle (width, height) | |
A generic 2D rectangle class that holds position and size as pairs.
This class provides the functionality to work with rectangles in a coordinate system. The position is the top-left corner, and the size represents the width and height.
T | The numeric type used for position and size (e.g., int, float). |
Recoded::Rect< T >::Rect | ( | ) |
Recoded::Rect< T >::Rect | ( | std::pair< T, T > | position, |
std::pair< T, T > | size ) |
|
constexpr |
Checks if a point is inside the rectangle (non-inclusive).
This function checks if a given point lies strictly within the rectangle's boundaries. The rectangle's edges are not considered part of the area.
point | The point (x, y) to test for inclusion. |
std::optional< Recoded::Rect< T > > Recoded::Rect< T >::findIntersection | ( | const Rect< T > & | rect | ) | const |
Finds the intersection between this rectangle and another.
If the rectangles do not intersect, this function returns std::nullopt
. Otherwise, it returns the intersecting rectangle.
rect | The other rectangle to test for intersection. |
std::nullopt
if they don't. std::pair< T, T > Recoded::Rect< T >::getCenter | ( | ) | const |
|
explicitconstexpr |
std::pair<T, T> Recoded::Rect< T >::position {} |
std::pair<T, T> Recoded::Rect< T >::size {} |