![]() |
Gamedev Framework (gf)
0.19.0
A C++17 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 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 bool | contains (Vector< T, 2 > point) const noexcept |
Check if a point is inside the rectangle. More... | |
constexpr bool | contains (const Rect &other) const noexcept |
Check if a rectangle is totally inside the rectangle. More... | |
constexpr bool | intersects (const Rect &other) const noexcept |
Check if two rectangles interset. More... | |
constexpr bool | intersects (const Rect &other, Rect &result) const noexcept |
Check if two rectangles interset and get the intersetion rectangle. More... | |
constexpr Rect | getIntersection (const Rect &other) const noexcept |
Compute the intersection of two rectangles. More... | |
constexpr T | getIntersectionVolume (const Rect &other) const noexcept |
Get the volume of the intersection. More... | |
constexpr T | getIntersectionExtentLength (const Rect &other) const noexcept |
Get the extent length of the intersection. More... | |
constexpr void | extend (const T(&point)[2]) noexcept |
Extend the rectangle with a point (as array) More... | |
constexpr void | extend (Vector< T, 2 > point) noexcept |
Extend the rectangle with a point. More... | |
constexpr void | extend (const Rect &other) noexcept |
Extend the rectangle with a rectangle. More... | |
constexpr Rect | getExtended (const Rect &other) const noexcept |
Get the rectangle extended by another rectangle. More... | |
constexpr T | getVolume () const noexcept |
Get the volume of the rectangle. More... | |
constexpr T | getExtentLength () const noexcept |
Get the extent length of the rectangle. More... | |
constexpr T | getMinimumEdge () const noexcept |
Get the minimum edge of the rectangle. More... | |
constexpr Rect | grow (T value) const noexcept |
Grow the rectangle. More... | |
constexpr Rect | shrink (T value) const noexcept |
Shrink the rectangle. More... | |
constexpr void | normalize () noexcept |
Ensures that min coordinates are less than max coordinates. 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... | |
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... | |
static constexpr Rect< T > | empty () noexcept |
Create an empty rectangle. More... | |
Public Attributes | |
Vector< T, 2 > | min |
The minimum point of the rectangle. More... | |
Vector< T, 2 > | max |
The maximum point 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... | |
template<typename Archive , typename T > | |
Archive & | operator| (Archive &ar, Rect< T > &rect) |
Serialize a rectangle. 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 a rectangle of size zero located at the origin.
|
inlinenoexcept |
Check if a point is inside the rectangle.
point | The point to test |
|
inlinenoexcept |
Check if a rectangle is totally inside the rectangle.
other | Another rectangle to test |
Create an empty rectangle.
Extend the rectangle with a point (as array)
point | The point of extension |
Extend the rectangle with a point.
point | The point of extension |
Extend the rectangle with a rectangle.
other | The rectangle of extension |
|
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 center of the rectangle.
|
inlinenoexcept |
Get the rectangle extended by another rectangle.
other | The rectangle of extension |
Get the extent length of the rectangle.
Get the height of the rectangle.
|
inlinenoexcept |
Compute the intersection of two rectangles.
other | Another rectangle to test |
|
inlinenoexcept |
Get the extent length of the intersection.
other | Another rectangle to test |
|
inlinenoexcept |
Get the volume of the intersection.
other | Another rectangle to test |
Get the minimum edge of the rectangle.
Get the position of the rectangle.
This is the same as min
.
|
inlinenoexcept |
Get a position from the rectangle and an anchor.
anchor | An anchor |
Get the size of the rectangle.
Get the top left corner.
Get the top right corner.
Get the volume of the rectangle.
Get the width of the rectangle.
Grow the rectangle.
value | The amount to grow |
|
inlinenoexcept |
Check if two rectangles interset.
other | Another rectangle to test |
|
inlinenoexcept |
Check if two rectangles interset and get the intersetion rectangle.
other | Another rectangle to test |
result | A reference to put the result of the intersection (in case there is any) |
Check if the rectangle is empty.
Ensures that min coordinates are less than max coordinates.
Shrink the rectangle.
value | The amount to shrink |
Inequality operator.
lhs | First rectangle |
rhs | Second rectangle |
Equality operator.
lhs | First rectangle |
rhs | Second rectangle |
|
related |
Serialize a rectangle.
ar | The archive |
rect | The rectangle to serialize |