galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::Rect< Type > Class Template Referencefinal

Represents a rectangle object. More...

#include <Rect.hpp>

+ Inheritance diagram for galaxy::Rect< Type >:
+ Collaboration diagram for galaxy::Rect< Type >:

Public Member Functions

 Rect () noexcept
 Constructor.
 
 Rect (const Type x, const Type y, const Type width, const Type height) noexcept
 Argument constructor.
 
 ~Rect () noexcept
 Destructor.
 
bool contains (const Type _x, const Type _y) const noexcept
 Does the rectangle contain the point (x, y).
 
bool contains (const Rect< Type > &b) const noexcept
 Does the rectangle contain another rectangle.
 
bool overlaps (const Rect< Type > &b) noexcept
 Do the rectangles a and b overlap.
 
bool intersects (const Rect< Type > &b) const noexcept
 Do two rectangles intersect.
 
void set_top_left (const glm::vec< 2, Type, glm::defaultp > &pos) noexcept
 Set the top-left position.
 
Type get_right () const noexcept
 Get top right corner.
 
Type get_bottom () const noexcept
 Get bottom left corner.
 
glm::vec< 2, Type, glm::defaultp > get_top_left () const noexcept
 Get the upper-left coordinate.
 
glm::vec< 2, Type, glm::defaultp > get_center () const noexcept
 Gets the center of the rectangle.
 
glm::vec< 2, Type, glm::defaultp > get_size () const noexcept
 Gets width and height of rectangle.
 
auto operator<=> (const Rect &) const noexcept=default
 Comparison operator.
 

Public Attributes

Type x
 X position.
 
Type y
 Y position.
 
Type width
 Width of rectangle.
 
Type height
 Height of rectangle.
 

Private Member Functions

bool value_in_range (const Type value, const Type min, const Type max) noexcept
 Private function to determine if value is in range. Inclusive. Credits: https://stackoverflow.com/a/306379.
 

Detailed Description

template<meta::is_arithmetic Type>
class galaxy::Rect< Type >

Represents a rectangle object.

Template Parameters
TypeArithmetic type to use for a rectangle.

Definition at line 25 of file Rect.hpp.

Constructor & Destructor Documentation

◆ Rect() [1/2]

template<meta::is_arithmetic Type>
galaxy::Rect< Type >::Rect ( )
inlinenoexcept

Constructor.

Definition at line 189 of file Rect.hpp.

◆ Rect() [2/2]

template<meta::is_arithmetic Type>
galaxy::Rect< Type >::Rect ( const Type x,
const Type y,
const Type width,
const Type height )
inlinenoexcept

Argument constructor.

Parameters
xX value.
yY value.
widthWidth value.
heightHeight value.

Definition at line 198 of file Rect.hpp.

◆ ~Rect()

template<meta::is_arithmetic Type>
galaxy::Rect< Type >::~Rect ( )
inlinenoexcept

Destructor.

Definition at line 207 of file Rect.hpp.

Member Function Documentation

◆ contains() [1/2]

template<meta::is_arithmetic Type>
bool galaxy::Rect< Type >::contains ( const Type _x,
const Type _y ) const
inlinenodiscardnoexcept

Does the rectangle contain the point (x, y).

Parameters
_xX coordinate.
_yY coordinate.
Returns
True if contains the point.

Definition at line 212 of file Rect.hpp.

+ Here is the caller graph for this function:

◆ contains() [2/2]

template<meta::is_arithmetic Type>
bool galaxy::Rect< Type >::contains ( const Rect< Type > & b) const
inlinenodiscardnoexcept

Does the rectangle contain another rectangle.

Parameters
bRectangle to check.
Returns
Returns true if the rectangle is completely inside, not on the edge.

Definition at line 219 of file Rect.hpp.

+ Here is the call graph for this function:

◆ overlaps()

template<meta::is_arithmetic Type>
bool galaxy::Rect< Type >::overlaps ( const Rect< Type > & b)
inlinenodiscardnoexcept

