Saga3D API Documentation  1.0-RC4
saga::core::rect< T > Class Template Reference

Rectangle template. More...

#include <rect.h>

Public Member Functions

 rect ()
 Default constructor creating empty rectangle at (0,0) More...
 
 rect (T x, T y, T x2, T y2)
 Constructor with two corners. More...
 
 rect (const glm::vec2 &upperLeft, const glm::vec2 &lowerRight)
 Constructor with two corners. More...
 
template<class U >
 rect (const glm::vec2 &pos, const glm::vec2 &size)
 Constructor with upper left corner and dimension. More...
 
template<class U >
 rect (const glm::vec2 &size)
 Constructor with upper left at 0,0 and lower right using dimension. More...
 
rect< T > operator+ (const glm::vec2 &pos) const
 move right by given numbers More...
 
rect< T > & operator+= (const glm::vec2 &pos)
 move right by given numbers More...
 
rect< T > operator- (const glm::vec2 &pos) const
 move left by given numbers More...
 
rect< T > & operator-= (const glm::vec2 &pos)
 move left by given numbers More...
 
bool operator== (const rect< T > &other) const
 equality operator More...
 
bool operator!= (const rect< T > &other) const
 inequality operator More...
 
bool operator< (const rect< T > &other) const
 compares size of rectangles More...
 
getArea () const
 Returns size of rectangle. More...
 
bool isPointInside (const glm::vec2 &pos) const
 Returns if a 2d point is within this rectangle. More...
 
bool isRectCollided (const rect< T > &other) const
 Check if the rectangle collides with another rectangle. More...
 
void clipAgainst (const rect< T > &other)
 Clips this rectangle with another one. More...
 
bool constrainTo (const rect< T > &other)
 Moves this rectangle to fit inside another one. More...
 
getWidth () const
 Get width of rectangle. More...
 
getHeight () const
 Get height of rectangle. More...
 
void repair ()
 If the lower right corner of the rect is smaller then the upper left, the points are swapped. More...
 
bool isValid () const
 Returns if the rect is valid to draw. More...
 
glm::vec2 getCenter () const
 Get the center of the rectangle. More...
 
glm::vec2 getSize () const
 Get the dimensions of the rectangle. More...
 
void addInternalPoint (const glm::vec2 &p)
 Adds a point to the rectangle. More...
 
void addInternalPoint (T x, T y)
 Adds a point to the bounding rectangle. More...
 

Public Attributes

glm::vec2 UpperLeftCorner
 Upper left corner. More...
 
glm::vec2 LowerRightCorner
 Lower right corner. More...
 

Detailed Description

template<class T>
class saga::core::rect< T >

Rectangle template.

Mostly used by 2D GUI elements and for 2D drawing methods. It has 2 positions instead of position and dimension and a fast method for collision detection with other rectangles and points.

Coordinates are (0,0) for top-left corner, and increasing to the right and to the bottom.

Definition at line 24 of file rect.h.

Constructor & Destructor Documentation

◆ rect() [1/5]

template<class T >
saga::core::rect< T >::rect ( )
inline

Default constructor creating empty rectangle at (0,0)

Definition at line 29 of file rect.h.

◆ rect() [2/5]

template<class T >
saga::core::rect< T >::rect ( x,
y,
x2,
y2 
)
inline

Constructor with two corners.

Definition at line 32 of file rect.h.

◆ rect() [3/5]

template<class T >
saga::core::rect< T >::rect ( const glm::vec2 &  upperLeft,
const glm::vec2 &  lowerRight 
)
inline

Constructor with two corners.

Definition at line 36 of file rect.h.

◆ rect() [4/5]

template<class T >
template<class U >
saga::core::rect< T >::rect ( const glm::vec2 &  pos,
const glm::vec2 &  size 
)
inline

Constructor with upper left corner and dimension.

Definition at line 41 of file rect.h.

◆ rect() [5/5]

template<class T >
template<class U >
saga::core::rect< T >::rect ( const glm::vec2 &  size)
inlineexplicit

Constructor with upper left at 0,0 and lower right using dimension.

Definition at line 46 of file rect.h.

Member Function Documentation

◆ addInternalPoint() [1/2]

template<class T >
void saga::core::rect< T >::addInternalPoint ( const glm::vec2 &  p)
inline

Adds a point to the rectangle.

Causes the rectangle to grow bigger if point is outside of the box

Parameters
pPoint to add to the box.

Definition at line 244 of file rect.h.

◆ addInternalPoint() [2/2]

