R-Type  2
Doom but in better
Loading...
Searching...
No Matches
Recoded::Rect< T > Class Template Reference

A generic 2D rectangle class that holds position and size as pairs. More...

#include <Rect.hpp>

Collaboration diagram for Recoded::Rect< T >:
Collaboration graph

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)
 

Detailed Description

template<typename T>
class Recoded::Rect< T >

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.

Template Parameters
TThe numeric type used for position and size (e.g., int, float).

Definition at line 38 of file Rect.hpp.

Constructor & Destructor Documentation

◆ Rect() [1/2]

template<typename T >
Recoded::Rect< T >::Rect ( )

Default constructor, initializes the rectangle with default values (0, 0) for position and size.

Definition at line 17 of file Rect.cpp.

◆ Rect() [2/2]

template<typename T >
Recoded::Rect< T >::Rect ( std::pair< T, T > position,
std::pair< T, T > size )

Constructor. Initializes the Rect component with a specified:

  • position
  • size
Parameters
positionThe position (top-left corner) of the rectangle.
sizeThe size (width, height) of the rectangle.

Definition at line 20 of file Rect.cpp.

Member Function Documentation

◆ contains()

template<typename T >
bool Recoded::Rect< T >::contains ( std::pair< T, T > point) const
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.

Parameters
pointThe point (x, y) to test for inclusion.
Returns
true if the point is inside the rectangle; false otherwise.

Definition at line 36 of file Rect.cpp.

◆ findIntersection()

template<typename T >
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.

Parameters
rectThe other rectangle to test for intersection.
Returns
An optional containing the intersection rectangle if they intersect, or std::nullopt if they don't.

Definition at line 43 of file Rect.cpp.

◆ getCenter()

template<typename T >
std::pair< T, T > Recoded::Rect< T >::getCenter ( ) const

Gets the center of the rectangle.

The center is calculated as the midpoint of the rectangle's position and size.

Returns
A pair representing the center coordinates (x, y).

Definition at line 63 of file Rect.cpp.

◆ operator Rect< U >()

template<typename T >
template<typename U >
Recoded::Rect< T >::operator Rect< U > ( ) const
explicitconstexpr

Converts this rectangle to another type of rectangle.

This operator allows casting from one rectangle type to another (e.g., from Rect<int> to Rect<float>).

Template Parameters
UThe target type for the conversion.
Returns
A new rectangle of type Rect<U>.

Definition at line 27 of file Rect.cpp.

Field Documentation

◆ position

template<typename T >
std::pair<T, T> Recoded::Rect< T >::position {}

the position (top and left corner)

Definition at line 97 of file Rect.hpp.

◆ size

template<typename T >
std::pair<T, T> Recoded::Rect< T >::size {}

The size of the rectangle (width, height)

Definition at line 98 of file Rect.hpp.


The documentation for this class was generated from the following files: