Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::Rect< T > Class Template Reference

Math class that represents an axis-aligned rectangle in two dimensions. More...

Public Member Functions

 Rect (T Width, T Height)
 Constructs a Rect object from its width and height. More...
 
 Rect (T X, T Y, T Width, T Height)
 Constructs a Rect object from its position, width and height. More...
 
 Rect (const T rect[4])
 Constructs a Rect object from an array of four elements. More...
 
 Rect (const Vector2< T > &lengths)
 Constructs a Rect object from a vector representing width and height. More...
 
 Rect (const Vector2< T > &vec1, const Vector2< T > &vec2)
 Constructs a Rect object from two vectors representing point of the space (X, Y) will be the components minimum of the two vectors and the width and height will be the components maximum - minimum. More...
 
template<typename U >
 Rect (const Rect< U > &rect)
 Constructs a Rect object from another type of Rect. More...
 
 Rect (const Rect &rect)=default
 
bool Contains (T X, T Y) const
 Tests whether the rectangle contains the provided point inclusive of the edge of the rectangle. More...
 
bool Contains (const Rect &rect) const
 Tests whether the rectangle contains the provided rectangle inclusive of the edge of the rectangle. More...
 
bool Contains (const Vector2< T > &point) const
 Tests whether the rectangle contains the provided point inclusive of the edge of the rectangle. More...
 
RectExtendTo (T X, T Y)
 Extends the rectangle to contain the point in the boundary. More...
 
RectExtendTo (const Rect &rect)
 Extends the rectangle to contain the rectangle. More...
 
RectExtendTo (const Vector2< T > &point)
 Extends the rectangle to contain the point in the boundary. More...
 
Vector2< T > GetCenter () const
 Gets a Vector2 for the center. More...
 
Vector2< T > GetCorner (RectCorner corner) const
 Gets the Vector2 for the corner. More...
 
Vector2< T > GetLengths () const
 Gets a Vector2 for the lengths. More...
 
Vector2< T > GetMaximum () const
 Gets a Vector2 for the maximum point. More...
 
Vector2< T > GetMinimum () const
 Gets a Vector2 for the minimum point. More...
 
Vector2< T > GetNegativeVertex (const Vector2< T > &normal) const
 Computes the negative vertex of one direction. More...
 
Vector2< T > GetPosition () const
 Gets a Vector2 for the position. More...
 
Vector2< T > GetPositiveVertex (const Vector2< T > &normal) const
 Computes the positive vertex of one direction. More...
 
bool Intersect (const Rect &rect, Rect *intersection=nullptr) const
 Checks whether or not this rectangle intersects another one. More...
 
bool IsValid () const
 Checks whether this rectangle is valid. More...
 
RectMakeZero ()
 Makes the rectangle position (0, 0) and lengths (0, 0) More...
 
RectSet (T Width, T Height)
 Sets the components of the rectangle with width and height. More...
 
RectSet (T X, T Y, T Width, T Height)
 Sets the components of the rectangle. More...
 
RectSet (const T rect[4])
 Sets the components of the rectangle from an array of four elements. More...
 
RectSet (const Rect< T > &rect)
 Sets the components of the rectangle with components from another. More...
 
RectSet (const Vector2< T > &lengths)
 Sets the components of the rectange from a vector representing width and height. More...
 
RectSet (const Vector2< T > &vec1, const Vector2< T > &vec2)
 Sets a Rect object from two vectors representing point of the space (X, Y) will be the components minimum of the two vectors and the width and height will be the components maximum - minimum. More...
 
template<typename U >
RectSet (const Rect< U > &rect)
 
String ToString () const
 Gives a string representation. More...
 
RectTranslate (const Vector2< T > &translation)
 Translates the rectangle. More...
 
T & operator[] (std::size_t i)
 Returns the ith element of the rectangle. More...
 
operator[] (std::size_t i) const
 Returns the ith element of the rectangle. More...
 
Rect operator* (T scalar) const
 Multiplies the lengths with the scalar. More...
 
