![]() |
Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
Utility class for manipulating 2D axis aligned rectangles. More...
#include <gf/Rect.h>
Public Member Functions | |
| constexpr | Rect () noexcept |
| Default constructor. More... | |
| constexpr | Rect (T rectLeft, T rectTop, T rectWidth, T rectHeight) noexcept |
| Construct the rectangle from its coordinates. More... | |
| Rect (const Vector< T, 2 > &rectPosition, const Vector< T, 2 > &rectSize) noexcept | |
| Construct the rectangle from position and size. More... | |
| constexpr Vector< T, 2 > | getPosition () const noexcept |
| Get the position of the rectangle. More... | |
| constexpr Vector< T, 2 > | getSize () const noexcept |
| Get the size of the rectangle. More... | |
| constexpr bool | isEmpty () const noexcept |
| Check if the rectangle is empty. More... | |
| constexpr Vector< T, 2 > | getCenter () const noexcept |
| Get the center of the rectangle. More... | |
| constexpr Vector< T, 2 > | getTopLeft () const noexcept |
| Get the top left corner. More... | |
| constexpr Vector< T, 2 > | getTopRight () const noexcept |
| Get the top right corner. More... | |
| constexpr Vector< T, 2 > | getBottomLeft () const noexcept |
| Get the bottom left corner. More... | |
| constexpr Vector< T, 2 > | getBottomRight () const noexcept |
| Get the bottom right corner. More... | |
| constexpr bool | contains (const Vector< T, 2 > &point) const noexcept |
| Check if a point is inside the rectangle's area. More... | |
| constexpr bool | contains (const Rect< T > &other) const noexcept |
| Check if a rectangle is inside the rectangle's area. More... | |
| constexpr bool | intersects (const Rect< T > &other) const noexcept |
| Check the intersection between two rectangles. More... | |
| bool | intersects (const Rect< T > &other, Rect< T > &result) const noexcept |
| Check the intersection between two rectangles. More... | |
| constexpr Rect< T > | extend (T value) const noexcept |
| Extend the rectangle. More... | |
| constexpr Rect< T > | shrink (T value) const noexcept |
| Shrink the rectangle. More... | |
Public Attributes | |
| union { | |
| struct { | |
| T left | |
| Left coordinate of the rectangle. More... | |
| T top | |
| Top coordinate of the rectangle. More... | |
| T width | |
| Width of the rectangle. More... | |
| T height | |
| Height of the rectangle. More... | |
| } | |
| struct { | |
| Vector< T, 2 > position | |
| Position of the rectangle. More... | |
| Vector< T, 2 > size | |
| Size of the rectangle. More... | |
| } | |
| }; | |
Related Functions | |
(Note that these are not member functions.) | |
| template<typename T > | |
| bool | operator== (const Rect< T > &lhs, const Rect< T > &rhs) |
| Equality operator. More... | |
| template<typename T > | |
| bool | operator!= (const Rect< T > &lhs, const Rect< T > &rhs) |
| Inequality operator. More... | |
Utility class for manipulating 2D axis aligned rectangles.
A rectangle is defined by its top-left corner and its size. It is a very simple class defined for convenience, so its member variables (left, top, width and height) are public and can be accessed directly. You can also access the position and the size of the rectangle directly as gf::Vector.
gf::Rect uses the usual rules for its boundaries:
This means that gf::RectI(0, 0, 1, 1) and gf::RectI(1, 1, 1, 1) don't intersect.
gf::Rect is a template and may be used with any numeric type, but for simplicity, some common typedef are defined:
int as Tunsigned as Tstd::size_t as Tfloat as TSo that you don't have to care about the template syntax.
Usage example:
Default constructor.
Creates an empty rectangle (it is equivalent to calling Rect(0, 0, 0, 0)).
|
inlinenoexcept |
Construct the rectangle from its coordinates.
Be careful, the last two parameters are the width and height, not the right and bottom coordinates!
| rectLeft | Left coordinate of the rectangle |
| rectTop | Top coordinate of the rectangle |
| rectWidth | Width of the rectangle |
| rectHeight | Height of the rectangle |
|
inlinenoexcept |
Construct the rectangle from position and size.
Be careful, the last parameter is the size, not the bottom-right corner!
| rectPosition | Position of the top left corner of the rectangle |
| rectSize | Size of the rectangle |
|
inlinenoexcept |
Check if a point is inside the rectangle's area.
| point | Point to test |
|
inlinenoexcept |
Check if a rectangle is inside the rectangle's area.
| other | Rectangle to test |
Extend the rectangle.
| value | The amount to extend |
Get the bottom left corner.
Get the bottom right corner.
Get the center of the rectangle.
Get the position of the rectangle.
It is a synonym for the position member
Get the size of the rectangle.
It is a synonym for the size member
Get the top left corner.
Get the top right corner.
|
inlinenoexcept |
Check the intersection between two rectangles.
| other | Rectangle to test |
|
inlinenoexcept |
Check the intersection between two rectangles.
This overload returns the overlapped rectangle in the result parameter.
| other | Rectangle to test |
| result | Rectangle to be filled with the intersection |
Check if the rectangle is empty.
An empty rectangle is a rectangle that has one of its size coordinates that is zero.
Shrink the rectangle.
| value | The amount to shrink |
Inequality operator.
| lhs | First rectangle |
| rhs | Second rectangle |
Equality operator.
| lhs | First rectangle |
| rhs | Second rectangle |
| union { ... } |
An anonymous union to handle the various representations
1.8.8