GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::Rectangle< T > Struct Template Reference

Flat 2D axis-aligned rectangle shape with a position and size. More...

#include <GREM/core/geometry.hpp>

Public Types

using Component = T
 Scalar coordinate component type.

Public Member Functions

template<typename U>
GREM_ALWAYS_INLINE constexpr operator Rectangle< U > () const noexcept
 Convert this rectangle to an equivalent rectangle of another scalar type.
constexpr operator Box< 2, T > () const noexcept
 Convert this rectangle to an equivalent 2D axis-aligned box.
bool operator== (const Rectangle &other) const =default
 Compare this rectangle to another for equality.
constexpr bool contains (const Point< 2, T > &point) const noexcept
 Check if a given point is contained within the extents of this rectangle.
constexpr bool intersects (const Ray< 2, T > &ray) const noexcept
 Check if this rectangle intersects a given ray.
constexpr RaycastResult< 2, T > raycast (const Ray< 2, T > &ray) const noexcept
 Find the closest intersection of this rectangle with a given ray.
constexpr Box< 2, T > getBoundingBox () const noexcept
 Get the axis-aligned bounding box of the rectangle.
constexpr Box< 2, T > toBox () const noexcept
 Convert this shape to an equivalent axis-aligned bounding box.

Public Attributes

Point< 2, T > position
 Position of the bottom left corner of the rectangle.
Length< 2, T > size
 Width and height of the rectangle.

Static Public Attributes

static constexpr size_t RANK = 2
 Number of dimensions of the vector space.

Detailed Description

template<typename T>
struct grem::Rectangle< T >

Flat 2D axis-aligned rectangle shape with a position and size.

Template Parameters
Tscalar coordinate component type.

Member Typedef Documentation

◆ Component

template<typename T>
using grem::Rectangle< T >::Component = T

Scalar coordinate component type.

Member Function Documentation

◆ operator Rectangle< U >()

template<typename T>
template<typename U>
GREM_ALWAYS_INLINE constexpr grem::Rectangle< T >::operator Rectangle< U > ( ) const
inlineexplicitconstexprnoexcept

Convert this rectangle to an equivalent rectangle of another scalar type.

Returns
the converted rectangle.

◆ operator Box< 2, T >()

template<typename T>
grem::Rectangle< T >::operator Box< 2, T > ( ) const
inlineconstexprnoexcept

Convert this rectangle to an equivalent 2D axis-aligned box.

Returns
the rectangle as an axis-aligned box.

◆ operator==()

template<typename T>
bool grem::Rectangle< T >::operator== ( const Rectangle< T > & other) const
nodiscarddefault

Compare this rectangle to another for equality.

Parameters
otherthe rectangle to compare this rectangle to.
Returns
true if the rectangles are equal, false otherwise.

◆ contains()

template<typename T>
bool grem::Rectangle< T >::contains ( const Point< 2, T > & point) const
inlinenodiscardconstexprnoexcept

Check if a given point is contained within the extents of this rectangle.

Parameters
pointpoint to check.
Returns
true if the rectangle contains the given point, false otherwise.

◆ intersects()

template<typename T>
bool grem::Rectangle< T >::intersects ( const Ray< 2, T > & ray) const
inlinenodiscardconstexprnoexcept

Check if this rectangle intersects a given ray.

Parameters
rayray to check.
Returns
true if an intersection was found, false otherwise.

◆ raycast()

template<typename T>
RaycastResult< 2, T > grem::Rectangle< T >::raycast ( const Ray< 2, T > & ray) const
inlinenodiscardconstexprnoexcept

Find the closest intersection of this rectangle with a given ray.

Parameters
rayray to check.
Returns
the result of the raycast.

◆ getBoundingBox()

template<typename T>
Box< 2, T > grem::Rectangle< T >::getBoundingBox ( ) const
inlinenodiscardconstexprnoexcept

Get the axis-aligned bounding box of the rectangle.

Returns
an axis-aligned box that contains the entire rectangle.

◆ toBox()

template<typename T>
Box< 2, T > grem::Rectangle< T >::toBox ( ) const
inlinenodiscardconstexprnoexcept

Convert this shape to an equivalent axis-aligned bounding box.

Returns
an axis-aligned box that is equivalent to this shape.

Member Data Documentation

◆ RANK

template<typename T>
size_t grem::Rectangle< T >::RANK = 2
staticconstexpr

Number of dimensions of the vector space.

◆ position

template<typename T>
Point<2, T> grem::Rectangle< T >::position

Position of the bottom left corner of the rectangle.

◆ size

template<typename T>
Length<2, T> grem::Rectangle< T >::size

Width and height of the rectangle.


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