template<class T >
void saga::core::rect< T >::addInternalPoint ( x,
y 
)
inline

Adds a point to the bounding rectangle.

Causes the rectangle to grow bigger if point is outside of the box

Parameters
xX-Coordinate of the point to add to this box.
yY-Coordinate of the point to add to this box.

Definition at line 254 of file rect.h.

◆ clipAgainst()

template<class T >
void saga::core::rect< T >::clipAgainst ( const rect< T > &  other)
inline

Clips this rectangle with another one.

Parameters
otherRectangle to clip with

Definition at line 129 of file rect.h.

◆ constrainTo()

template<class T >
bool saga::core::rect< T >::constrainTo ( const rect< T > &  other)
inline

Moves this rectangle to fit inside another one.

Returns
True on success, false if not possible

Definition at line 150 of file rect.h.

◆ getArea()

template<class T >
T saga::core::rect< T >::getArea ( ) const
inline

Returns size of rectangle.

Definition at line 100 of file rect.h.

◆ getCenter()

template<class T >
glm::vec2 saga::core::rect< T >::getCenter ( ) const
inline

Get the center of the rectangle.

Definition at line 226 of file rect.h.

◆ getHeight()

template<class T >
T saga::core::rect< T >::getHeight ( ) const
inline

Get height of rectangle.

Definition at line 193 of file rect.h.

◆ getSize()

template<class T >
glm::vec2 saga::core::rect< T >::getSize ( ) const
inline

Get the dimensions of the rectangle.

Definition at line 234 of file rect.h.

◆ getWidth()

template<class T >
T saga::core::rect< T >::getWidth ( ) const
inline

Get width of rectangle.

Definition at line 187 of file rect.h.

◆ isPointInside()

template<class T >
bool saga::core::rect< T >::isPointInside ( const glm::vec2 &  pos) const
inline

Returns if a 2d point is within this rectangle.

Parameters
posPosition to test if it lies within this rectangle.
Returns
True if the position is within the rectangle, false if not.

Definition at line 108 of file rect.h.

◆ isRectCollided()

template<class T >
bool saga::core::rect< T >::isRectCollided ( const rect< T > &  other) const
inline

Check if the rectangle collides with another rectangle.

Parameters
otherRectangle to test collision with
Returns
True if the rectangles collide.

Definition at line 119 of file rect.h.

◆ isValid()

template<class T >
bool saga::core::rect< T >::isValid ( ) const
inline

Returns if the rect is valid to draw.

It would be invalid if the UpperLeftCorner is lower or more right than the LowerRightCorner.

Definition at line 219 of file rect.h.

◆ operator!=()

template<class T >
bool saga::core::rect< T >::operator!= ( const rect< T > &  other) const
inline

inequality operator

Definition at line 87 of file rect.h.

◆ operator+()

template<class T >
rect<T> saga::core::rect< T >::operator+ ( const glm::vec2 &  pos) const
inline

move right by given numbers

Definition at line 50 of file rect.h.

◆ operator+=()

template<class T >
rect<T>& saga::core::rect< T >::operator+= ( const glm::vec2 &  pos)
inline

move right by given numbers

Definition at line 57 of file rect.h.

◆ operator-()

template<class T >
rect<T> saga::core::rect< T >::operator- ( const glm::vec2 &  pos) const
inline

move left by given numbers

Definition at line 65 of file rect.h.

◆ operator-=()

template<class T >
rect<T>& saga::core::rect< T >::operator-= ( const glm::vec2 &  pos)
inline

move left by given numbers

Definition at line 72 of file rect.h.

◆ operator<()

template<class T >
bool saga::core::rect< T >::operator< ( const rect< T > &  other) const
inline

compares size of rectangles

Definition at line 94 of file rect.h.

◆ operator==()

template<class T >
bool saga::core::rect< T >::operator== ( const rect< T > &  other) const
inline

equality operator

Definition at line 80 of file rect.h.

◆ repair()

template<class T >
void saga::core::rect< T >::repair ( )
inline

If the lower right corner of the rect is smaller then the upper left, the points are swapped.

Definition at line 199 of file rect.h.

Member Data Documentation

◆ LowerRightCorner

template<class T >
glm::vec2 saga::core::rect< T >::LowerRightCorner

Lower right corner.

Definition at line 270 of file rect.h.

◆ UpperLeftCorner

template<class T >
glm::vec2 saga::core::rect< T >::UpperLeftCorner

Upper left corner.

Definition at line 268 of file rect.h.


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