Rect operator* (const Vector2< T > &vec) const
 Multiplies the lengths with the vector. More...
 
Rect operator/ (T scalar) const
 Divides the lengths with the scalar. More...
 
Rect operator/ (const Vector2< T > &vec) const
 Divides the lengths with the vector. More...
 
Rectoperator= (const Rect &other)=default
 
Rectoperator*= (T scalar)
 Multiplies the lengths of this rectangle with the scalar. More...
 
Rectoperator*= (const Vector2< T > &vec)
 Multiplies the lengths of this rectangle with the vector. More...
 
Rectoperator/= (T scalar)
 Divides the lengths of this rectangle with the scalar. More...
 
Rectoperator/= (const Vector2< T > &vec)
 Divives the lengths of this rectangle with the vector. More...
 
bool operator== (const Rect &rect) const
 Compares the rectangle to other one. More...
 
bool operator!= (const Rect &rect) const
 Compares the rectangle to other one. More...
 
template<typename U >
Rect< T > & Set (const Rect< U > &rect)
 Sets the components of the rectangle from another type of Rect. More...
 

Static Public Member Functions

static Rect Lerp (const Rect &from, const Rect &to, T interpolation)
 Interpolates the rectangle to other one with a factor of interpolation. More...
 
static Rect Zero ()
 Shorthand for the rectangle (0, 0, 0, 0) More...
 

Public Attributes

x
 
y
 
width
 
height
 

Detailed Description

template<typename T>
class Nz::Rect< T >

Math class that represents an axis-aligned rectangle in two dimensions.

Remarks
The basis is said to be "left-hand". It means that with your left hand, the thumb is X positive, the index finger Y positive pointing to the bottom

Constructor & Destructor Documentation

◆ Rect() [1/6]

template<typename T>
Nz::Rect< T >::Rect ( Width,
Height 
)

Constructs a Rect object from its width and height.

Parameters
WidthWidth of the rectangle (following X)
HeightHeight of the rectangle (following Y)
Remarks
Position will be (0, 0)

◆ Rect() [2/6]

template<typename T>
Nz::Rect< T >::Rect ( X,
Y,
Width,
Height 
)

Constructs a Rect object from its position, width and height.

Parameters
XX position
YY position
WidthWidth of the rectangle (following X)
HeightHeight of the rectangle (following Y)

◆ Rect() [3/6]

template<typename T>
Nz::Rect< T >::Rect ( const T  vec[4])

Constructs a Rect object from an array of four elements.

Parameters
vec[4]vec[0] is X position, vec[1] is Y position, vec[2] is width and vec[3] is height

◆ Rect() [4/6]

template<typename T>
Nz::Rect< T >::Rect ( const Vector2< T > &  lengths)

Constructs a Rect object from a vector representing width and height.

Parameters
lengths(Width, Height) of the rectangle
Remarks
X and Y will be (0, 0)

◆ Rect() [5/6]

template<typename T>
Nz::Rect< T >::Rect ( const Vector2< T > &  vec1,
const Vector2< T > &  vec2 
)

Constructs a Rect object from two vectors representing point of the space (X, Y) will be the components minimum of the two vectors and the width and height will be the components maximum - minimum.

Parameters
vec1First point
vec2Second point

◆ Rect() [6/6]

template<typename T >
template<typename U >
Nz::Rect< T >::Rect ( const Rect< U > &  rect)
explicit

Constructs a Rect object from another type of Rect.

Parameters
rectRect of type U to convert to type T

Member Function Documentation

◆ Contains() [1/3]

template<typename T>
bool Nz::Rect< T >::Contains ( X,
Y 
) const

Tests whether the rectangle contains the provided point inclusive of the edge of the rectangle.

Returns
true if inclusive
Parameters
XX position of the point
YY position of the point
See also
Contains

◆ Contains() [2/3]

template<typename T>
bool Nz::Rect< T >::Contains ( const Rect< T > &  rect) const

