#include <rect.h>
Public Member Functions | |
constexpr | Rect (int16 w, int16 h) |
Rect (const Point &topLeft, const Point &bottomRight) | |
constexpr | Rect (const Point &topLeft, int16 w, int16 h) |
Rect (int16 x1, int16 y1, int16 x2, int16 y2) | |
bool | operator== (const Rect &rhs) const |
bool | operator!= (const Rect &rhs) const |
int16 | width () const |
int16 | height () const |
void | setWidth (int16 aWidth) |
void | setHeight (int16 aHeight) |
bool | contains (int16 x, int16 y) const |
bool | contains (const Point &p) const |
bool | contains (const Rect &r) const |
bool | equals (const Rect &r) const |
bool | intersects (const Rect &r) const |
Rect | findIntersectingRect (const Rect &r) const |
void | extend (const Rect &r) |
void | grow (int16 offset) |
void | clip (const Rect &r) |
void | clip (int16 maxw, int16 maxh) |
bool | isEmpty () const |
bool | isValidRect () const |
void | moveTo (int16 x, int16 y) |
void | translate (int16 dx, int16 dy) |
void | moveTo (const Point &p) |
void | debugPrint (int debuglevel=0, const char *caption="Rect:") const |
Static Public Member Functions | |
static Rect | center (int16 cx, int16 cy, int16 w, int16 h) |
static bool | getBlitRect (Point &dst, Rect &rect, const Rect &clip) |
Public Attributes | |
int16 | top |
int16 | left |
int16 | bottom |
int16 | right |
Simple class for handling a rectangular zone.
Note: This implementation is built around the assumption that (top,left) is part of the rectangle, but (bottom,right) is not. This is reflected in various methods, including contains(), intersects(), and others.
Another very widespread approach to rectangle classes treats (bottom,right) also as a part of the rectangle.
Conceptually, both are sound, but the approach we use saves many intermediate computations (like computing the height in our case is done by doing this: height = bottom - top; while in the alternate system, it would be height = bottom - top + 1;
When writing code using our Rect class, always keep this principle in mind!
|
inline |
Create a rectangle with the top-left corner at position (0, 0) and the given width w
and height h
.
Create a rectangle with the top-left corner at the position topLeft
and the bottom-right corner at the position bottomRight
.
The topLeft
x value must be greater or equal bottomRight
x and topLeft
y must be greater or equal bottomRight
y.
|
inline |
Create a rectangle with the top-left corner at the position topLeft
and the given width w
and height h
.
|
inline |
Create a rectangle with the top-left corner at the given position (x1, y1) and the bottom-right corner at the position (x2, y2).
The x2
value must be greater or equal x1
and y2
must be greater or equal y1
.
|
inline |
Check if two rectangles are identical.
|
inline |
Check if two rectangles are different.
|
inline |
Return the width of a rectangle.
|
inline |
Return the height of a rectangle.
|
inline |
< Set the width to aWidth
value.
|
inline |
< Set the height to aHeight
value.
|
inline |
Check if the given position is inside this rectangle.
x | The horizontal position to check. |
y | The vertical position to check. |
|
inline |
Check if the given point is inside this rectangle.
p | The point to check. |
|
inline |
|
inline |
|
inline |
Check if the given rectangle intersects with this rectangle.
r | The rectangle to check. |
Find the intersecting rectangle between this rectangle and the given rectangle.
r | The intersecting rectangle. |
|
inline |
Extend this rectangle so that it contains r
.
r | The rectangle to extend by. |
|
inline |
Extend this rectangle in all four directions by the given number of pixels.
offset | The size to grow by. |
|
inline |
Clip this rectangle with another rectangle r
.
|
inline |
Reduce the dimensions of this rectangle by setting max width and max height.
|
inline |
Check if the rectangle is empty (its width or length is 0) or invalid (its width or length are negative).
true | The rectangle is empty or invalid. |
false | The rectangle is valid and not empty. |
|
inline |
Check if this is a valid rectangle.
|
inline |
Move this rectangle to the position defined by x
, y
.
|
inline |
Move the rectangle by the given delta x and y values.
|
inline |
Move this rectangle to the position of the point p
.
|
inline |
Print debug messages related to this class.
|
inlinestatic |
Create a rectangle around the given center.
Given target surface with size clip, this function ensures that blit arguments dst
and rect
are within the clip
rectangle.
dst | Blit destination coordinates. |
rect | Blit source rectangle. |
clip | Clip rectangle (size of destination surface). |
int16 Common::Rect::left |
The point at the top left of the rectangle (part of the Rect).
int16 Common::Rect::right |
The point at the bottom right of the rectangle (not part of the Rect).