|
Infinity Engine v0.6.20
C++ API Documentation
|
Axis-aligned rectangle defined by left, right, top, and bottom edges. More...
#include <Rect.hpp>
Public Member Functions | |
| constexpr | Rect () |
| Default constructor. | |
| constexpr | Rect (const Rect &r) |
| Copy constructor. | |
| constexpr | Rect (float l, float r, float t, float b) |
| Constructs a rectangle from edge positions. | |
| constexpr Rect & | operator= (const Rect &)=default |
| Copy assignment operator. | |
| void | set (float in_l, float in_r, float in_t, float in_b) |
| Sets all four edge positions. | |
| Vector2 | topLeft () const |
| Gets the top-left corner position. | |
| Vector2 | topRight () const |
| Gets the top-right corner position. | |
| Vector2 | bottomLeft () const |
| Gets the bottom-left corner position. | |
| Vector2 | bottomRight () const |
| Gets the bottom-right corner position. | |
| float | width () const |
| Computes the width of the rectangle. | |
| float | height () const |
| Computes the height of the rectangle. | |
| float | area () const |
| Computes the area of the rectangle. | |
| bool | contains (const Vector2 &p) const |
| Tests if a point is contained within the rectangle. | |
| Rect | translated (const Vector2 &offset) const |
| Creates a translated copy of this rectangle. | |
| Rect | scaled (float factor) const |
| Creates a scaled copy of this rectangle. | |
| Vector2 | center () const |
| Computes the center point of the rectangle. | |
| Vector2 | size () const |
| Gets the size of the rectangle as a vector. | |
| Rect & | operator+= (const Rect &rhs) |
| Addition assignment with another rectangle. | |
| Rect & | operator+= (const Vector2 &rhs) |
| Addition assignment with a vector. | |
| Rect & | operator-= (const Rect &rhs) |
| Subtraction assignment with another rectangle. | |
| Rect & | operator-= (const Vector2 &rhs) |
| Subtraction assignment with a vector. | |
| operator bool () const noexcept | |
| Boolean conversion operator. | |
Static Public Member Functions | |
| static Rect | fromSize (float x, float y, float width, float height) |
| Creates a rectangle from position and size. | |
| static constexpr Rect | zero () |
| Creates a zero-sized rectangle at the origin. | |
Public Attributes | |
| float | l |
| Left edge position. | |
| float | r |
| Right edge position. | |
| float | t |
| Top edge position. | |
| float | b |
| Bottom edge position. | |
Axis-aligned rectangle defined by left, right, top, and bottom edges.
Rect represents a 2D axis-aligned rectangular region, storing the positions of its four edges (left, right, top, bottom). This representation is flexible and supports various coordinate conventions depending on the application.
Common uses in procedural generation:
The rectangle can be interpreted in different coordinate systems:
Example usage:
|
inlineconstexpr |
Default constructor.
Creates a zero-sized rectangle at the origin (all edges at 0).
|
inlineconstexpr |
Copy constructor.
| r | Rectangle to copy from. |
|
inlineconstexpr |
Constructs a rectangle from edge positions.
| l | Left edge position. |
| r | Right edge position. |
| t | Top edge position. |
| b | Bottom edge position. |
| float Infinity::Types::Math::Rect::area | ( | ) | const |
Computes the area of the rectangle.
| Vector2 Infinity::Types::Math::Rect::bottomLeft | ( | ) | const |
Gets the bottom-left corner position.
| Vector2 Infinity::Types::Math::Rect::bottomRight | ( | ) | const |
Gets the bottom-right corner position.
| Vector2 Infinity::Types::Math::Rect::center | ( | ) | const |
| bool Infinity::Types::Math::Rect::contains | ( | const Vector2 & | p | ) | const |
Tests if a point is contained within the rectangle.
Tests if the point's coordinates are within the bounds defined by the rectangle's edges. The test assumes left < right and top < bottom.
| p | Point to test. |
|
static |
Creates a rectangle from position and size.
Constructs a rectangle given a top-left corner position and dimensions. Assumes a coordinate system where X increases rightward and Y increases downward (typical screen space convention).
| x | Left edge position (X coordinate of top-left corner). |
| y | Top edge position (Y coordinate of top-left corner). |
| width | Width of the rectangle (right = x + width). |
| height | Height of the rectangle (bottom = y + height). |
| float Infinity::Types::Math::Rect::height | ( | ) | const |
Computes the height of the rectangle.
|
explicitnoexcept |
Boolean conversion operator.
Returns true if the rectangle is non-zero (any edge is non-zero).
Addition assignment with another rectangle.
Adds the edges of another rectangle to this rectangle's edges.
| rhs | Rectangle to add. |
Addition assignment with a vector.
Translates the rectangle by adding the vector to all edges.
| rhs | Translation offset. |
Subtraction assignment with another rectangle.
Subtracts the edges of another rectangle from this rectangle's edges.
| rhs | Rectangle to subtract. |
Subtraction assignment with a vector.
Translates the rectangle by subtracting the vector from all edges.
| rhs | Translation offset. |
Copy assignment operator.
| Rect Infinity::Types::Math::Rect::scaled | ( | float | factor | ) | const |
Creates a scaled copy of this rectangle.
Returns a new rectangle with all edge positions scaled by the given factor. This scales around the origin (0, 0), not around the rectangle's center.
| factor | Scale factor to apply to all edges. |
| void Infinity::Types::Math::Rect::set | ( | float | in_l, |
| float | in_r, | ||
| float | in_t, | ||
| float | in_b | ||
| ) |
Sets all four edge positions.
| in_l | Left edge position. |
| in_r | Right edge position. |
| in_t | Top edge position. |
| in_b | Bottom edge position. |
| Vector2 Infinity::Types::Math::Rect::size | ( | ) | const |
Gets the size of the rectangle as a vector.
| Vector2 Infinity::Types::Math::Rect::topLeft | ( | ) | const |
Gets the top-left corner position.
| Vector2 Infinity::Types::Math::Rect::topRight | ( | ) | const |
Gets the top-right corner position.
Creates a translated copy of this rectangle.
Returns a new rectangle with all edges offset by the given vector.
| offset | Translation offset to apply. |
| float Infinity::Types::Math::Rect::width | ( | ) | const |
Computes the width of the rectangle.
|
inlinestaticconstexpr |
Creates a zero-sized rectangle at the origin.
| float Infinity::Types::Math::Rect::b |
Bottom edge position.
| float Infinity::Types::Math::Rect::l |
Left edge position.
| float Infinity::Types::Math::Rect::r |
Right edge position.
| float Infinity::Types::Math::Rect::t |
Top edge position.