Tests whether the rectangle contains the provided rectangle inclusive of the edge of the rectangle.

Returns
true if inclusive
Parameters
rectOther rectangle to test
See also
Contains

◆ Contains() [3/3]

template<typename T>
bool Nz::Rect< T >::Contains ( const Vector2< T > &  point) const

Tests whether the rectangle contains the provided point inclusive of the edge of the rectangle.

Returns
true if inclusive
Parameters
pointPosition of the point
See also
Contains

◆ ExtendTo() [1/3]

template<typename T>
Rect< T > & Nz::Rect< T >::ExtendTo ( X,
Y 
)

Extends the rectangle to contain the point in the boundary.

Returns
A reference to this rectangle extended
Parameters
XX position of the point
YY position of the point
See also
ExtendTo

◆ ExtendTo() [2/3]

template<typename T>
Rect< T > & Nz::Rect< T >::ExtendTo ( const Rect< T > &  rect)

Extends the rectangle to contain the rectangle.

Returns
A reference to this rectangle extended
Parameters
rectOther rectangle to contain
See also
ExtendTo

◆ ExtendTo() [3/3]

template<typename T>
Rect< T > & Nz::Rect< T >::ExtendTo ( const Vector2< T > &  point)

Extends the rectangle to contain the point in the boundary.

Returns
A reference to this rectangle extended
Parameters
pointPosition of the point
See also
ExtendTo

◆ GetCenter()

template<typename T >
Vector2< T > Nz::Rect< T >::GetCenter ( ) const

Gets a Vector2 for the center.

Returns
The position of the center of the rectangle

◆ GetCorner()

template<typename T >
Vector2< T > Nz::Rect< T >::GetCorner ( RectCorner  corner) const

Gets the Vector2 for the corner.

Returns
The position of the corner of the rectangle according to enum RectCorner
Parameters
cornerEnumeration of type RectCorner
Remarks
If enumeration is not defined in RectCorner, a NazaraError is thrown and a Vector2 uninitialised is returned

◆ GetLengths()

template<typename T >
Vector2< T > Nz::Rect< T >::GetLengths ( ) const

Gets a Vector2 for the lengths.

Returns
The lengths of the rectangle (width, height)

◆ GetMaximum()

template<typename T >
Vector2< T > Nz::Rect< T >::GetMaximum ( ) const

Gets a Vector2 for the maximum point.

Returns
The RectCorner_RightBottom of the rectangle
See also
GetCorner

◆ GetMinimum()

template<typename T >
Vector2< T > Nz::Rect< T >::GetMinimum ( ) const

Gets a Vector2 for the minimum point.

Returns
The RectCorner_LeftTop of the rectangle
See also
GetCorner, GetPosition

◆ GetNegativeVertex()

template<typename T>
Vector2< T > Nz::Rect< T >::GetNegativeVertex ( const Vector2< T > &  normal) const

Computes the negative vertex of one direction.

Returns
The position of the vertex on the rectangle in the opposite way of the normal while considering the center. It means that if the normal has one component negative, the component is set to width or height corresponding to the sign
Parameters
normalVector indicating a direction
See also
GetPositiveVertex

◆ GetPosition()

template<typename T >
Vector2< T > Nz::Rect< T >::GetPosition ( ) const

Gets a Vector2 for the position.

Returns
The RectCorner_LeftTop of the rectangle
See also
GetCorner, GetMinimum

◆ GetPositiveVertex()

template<typename T>
Vector2< T > Nz::Rect< T >::GetPositiveVertex ( const Vector2< T > &  normal) const

Computes the positive vertex of one direction.

Returns
The position of the vertex on the rectangle in the same way of the normal while considering the center. It means that if the normal has one component positive, the component is set to width or height corresponding to the sign
Parameters
normalVector indicating a direction
See also
GetNegativeVertex

◆ Intersect()

template<typename T >
bool Nz::Rect< T >::Intersect ( const Rect< T > &  rect,
Rect< T > *  intersection = nullptr 
) const

