Public Member Functions | Public Attributes | Related Functions | List of all members
ime::Rect< T > Class Template Reference

Class for manipulating 2D axis aligned rectangles. More...

#include <Rect.h>

Public Member Functions

 Rect ()
 Default constructor. More...
 
 Rect (T rectLeft, T rectTop, T rectWidth, T rectHeight)
 Construct the rectangle from its coordinates. More...
 
 Rect (const Vector2< T > &position, const Vector2< T > &size)
 Construct the rectangle from position and size. More...
 
template<typename U >
 Rect (const Rect< U > &rectangle)
 Construct the rectangle from another type of rectangle. More...
 
bool contains (T x, T y) const
 Check if a point is inside the rectangle's area. More...
 
bool contains (const Vector2< T > &point) const
 Check if a point is inside the rectangle's area. More...
 
bool intersects (const Rect< T > &other) const
 Check the intersection between two rectangles. More...
 
bool intersects (const Rect< T > &rectangle, Rect< T > &intersection) const
 Check the intersection between two rectangles. More...
 
Vector2< T > getPosition () const
 Get the position of the rectangle's top-left corner. More...
 
Vector2< T > getSize () const
 Get the size of the rectangle. More...
 

Public Attributes

left
 Left coordinate of the rectangle. More...
 
top
 Top coordinate of the rectangle. More...
 
width
 Width of the rectangle. More...
 
height
 Height of the rectangle. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
bool operator== (const Rect< T > &left, const Rect< T > &right)
 Overload of binary operator ==. More...
 
template<typename T >
bool operator!= (const Rect< T > &left, const Rect< T > &right)
 Overload of binary operator !=. More...
 

Detailed Description

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

Class for manipulating 2D axis aligned rectangles.

Definition at line 36 of file Rect.h.

Constructor & Destructor Documentation

◆ Rect() [1/4]

template<typename T >
ime::Rect< T >::Rect ( )

Default constructor.

Creates an empty rectangle (it is equivalent to calling Rect(0, 0, 0, 0))

◆ Rect() [2/4]

template<typename T >
ime::Rect< T >::Rect ( rectLeft,
rectTop,
rectWidth,
rectHeight 
)

Construct the rectangle from its coordinates.

Parameters
rectLeftLeft coordinate of the rectangle
rectTopTop coordinate of the rectangle
rectWidthWidth of the rectangle
rectHeightHeight of the rectangle
Note
the last two parameters are the width and height, not the right and bottom coordinates!

◆ Rect() [3/4]

template<typename T >
ime::Rect< T >::Rect ( const Vector2< T > &  position,
const Vector2< T > &  size 
)

Construct the rectangle from position and size.

Parameters
positionPosition of the top-left corner of the rectangle
sizeSize of the rectangle
Note
The last parameter is the size, not the bottom-right corner!

◆ Rect() [4/4]

template<typename T >
template<typename U >
ime::Rect< T >::Rect ( const Rect< U > &  rectangle)
explicit

Construct the rectangle from another type of rectangle.

Parameters
rectangleRectangle to convert

This constructor doesn't replace the copy constructor, it's called only when U != T. A call to this constructor will fail to compile if U is not convertible to T

Member Function Documentation

◆ contains() [1/2]

template<typename T >
bool ime::Rect< T >::contains ( const Vector2< T > &  point) const

Check if a point is inside the rectangle's area.

Parameters
pointPoint to test
Returns
True if the point is inside, false otherwise

This check is non-inclusive. If the point lies on the edge of the rectangle, this function will return false.

See also
intersects

◆ contains() [2/2]

template<typename T >
bool ime::Rect< T >::contains ( x,
y 
) const

Check if a point is inside the rectangle's area.

Parameters
xX coordinate of the point to test
yY coordinate of the point to test
Returns
True if the point is inside, false otherwise

This check is non-inclusive. If the point lies on the edge of the rectangle, this function will return false.

See also
intersect

◆ getPosition()

template<typename T >
Vector2< T > ime::Rect< T >::getPosition ( ) const

Get the position of the rectangle's top-left corner.

Returns
Position of rectangle
See also
getSize

◆ getSize()

template<typename T >
Vector2< T > ime::Rect< T >::getSize ( ) const

Get the size of the rectangle.

Returns
Size of rectangle
See also
getPosition

◆ intersects() [1/2]

template<typename T >
bool ime::Rect< T >::intersects ( const Rect< T > &  other) const

Check the intersection between two rectangles.

Parameters
otherRectangle to test
Returns
True if rectangles overlap, false otherwise
See also
contains

◆ intersects() [2/2]

template<typename T >
bool ime::Rect< T >::intersects ( const Rect< T > &  rectangle,
Rect< T > &  intersection 
) const

Check the intersection between two rectangles.

Parameters
rectangleRectangle to test
intersectionRectangle to be filled with the intersection
Returns
True if rectangles overlap, false otherwise

This overload returns the overlapped rectangle in the intersection parameter

See also
contains

Friends And Related Function Documentation

◆ operator!=()

template<typename T >
bool operator!= ( const Rect< T > &  left,
const Rect< T > &  right 
)
related

Overload of binary operator !=.

Parameters
leftLeft operand (a rectangle)
rightRight operand (a rectangle)
Returns
True if left is not equal to right

This operator compares strict difference between two rectangles Create most common types

◆ operator==()

template<typename T >
bool operator== ( const Rect< T > &  left,
const Rect< T > &  right 
)
related

Overload of binary operator ==.

Parameters
leftLeft operand (a rectangle)
rightRight operand (a rectangle)
Returns
True if left is equal to right

This operator compares strict equality between two rectangles

Member Data Documentation

◆ height

template<typename T >
T ime::Rect< T >::height

Height of the rectangle.

Definition at line 145 of file Rect.h.

◆ left

template<typename T >
T ime::Rect< T >::left

Left coordinate of the rectangle.

Definition at line 142 of file Rect.h.

◆ top

template<typename T >
T ime::Rect< T >::top

Top coordinate of the rectangle.

Definition at line 143 of file Rect.h.

◆ width

template<typename T >
T ime::Rect< T >::width

Width of the rectangle.

Definition at line 144 of file Rect.h.


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