Do the rectangles a and b overlap.

Parameters
bSecond rectangle to test.
Returns
Returns true if there is an overlap.

Definition at line 225 of file Rect.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ intersects()

template<meta::is_arithmetic Type>
bool galaxy::Rect< Type >::intersects ( const Rect< Type > & b) const
inlinenodiscardnoexcept

Do two rectangles intersect.

Parameters
bRectangle to test.
Returns
True if the rectangles intersect.

Definition at line 235 of file Rect.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_top_left()

template<meta::is_arithmetic Type>
void galaxy::Rect< Type >::set_top_left ( const glm::vec< 2, Type, glm::defaultp > & pos)
inlinenoexcept

Set the top-left position.

Parameters
pos{x, y} coordinate.

Definition at line 241 of file Rect.hpp.

+ Here is the caller graph for this function:

◆ get_right()

template<meta::is_arithmetic Type>
Type galaxy::Rect< Type >::get_right ( ) const
inlinenodiscardnoexcept

Get top right corner.

Returns
x + width.

Definition at line 248 of file Rect.hpp.

+ Here is the caller graph for this function:

◆ get_bottom()

template<meta::is_arithmetic Type>
Type galaxy::Rect< Type >::get_bottom ( ) const
inlinenodiscardnoexcept

Get bottom left corner.

Returns
y + height.

Definition at line 254 of file Rect.hpp.

+ Here is the caller graph for this function:

◆ get_top_left()

template<meta::is_arithmetic Type>
glm::vec< 2, Type, glm::defaultp > galaxy::Rect< Type >::get_top_left ( ) const
inlinenodiscardnoexcept

Get the upper-left coordinate.

Returns
{x, y}.

Definition at line 260 of file Rect.hpp.

+ Here is the caller graph for this function:

◆ get_center()

template<meta::is_arithmetic Type>
glm::vec< 2, Type, glm::defaultp > galaxy::Rect< Type >::get_center ( ) const
inlinenodiscardnoexcept

Gets the center of the rectangle.

Returns
Center point of rectangle.

Definition at line 266 of file Rect.hpp.

+ Here is the caller graph for this function:

◆ get_size()

template<meta::is_arithmetic Type>
glm::vec< 2, Type, glm::defaultp > galaxy::Rect< Type >::get_size ( ) const
inlinenodiscardnoexcept

Gets width and height of rectangle.

Returns
{width, height}.

Definition at line 272 of file Rect.hpp.

+ Here is the caller graph for this function:

◆ operator<=>()

template<meta::is_arithmetic Type>
auto galaxy::Rect< Type >::operator<=> ( const Rect< Type > & ) const
nodiscarddefaultnoexcept

Comparison operator.

◆ value_in_range()

template<meta::is_arithmetic Type>
bool galaxy::Rect< Type >::value_in_range ( const Type value,
const Type min,
const Type max )
inlinenodiscardprivatenoexcept

Private function to determine if value is in range. Inclusive. Credits: https://stackoverflow.com/a/306379.

Parameters
valueValue to check if in the min-max range.
minLower range.
maxUpper range.
Returns
True if value is inbetween min and max. Inclusive.

Definition at line 278 of file Rect.hpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ x

template<meta::is_arithmetic Type>
Type galaxy::Rect< Type >::x

X position.

Definition at line 146 of file Rect.hpp.

◆ y

template<meta::is_arithmetic Type>
Type galaxy::Rect< Type >::y

Y position.

Definition at line 151 of file Rect.hpp.

◆ width

template<meta::is_arithmetic Type>
Type galaxy::Rect< Type >::width

Width of rectangle.

Definition at line 156 of file Rect.hpp.

◆ height

template<meta::is_arithmetic Type>
Type galaxy::Rect< Type >::height

Height of rectangle.

Definition at line 161 of file Rect.hpp.


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