Checks whether or not this rectangle intersects another one.

Returns
true if the rectangle intersects
Parameters
rectRectangle to check
intersectionOptional argument for the rectangle which represent the intersection

◆ IsValid()

template<typename T >
bool Nz::Rect< T >::IsValid ( ) const

Checks whether this rectangle is valid.

Returns
true if the rectangle has a strictly positive width and height

◆ Lerp()

template<typename T>
Rect< T > Nz::Rect< T >::Lerp ( const Rect< T > &  from,
const Rect< T > &  to,
interpolation 
)
static

Interpolates the rectangle to other one with a factor of interpolation.

Returns
A new rectangle which is the interpolation of two rectangles
Parameters
fromInitial rectangle
toTarget rectangle
interpolationFactor of interpolation
Remarks
interpolation is meant to be between 0 and 1, other values are potentially undefined behavior
With NAZARA_DEBUG, a NazaraError is thrown and Zero() is returned
See also
Lerp

◆ MakeZero()

template<typename T >
Rect< T > & Nz::Rect< T >::MakeZero ( )

Makes the rectangle position (0, 0) and lengths (0, 0)

Returns
A reference to this box with position (0, 0) and lengths (0, 0)
See also
Zero

◆ operator!=()

template<typename T >
bool Nz::Rect< T >::operator!= ( const Rect< T > &  rect) const

Compares the rectangle to other one.

Returns
false if the rectangles are the same
Parameters
rectOther rectangle to compare with

◆ operator*() [1/2]

template<typename T>
Rect< T > Nz::Rect< T >::operator* ( scalar) const

Multiplies the lengths with the scalar.

Returns
A rectangle where the position is the same and width and height are the product of the old width and height and the scalar
Parameters
scalarThe scalar to multiply width and height with

◆ operator*() [2/2]

template<typename T>
Rect< T > Nz::Rect< T >::operator* ( const Vector2< T > &  vec) const

Multiplies the lengths with the vector.

Returns
A rectangle where the position is the same and width and height are the product of the old width and height with the vec
Parameters
vecThe vector where component one multiply width and two height

◆ operator*=() [1/2]

template<typename T>
Rect< T > & Nz::Rect< T >::operator*= ( scalar)

Multiplies the lengths of this rectangle with the scalar.

Returns
A reference to this rectangle where lengths are the product of these lengths and the scalar
Parameters
scalarThe scalar to multiply width and height with

◆ operator*=() [2/2]

template<typename T>
Rect< T > & Nz::Rect< T >::operator*= ( const Vector2< T > &  vec)

Multiplies the lengths of this rectangle with the vector.

Returns
A reference to this rectangle where width and height are the product of the old width and height with the vec
Parameters
vecThe vector where component one multiply width and two height

◆ operator/() [1/2]

template<typename T>
Rect< T > Nz::Rect< T >::operator/ ( scalar) const

Divides the lengths with the scalar.

Returns
A rectangle where the position is the same and width and height are the quotient of the old width and height and the scalar
Parameters
scalarThe scalar to divide width and height with

◆ operator/() [2/2]

template<typename T>
Rect< T > Nz::Rect< T >::operator/ ( const Vector2< T > &  vec) const

Divides the lengths with the vector.

Returns
A rectangle where the position is the same and width and height are the quotient of the old width and height with the vec
Parameters
vecThe vector where component one divide width and two height

◆ operator/=() [1/2]

template<typename T>
Rect< T > & Nz::Rect< T >::operator/= ( scalar)

Divides the lengths of this rectangle with the scalar.

Returns
A reference to this rectangle where lengths are the quotient of these lengths and the scalar
Parameters
scalarThe scalar to divide width and height with

◆ operator/=() [2/2]

template<typename T>
Rect< T > & Nz::Rect< T >::operator/= ( const Vector2< T > &  vec)

Divives the lengths of this rectangle with the vector.

Returns
A reference to this rectangle where width and height are the quotient of the old width and height with the vec
Parameters
vecThe vector where component one divide width and two height

