Rect#
-
class Rect#
2D rectangle representation using integer coordinates.
This class represents a 2D rectangle defined by left, right, top, and bottom boundaries using integer coordinates. It provides methods for computing dimensions, expanding the rectangle, and testing point containment.
The coordinate system assumes that left < right and top < bottom.
Public Functions
-
inline Rect()#
Default constructor creating a zero-sized rectangle.
Creates a rectangle with all boundaries set to zero.
- inline Rect(
- uint32_t left,
- uint32_t right,
- uint32_t top,
- uint32_t bottom,
Constructor with explicit boundary values.
- Parameters:
left – [in] Left boundary coordinate
right – [in] Right boundary coordinate
top – [in] Top boundary coordinate
bottom – [in] Bottom boundary coordinate
- Pre:
left <= right and top <= bottom
-
inline uint32_t Width() const#
Computes the width of the rectangle.
- Returns:
Width as the difference between right and left boundaries
-
inline uint32_t Height() const#
Computes the height of the rectangle.
- Returns:
Height as the difference between bottom and top boundaries
-
inline void Expand(uint32_t x)#
Expands the rectangle by a uniform amount in all directions.
Warning
This operation may cause underflow if x is larger than the boundaries.
- Parameters:
x – [in] Amount to expand by in each direction
-
inline uint32_t Left() const#
Gets the left boundary coordinate.
- Returns:
Left boundary value
-
inline uint32_t Right() const#
Gets the right boundary coordinate.
- Returns:
Right boundary value
-
inline uint32_t Top() const#
Gets the top boundary coordinate.
- Returns:
Top boundary value
-
inline uint32_t Bottom() const#
Gets the bottom boundary coordinate.
- Returns:
Bottom boundary value
-
inline bool Contains(uint32_t x, uint32_t y) const#
Tests if a point is contained within the rectangle.
- Parameters:
x – [in] X-coordinate of the point to test
y – [in] Y-coordinate of the point to test
- Returns:
True if the point is inside or on the boundary of the rectangle, false otherwise
-
inline Rect()#