Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials

# irr::core::rect< T > Class Template Reference

Rectangle template. More...

`#include <rect.h>`

List of all members.

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

## Detailed Description

### template<class T>
class irr::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 26 of file rect.h.

## Constructor & Destructor Documentation

template<class T>

irr::core::rect< T >::rect | ( |  | ) | `[inline]`

Default constructor creating empty rectangle at (0,0).

Definition at line 31 of file rect.h.

template<class T>

irr::core::rect< T >::rect | ( | T | x,
|  | T | y,
|  | T | x2,
|  | T | y2 |
| ) |  |  | `[inline]`

Constructor with two corners.

Definition at line 34 of file rect.h.

template<class T>

irr::core::rect< T >::rect | ( | const position2d< T > & | upperLeft,
|  | const position2d< T > & | lowerRight |
| ) |  |  | `[inline]`

Constructor with two corners.

Definition at line 38 of file rect.h.

template<class T>
template<class U>

irr::core::rect< T >::rect | ( | const position2d< T > & | pos,
|  | const dimension2d< U > & | size |
| ) |  |  | `[inline]`

Constructor with upper left corner and dimension.

Definition at line 43 of file rect.h.

## Member Function Documentation

template<class T>

void irr::core::rect< T >::addInternalPoint | ( | T | x,
|  | T | y |
| ) |  |  | `[inline]`

Adds a point to the bounding rectangle.

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

Parameters:

  | x | X-Coordinate of the point to add to this box.
  | y | Y-Coordinate of the point to add to this box.

Definition at line 251 of file rect.h.

template<class T>

void irr::core::rect< T >::addInternalPoint | ( | const position2d< T > & | p | ) | `[inline]`

Adds a point to the rectangle.

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

Parameters:

  | p | Point to add to the box.

Definition at line 241 of file rect.h.

Referenced by irr::core::rect< float >::addInternalPoint().

template<class T>

void irr::core::rect< T >::clipAgainst | ( | const rect< T > & | other | ) | `[inline]`

Clips this rectangle with another one.

Parameters:

  | other | Rectangle to clip with

Definition at line 126 of file rect.h.

template<class T>

bool irr::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 147 of file rect.h.

template<class T>

T irr::core::rect< T >::getArea | ( |  | ) | const`[inline]`

Returns size of rectangle.

Definition at line 97 of file rect.h.

Referenced by irr::core::rect< float >::operator<().

template<class T>

position2d<T> irr::core::rect< T >::getCenter | ( |  | ) | const`[inline]`

Get the center of the rectangle.

Definition at line 223 of file rect.h.

template<class T>

T irr::core::rect< T >::getHeight | ( |  | ) | const`[inline]`

Get height of rectangle.

Definition at line 190 of file rect.h.

Referenced by irr::core::CMatrix4< T >::buildNDCToDCMatrix(), irr::core::rect< float >::constrainTo(), irr::core::rect< float >::getArea(), irr::core::rect< float >::getSize(), and irr::gui::IGUIElement::updateAbsolutePosition().

template<class T>

dimension2d<T> irr::core::rect< T >::getSize | ( |  | ) | const`[inline]`

Get the dimensions of the rectangle.

Definition at line 231 of file rect.h.

Referenced by irr::gui::IGUIElement::setRelativePosition().

template<class T>

T irr::core::rect< T >::getWidth | ( |  | ) | const`[inline]`

Get width of rectangle.

Definition at line 184 of file rect.h.

Referenced by irr::core::CMatrix4< T >::buildNDCToDCMatrix(), irr::core::rect< float >::constrainTo(), irr::core::rect< float >::getArea(), irr::core::rect< float >::getSize(), and irr::gui::IGUIElement::updateAbsolutePosition().

template<class T>

bool irr::core::rect< T >::isPointInside | ( | const position2d< T > & | pos | ) | const`[inline]`

Returns if a 2d point is within this rectangle.

Parameters:

  | pos | Position to test if it lies within this rectangle.

Returns:
  True if the position is within the rectangle, false if not.

