CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Math::TRect2< T > Struct Template Reference

Represents a 2D rectangle using real values. More...

#include <CeresEngine/Math/Rect.hpp>

Public Member Functions

 TRect2 ()=default
 
 TRect2 (const TPoint2< T > &origin, const TSize2< T > &size)
 
 TRect2 (const TPoint2< T > &center, const TRect2Edge< T > &edge)
 
 TRect2 (T x, T y, T width, T height)
 
bool contains (const TPoint2< T > &point) const
 Returns true if the rectangle contains the provided point.
 
bool contains (const TRect2< T > &rect) const
 
bool overlaps (const TRect2 &other) const
 Returns true if the rectangle overlaps the provided rectangle.
 
void encapsulate (const TRect2 &other)
 Extends this rectangle so that the provided rectangle is completely contained within it.
 
void clip (const TRect2 &clipRect)
 Clips current rectangle so that it does not overlap the provided rectangle.
 
TRect2 intersection (const TRect2 &other) const
 
bool fullyContained (const TRect2 &other) const
 
TRect2 inset (const TRect2Edge< T > &insets) const
 
TRect2 inset (T value) const
 
TRect2 outset (const TRect2Edge< T > &insets) const
 
TRect2 outset (T value) const
 
void transform (const TMatrix4< T > &matrix)
 Transforms the bounds by the given matrix.
 
void transform (const TMatrix3< T > &matrix)
 Transforms the bounds by the given matrix.
 
TPoint2< T > getCenter () const
 Center of the rectangle.
 
TSize2< T > getHalfSize () const
 Extents of the rectangle (distance from center to one of the corners)
 
TPoint2< T > getTopLeft () const
 
void setTopLeft (const TPoint2< T > &topLeft)
 
TPoint2< T > getTopRight () const
 
void setTopRight (const TPoint2< T > &topRight)
 
TPoint2< T > getBottomLeft () const
 
void setBottomLeft (const TPoint2< T > &bottomLeft)
 
TPoint2< T > getBottomRight () const
 
void setBottomRight (const TPoint2< T > &bottomRight)
 

Static Public Member Functions

static TRect2 fromCenterAndSize (const TPoint2< T > &center, const TSize2< T > &size)
 Creates a new 2D rect by passing the center and it's size.
 
static TRect2 fromCenterAndSize (const TPoint2< T > &center, T size)
 Creates a new 2D rect by passing the center and it's size.
 
static Vector< TRect2getIntersectionGroups (const Vector< TRect2 > &rects)
 Computes a set of non-intersecting rects that enclose all given rects.
 

Public Attributes

TPoint2< T > origin = TPoint2<T>(0.0, 0.0)
 
TSize2< T > size = TSize2<T>(0.0, 0.0)
 

Friends

bool operator== (const TRect2 &lhs, const TRect2 &rhs)
 
bool operator!= (const TRect2 &lhs, const TRect2 &rhs)
 
template<std::size_t I>
T & get (TRect2 &rect) noexcept
 Gets a value from the rectangle.
 
template<std::size_t I>
const T & get (const TRect2 &rect) noexcept
 Gets a value from the rectangle.
 

Detailed Description

template<typename T>
struct Math::TRect2< T >

Represents a 2D rectangle using real values.

Rectangle is represented with an origin in top left and width/height.

Constructor & Destructor Documentation

◆ TRect2() [1/4]

template<typename T >
Math::TRect2< T >::TRect2 ( )
default

◆ TRect2() [2/4]

template<typename T >
Math::TRect2< T >::TRect2 ( const TPoint2< T > &  origin,
const TSize2< T > &  size 
)
inline

◆ TRect2() [3/4]

template<typename T >
Math::TRect2< T >::TRect2 ( const TPoint2< T > &  center,
const TRect2Edge< T > &  edge 
)

◆ TRect2() [4/4]

template<typename T >
Math::TRect2< T >::TRect2 ( x,
y,
width,
height 
)
inline

Member Function Documentation

◆ clip()

template<typename T >
void Math::TRect2< T >::clip ( const TRect2< T > &  clipRect)

Clips current rectangle so that it does not overlap the provided rectangle.

◆ contains() [1/2]

template<typename T >
bool Math::TRect2< T >::contains ( const TPoint2< T > &  point) const

Returns true if the rectangle contains the provided point.

◆ contains() [2/2]

template<typename T >
bool Math::TRect2< T >::contains ( const TRect2< T > &  rect) const

◆ encapsulate()

template<typename T >
void Math::TRect2< T >::encapsulate ( const TRect2< T > &  other)

Extends this rectangle so that the provided rectangle is completely contained within it.

◆ fromCenterAndSize() [1/2]

template<typename T >
static TRect2 Math::TRect2< T >::fromCenterAndSize ( const TPoint2< T > &  center,
const TSize2< T > &  size 
)
inlinestatic

Creates a new 2D rect by passing the center and it's size.

◆ fromCenterAndSize() [2/2]