◆ operator==()

template<typename T >
bool Nz::Rect< T >::operator== ( const Rect< T > &  rect) const

Compares the rectangle to other one.

Returns
true if the rectangles are the same
Parameters
rectOther rectangle to compare with

◆ operator[]() [1/2]

template<typename T >
T & Nz::Rect< T >::operator[] ( std::size_t  i)

Returns the ith element of the rectangle.

Returns
A reference to the ith element of the rectangle
Remarks
Access to index greather than 4 is undefined behavior
Produce a NazaraError if you try to access to index greater than 4 with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and one of you try to acces to index greather than 4

◆ operator[]() [2/2]

template<typename T >
T Nz::Rect< T >::operator[] ( std::size_t  i) const

Returns the ith element of the rectangle.

Returns
A value to the ith element of the rectangle
Remarks
Access to index greater than 4 is undefined behavior
Produce a NazaraError if you try to access to index greater than 4 with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and one of you try to acces to index greather than 4

◆ Set() [1/7]

template<typename T>
Rect< T > & Nz::Rect< T >::Set ( Width,
Height 
)

Sets the components of the rectangle with width and height.

Returns
A reference to this rectangle
Parameters
WidthWidth of the rectangle (following X)
HeightHeight of the rectangle (following Y)
Remarks
Position will be (0, 0)

◆ Set() [2/7]

template<typename T>
Rect< T > & Nz::Rect< T >::Set ( X,
Y,
Width,
Height 
)

Sets the components of the rectangle.

Returns
A reference to this rectangle
Parameters
XX position
YY position
WidthWidth of the rectangle (following X)
HeightHeight of the rectangle (following Y)

◆ Set() [3/7]

template<typename T>
Rect< T > & Nz::Rect< T >::Set ( const T  rect[4])

Sets the components of the rectangle from an array of four elements.

Returns
A reference to this rectangle
Parameters
rect[4]rect[0] is X position, rect[1] is Y position, rect[2] is width and rect[3] is height

◆ Set() [4/7]

template<typename T>
Rect< T > & Nz::Rect< T >::Set ( const Rect< T > &  rect)

Sets the components of the rectangle with components from another.

Returns
A reference to this rectangle
Parameters
rectThe other Rect

◆ Set() [5/7]

template<typename T>
Rect< T > & Nz::Rect< T >::Set ( const Vector2< T > &  lengths)

Sets the components of the rectange from a vector representing width and height.

Returns
A reference to this rectangle
Parameters
lengths(Width, Height) of the rectangle
Remarks
Position will be (0, 0)

◆ Set() [6/7]

template<typename T>
Rect< T > & Nz::Rect< T >::Set ( const Vector2< T > &  vec1,
const Vector2< T > &  vec2 
)

Sets a Rect object from two vectors representing point of the space (X, Y) will be the components minimum of the two vectors and the width and height will be the components maximum - minimum.

Returns
A reference to this rectangle
Parameters
vec1First point
vec2Second point

◆ Set() [7/7]

template<typename T>
template<typename U >
Rect<T>& Nz::Rect< T >::Set ( const Rect< U > &  rect)

Sets the components of the rectangle from another type of Rect.

Returns
A reference to this rectangle
Parameters
rectRectangle of type U to convert its components

◆ ToString()

template<typename T >
String Nz::Rect< T >::ToString ( ) const

Gives a string representation.

Returns
A string representation of the object: "Rect(x, y, width, height)"

◆ Translate()

template<typename T>
Rect< T > & Nz::Rect< T >::Translate ( const Vector2< T > &  translation)

Translates the rectangle.

Returns
A reference to this rectangle translated
Parameters
translationVector2 which is the translation for the position

◆ Zero()

template<typename T >
Rect< T > Nz::Rect< T >::Zero ( )
static

Shorthand for the rectangle (0, 0, 0, 0)

Returns
A rectangle with position (0, 0) and lengths (0, 0)
See also
MakeZero

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