Definition at line 105 of file rect.h.

template<class T>

bool irr::core::rect< T >::isRectCollided | ( | const rect< T > & | other | ) | const`[inline]`

Check if the rectangle collides with another rectangle.

Parameters:

  | other | Rectangle to test collision with

Returns:
  True if the rectangles collide.

Definition at line 116 of file rect.h.

template<class T>

bool irr::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 216 of file rect.h.

template<class T>

bool irr::core::rect< T >::operator!= | ( | const rect< T > & | other | ) | const`[inline]`

inequality operator

Definition at line 84 of file rect.h.

template<class T>

rect<T> irr::core::rect< T >::operator+ | ( | const position2d< T > & | pos | ) | const`[inline]`

move right by given numbers

Definition at line 47 of file rect.h.

template<class T>

rect<T>& irr::core::rect< T >::operator+= | ( | const position2d< T > & | pos | ) | `[inline]`

move right by given numbers

Definition at line 54 of file rect.h.

template<class T>

rect<T> irr::core::rect< T >::operator- | ( | const position2d< T > & | pos | ) | const`[inline]`

move left by given numbers

Definition at line 62 of file rect.h.

template<class T>

rect<T>& irr::core::rect< T >::operator-= | ( | const position2d< T > & | pos | ) | `[inline]`

move left by given numbers

Definition at line 69 of file rect.h.

template<class T>

bool irr::core::rect< T >::operator< | ( | const rect< T > & | other | ) | const`[inline]`

compares size of rectangles

Definition at line 91 of file rect.h.

template<class T>

bool irr::core::rect< T >::operator== | ( | const rect< T > & | other | ) | const`[inline]`

equality operator

Definition at line 77 of file rect.h.

template<class T>

void irr::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 196 of file rect.h.

## Member Data Documentation

template<class T>

position2d<T> irr::core::rect< T >::LowerRightCorner

Lower right corner.

Definition at line 267 of file rect.h.

Referenced by irr::core::rect< float >::addInternalPoint(), irr::core::CMatrix4< T >::buildNDCToDCMatrix(), irr::core::rect< float >::clipAgainst(), irr::core::rect< float >::constrainTo(), irr::core::rect< float >::getCenter(), irr::core::rect< float >::getHeight(), irr::core::rect< float >::getWidth(), irr::core::rect< float >::isPointInside(), irr::core::rect< float >::isRectCollided(), irr::core::rect< float >::isValid(), irr::core::rect< float >::operator!=(), irr::core::rect< float >::operator+=(), irr::core::rect< float >::operator-=(), irr::core::rect< float >::operator==(), irr::core::rect< float >::repair(), irr::gui::IGUIElement::setRelativePosition(), and irr::gui::IGUIElement::setRelativePositionProportional().

template<class T>

position2d<T> irr::core::rect< T >::UpperLeftCorner

Upper left corner.

Definition at line 265 of file rect.h.

Referenced by irr::core::rect< float >::addInternalPoint(), irr::core::CMatrix4< T >::buildNDCToDCMatrix(), irr::core::rect< float >::clipAgainst(), irr::core::rect< float >::constrainTo(), irr::core::rect< float >::getCenter(), irr::core::rect< float >::getHeight(), irr::core::rect< float >::getWidth(), irr::core::rect< float >::isPointInside(), irr::core::rect< float >::isRectCollided(), irr::core::rect< float >::isValid(), irr::core::rect< float >::operator!=(), irr::core::rect< float >::operator+=(), irr::core::rect< float >::operator-=(), irr::core::rect< float >::operator==(), irr::core::rect< float >::repair(), irr::gui::IGUIElement::setRelativePosition(), irr::gui::IGUIElement::setRelativePositionProportional(), and irr::gui::IGUIElement::updateAbsolutePosition().

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

- rect.h

| The Irrlicht Engine Documentation © 2003-2009 by Nikolaus Gebhardt. Generated on Sun Jan 10 09:24:09 2010 by Doxygen (1.5.6)