template<typename T >
static TRect2 Math::TRect2< T >::fromCenterAndSize ( const TPoint2< T > &  center,
size 
)
inlinestatic

Creates a new 2D rect by passing the center and it's size.

◆ fullyContained()

template<typename T >
bool Math::TRect2< T >::fullyContained ( const TRect2< T > &  other) const

◆ getBottomLeft()

template<typename T >
TPoint2< T > Math::TRect2< T >::getBottomLeft ( ) const
inline

◆ getBottomRight()

template<typename T >
TPoint2< T > Math::TRect2< T >::getBottomRight ( ) const
inline

◆ getCenter()

template<typename T >
TPoint2< T > Math::TRect2< T >::getCenter ( ) const

Center of the rectangle.

◆ getHalfSize()

template<typename T >
TSize2< T > Math::TRect2< T >::getHalfSize ( ) const

Extents of the rectangle (distance from center to one of the corners)

◆ getIntersectionGroups()

template<typename T >
static Vector< TRect2 > Math::TRect2< T >::getIntersectionGroups ( const Vector< TRect2< T > > &  rects)
static

Computes a set of non-intersecting rects that enclose all given rects.

Parameters
rectsThe rectangles to compute the smaller non-intersecting rectangle set.
Returns
A set of rectangle groups that separates non-intersecting groups.

◆ getTopLeft()

template<typename T >
TPoint2< T > Math::TRect2< T >::getTopLeft ( ) const
inline

◆ getTopRight()

template<typename T >
TPoint2< T > Math::TRect2< T >::getTopRight ( ) const
inline

◆ inset() [1/2]

template<typename T >
TRect2 Math::TRect2< T >::inset ( const TRect2Edge< T > &  insets) const

◆ inset() [2/2]

template<typename T >
TRect2 Math::TRect2< T >::inset ( value) const
inline

◆ intersection()

template<typename T >
TRect2 Math::TRect2< T >::intersection ( const TRect2< T > &  other) const

◆ outset() [1/2]

template<typename T >
TRect2 Math::TRect2< T >::outset ( const TRect2Edge< T > &  insets) const

◆ outset() [2/2]

template<typename T >
TRect2 Math::TRect2< T >::outset ( value) const
inline

◆ overlaps()

template<typename T >
bool Math::TRect2< T >::overlaps ( const TRect2< T > &  other) const

Returns true if the rectangle overlaps the provided rectangle.

Also returns true if the rectangles are contained within each other completely (no intersecting edges).

◆ setBottomLeft()

template<typename T >
void Math::TRect2< T >::setBottomLeft ( const TPoint2< T > &  bottomLeft)
inline

◆ setBottomRight()

template<typename T >
void Math::TRect2< T >::setBottomRight ( const TPoint2< T > &  bottomRight)
inline

◆ setTopLeft()

template<typename T >
void Math::TRect2< T >::setTopLeft ( const TPoint2< T > &  topLeft)
inline

◆ setTopRight()

template<typename T >
void Math::TRect2< T >::setTopRight ( const TPoint2< T > &  topRight)
inline

◆ transform() [1/2]

template<typename T >
void Math::TRect2< T >::transform ( const TMatrix3< T > &  matrix)

Transforms the bounds by the given matrix.

Resulting value is an axis aligned rectangle encompassing the transformed points.

Note
Since the resulting value is an AA rectangle of the original transformed rectangle, the bounds will be larger than needed. Oriented rectangle would provide a much tighter fit.

◆ transform() [2/2]

template<typename T >
void Math::TRect2< T >::transform ( const TMatrix4< T > &  matrix)

Transforms the bounds by the given matrix.

Resulting value is an axis aligned rectangle encompassing the transformed points.

Note
Since the resulting value is an AA rectangle of the original transformed rectangle, the bounds will be larger than needed. Oriented rectangle would provide a much tighter fit.

Friends And Related Symbol Documentation

◆ get [1/2]

template<typename T >
template<std::size_t I>
const T & get ( const TRect2< T > &  rect)
friend

Gets a value from the rectangle.

Template Parameters
IThe parameter index to fetched from the rect.
Parameters
rectThe rect to fetch the I-th parameter from.
Returns
The I-th parameter from rect.

◆ get [2/2]

template<typename T >
template<std::size_t I>
T & get ( TRect2< T > &  rect)
friend

Gets a value from the rectangle.

Template Parameters
IThe parameter index to fetched from the rect.
Parameters
rectThe rect to fetch the I-th parameter from.
Returns
The I-th parameter from rect.

◆ operator!=

template<typename T >
bool operator!= ( const TRect2< T > &  lhs,
const TRect2< T > &  rhs 
)
friend

◆ operator==

template<typename T >
bool operator== ( const TRect2< T > &  lhs,
const TRect2< T > &  rhs 
)
friend

Member Data Documentation

◆ origin

template<typename T >
TPoint2<T> Math::TRect2< T >::origin = TPoint2<T>(0.0, 0.0)

◆ size

template<typename T >
TSize2<T> Math::TRect2< T >::size = TSize2<T>(0.0, 0.0)

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