![]() |
Gamedev Framework (gf)
0.14.0
A C++14 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 (const Box< T, 2 > &box) |
Constructor from a box. More... | |
constexpr Vector< T, 2 > | getPositionFromAnchor (Anchor anchor) const noexcept |
Get a position from the rectangle and an anchor. 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 T | getWidth () const noexcept |
Get the width of the rectangle. More... | |
constexpr T | getHeight () const noexcept |
Get the height of the rectangle. More... | |
![]() | |
constexpr | Box () noexcept |
Default constructor. More... | |
constexpr | Box (Vector< T, N > p0, Vector< T, N > p1) noexcept |
Constructor with two points. More... | |
constexpr | Box (const T(&p0)[N], const T(&p1)[N]) noexcept |
Constructor with two points (as arrays) More... | |
constexpr | Box (Vector< T, N > p) noexcept |
Constructor with one point. More... | |
constexpr Vector< T, N > | getPosition () const noexcept |
Get the position of the box. More... | |
constexpr Vector< T, N > | getSize () const noexcept |
Get the size of the box. More... | |
constexpr bool | isEmpty () const noexcept |
Check if the box is empty. More... | |
constexpr Vector< T, N > | getCenter () const noexcept |
Get the center of the box. More... | |
constexpr bool | contains (Vector< T, N > point) const noexcept |
Check if a point is inside the box. More... | |
constexpr bool | contains (const Box< T, N > &other) const noexcept |
Check if a box is totally inside the box. More... | |
constexpr bool | intersects (const Box< T, N > &other) const noexcept |
Check if two boxes interset. More... | |
constexpr bool | intersects (const Box< T, N > &other, Box< T, N > &result) const noexcept |
Check if two boxes interset and get the intersetion box. More... | |
constexpr Box< T, N > | getIntersection (const Box< T, N > &other) const noexcept |
Compute the intersection of two boxes. More... | |
constexpr T | getIntersectionVolume (const Box< T, N > &other) const noexcept |
Get the volume of the intersection. More... | |
constexpr T | getIntersectionExtentLength (const Box< T, N > &other) const noexcept |
Get the extent length of the intersection. More... | |
constexpr void | extend (const T(&point)[N]) noexcept |
Extend the box with a point (as array) More... | |
constexpr void | extend (Vector< T, N > point) noexcept |
Extend the box with a point. More... | |
constexpr void | extend (const Box< T, N > &other) noexcept |
Extend the box with a box. More... | |
constexpr Box< T, N > | getExtended (const Box< T, N > &other) const noexcept |
Get the box extended by another box. More... | |
constexpr T | getVolume () const noexcept |
Get the volume of the box. More... | |
constexpr T | getExtentLength () const noexcept |
Get the extent length of the box. More... | |
constexpr T | getMinimumEdge () const noexcept |
Get the minimum edge of the box. More... | |
constexpr Box< T, 2 > | grow (T value) const noexcept |
Grow the box. More... | |
constexpr Box< T, 2 > | shrink (T value) const noexcept |
Shrink the box. More... | |
constexpr void | normalize () noexcept |
Ensures that min coordinates are less than max coordinates. More... | |
Static Public Member Functions | |
static constexpr Rect< T > | fromMinMax (Vector< T, 2 > min, Vector< T, 2 > max) noexcept |
Create a rectangle from a min point and a max point. More... | |
static constexpr Rect< T > | fromPositionSize (Vector< T, 2 > position, Vector< T, 2 > size) noexcept |
Create a rectangle from a position (top-left) and a size. More... | |
static constexpr Rect< T > | fromCenterSize (Vector< T, 2 > center, Vector< T, 2 > size) noexcept |
Create a rectangle from a center and a size. 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... | |
template<typename Archive , typename T > | |
Archive & | operator| (Archive &ar, Rect< T > &rect) |
Serialize a rectangle. More... | |
![]() | |
constexpr bool | operator== (const Box< T, N > &lhs, const Box< T, N > &rhs) |
Equality operator. More... | |
Additional Inherited Members | |
![]() | |
Vector< T, N > | min |
The minimum point of the box. More... | |
Vector< T, N > | max |
The maximum point of the box. More... | |
Utility class for manipulating 2D axis aligned rectangles.
A rectangle is defined by its top-left corner (called min
) and its bottom-right corner (called `max').
gf::Rect uses the usual rules for its boundaries:
gf::Rect is a template and may be used with any numeric type, but for simplicity, some common typedef are defined:
int
as T
unsigned
as T
std::size_t
as T
float
as T
So that you don't have to care about the template syntax.
Usage example:
Default constructor.
Creates an empty rectangle.
Constructor from a box.
box | The orignal box |
|
inlinestaticnoexcept |
Create a rectangle from a center and a size.
center | The center of the rectangle |
size | The size of the rectangle |
|
inlinestaticnoexcept |
Create a rectangle from a min point and a max point.
min | The minimum point in the rectangle |
max | The maximum point in the rectangle |
|
inlinestaticnoexcept |
Create a rectangle from a position (top-left) and a size.
position | The top-left position of the rectangle |
size | The size of the rectangle |
Get the bottom left corner.
Get the bottom right corner.
Get the height of the rectangle.
|
inlinenoexcept |
Get a position from the rectangle and an anchor.
anchor | An anchor |
Get the top left corner.
Get the top right corner.
Get the width of the rectangle.
Inequality operator.
lhs | First rectangle |
rhs | Second rectangle |
Equality operator.
lhs | First rectangle |
rhs | Second rectangle |