SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
spark::math::Rectangle< T > Class Template Reference

Represents a rectangle in 2D space. More...

#include <Rectangle.h>

Public Member Functions

constexpr Rectangle ()=default
 \brif Initializes a Rectangle with position and extent set to {0, 0}.
 
 Rectangle (const Vector2< T > &position, const Vector2< T > &extent)
 Initializes a Rectangle with the given position and extent.
 
 Rectangle (T x, T y, T width, T height)
 Initializes a Rectangle with the given position and extent.
 
constexpr bool operator== (const Rectangle &other) const noexcept
 Compares two Rectangle for equality.
 
constexpr bool operator!= (const Rectangle &other) const noexcept
 Compares two Rectangle for inequality.
 
template<typename To >
constexpr Rectangle< To > castTo () const
 Casts the rectangle to a rectangle with a different component type.
 

Public Attributes

spark::math::Vector2< T > position = {}
 
spark::math::Vector2< T > extent = {}
 

Detailed Description

template<typename T>
class spark::math::Rectangle< T >

Represents a rectangle in 2D space.

Template Parameters
TThe type of the rectangle's components.

A rectangle is defined by a position (top left) and an extent (width and height).

Constructor & Destructor Documentation

◆ Rectangle() [1/2]

template<typename T >
spark::math::Rectangle< T >::Rectangle ( const Vector2< T > & position,
const Vector2< T > & extent )
explicit

Initializes a Rectangle with the given position and extent.

Parameters
positionThe position of the rectangle (top left corner coordinates).
extentThe extent of the rectangle (width and height).

◆ Rectangle() [2/2]

template<typename T >
spark::math::Rectangle< T >::Rectangle ( T x,
T y,
T width,
T height )
explicit

Initializes a Rectangle with the given position and extent.

Parameters
xThe x coordinate of the rectangle's top left corner.
yThe y coordinate of the rectangle's top left corner.
widthThe width of the rectangle.
heightThe height of the rectangle.

Member Function Documentation

◆ castTo()

template<typename T >
template<typename To >
Rectangle< To > spark::math::Rectangle< T >::castTo ( ) const
constexpr

Casts the rectangle to a rectangle with a different component type.

Template Parameters
ToThe type of the new rectangle's components.
Returns
A Rectangle with the same position and extent as this rectangle, but with components of type To.

◆ operator!=()

template<typename T >
bool spark::math::Rectangle< T >::operator!= ( const Rectangle< T > & other) const
constexprnoexcept

Compares two Rectangle for inequality.

Parameters
otherA Rectangle to compare with.
Returns
true if this is not equal to other false otherwise.

◆ operator==()

template<typename T >
bool spark::math::Rectangle< T >::operator== ( const Rectangle< T > & other) const
constexprnoexcept

Compares two Rectangle for equality.

Parameters
otherA Rectangle to compare with.
Returns
true if this is equal to other false otherwise.