Scribus
Open source desktop publishing at your fingertips
|
The FRect class defines a rectangle in the plane. More...
Public Member Functions | |
FRect () | |
FRect (FPoint &topleft, FPoint &bottomright) | |
FRect (FPoint &topleft, FSize &size) | |
FRect (qreal left, qreal top, qreal width, qreal height) | |
bool | isNull () const |
bool | isEmpty () const |
bool | isValid () const |
FRect | normalize () const |
qreal | left () const |
qreal | top () const |
qreal | right () const |
qreal | bottom () const |
qreal & | rLeft () |
qreal & | rTop () |
qreal & | rRight () |
qreal & | rBottom () |
qreal | x () const |
qreal | y () const |
void | setLeft (qreal pos) |
void | setTop (qreal pos) |
void | setRight (qreal pos) |
void | setBottom (qreal pos) |
void | setX (qreal x) |
void | setY (qreal y) |
void | setTopLeft (FPoint &p) |
void | setBottomRight (FPoint &p) |
void | setTopRight (FPoint &p) |
void | setBottomLeft (FPoint &p) |
FPoint | topLeft () const |
FPoint | bottomRight () const |
FPoint | topRight () const |
FPoint | bottomLeft () const |
FPoint | center () const |
void | rect (qreal *x, qreal *y, qreal *w, qreal *h) const |
void | coords (qreal *x1, qreal *y1, qreal *x2, qreal *y2) const |
void | moveLeft (qreal pos) |
void | moveTop (qreal pos) |
void | moveRight (qreal pos) |
void | moveBottom (qreal pos) |
void | moveTopLeft (FPoint &p) |
void | moveBottomRight (FPoint &p) |
void | moveTopRight (FPoint &p) |
void | moveBottomLeft (FPoint &p) |
void | moveCenter (FPoint &p) |
void | moveBy (qreal dx, qreal dy) |
void | setRect (qreal x, qreal y, qreal w, qreal h) |
void | setCoords (qreal x1, qreal y1, qreal x2, qreal y2) |
void | addCoords (qreal x1, qreal y1, qreal x2, qreal y2) |
FSize | size () const |
qreal | width () const |
qreal | height () const |
void | setWidth (qreal w) |
void | setHeight (qreal h) |
void | setSize (const FSize &s) |
FRect | operator| (const FRect &r) const |
FRect | operator& (const FRect &r) const |
FRect & | operator|= (const FRect &r) |
FRect & | operator&= (const FRect &r) |
bool | contains (FPoint &p, bool proper=false) const |
bool | contains (qreal x, qreal y) const |
bool | contains (qreal x, qreal y, bool proper) const |
bool | contains (const FRect &r, bool proper=false) const |
FRect | unite (const FRect &r) const |
FRect | intersect (const FRect &r) const |
bool | intersects (const FRect &r) const |
Friends | |
bool | operator== (const FRect &, const FRect &) |
bool | operator!= (const FRect &, const FRect &) |
The FRect class defines a rectangle in the plane.
A rectangle is internally represented as an upper-left corner and a bottom-right corner, but it is normally expressed as an upper-left corner and a size.
The coordinate type is qreal (defined in qwindowdefs.h
as int
). The minimum value of qreal is qreal_MIN (-2147483648) and the maximum value is qreal_MAX (2147483647).
Note that the size (width and height) of a rectangle might be different from what you are used to. If the top-left corner and the bottom-right corner are the same, the height and the width of the rectangle will both be 1.
Generally, {width = right - left + 1} and {height = bottom - top + 1}. We designed it this way to make it correspond to rectangular spaces used by drawing functions in which the width and height denote a number of pixels. For example, drawing a rectangle with width and height 1 draws a single pixel.
The default coordinate system has origin (0, 0) in the top-left corner. The positive direction of the y axis is down, and the positive x axis is from left to right.
A FRect can be constructed with a set of left, top, width and height integers, from two FPoints or from a FPoint and a FSize. After creation the dimensions can be changed, e.g. with setLeft(), setRight(), setTop() and setBottom(), or by setting sizes, e.g. setWidth(), setHeight() and setSize(). The dimensions can also be changed with the move functions, e.g. moveBy(), moveCenter(), moveBottomRight(), etc. You can also add coordinates to a rectangle with addCoords().
You can test to see if a FRect contains a specific point with contains(). You can also test to see if two FRects intersect with intersects() (see also intersect()). To get the bounding rectangle of two FRects use unite().
|
inline |
Constructs an invalid rectangle.
Constructs a rectangle with topLeft as the top-left corner and bottomRight as the bottom-right corner.
Constructs a rectangle with topLeft as the top-left corner and size as the rectangle size.
|
inline |
void FRect::addCoords | ( | qreal | xp1, |
qreal | yp1, | ||
qreal | xp2, | ||
qreal | yp2 | ||
) |
Adds xp1, yp1, xp2 and yp2 respectively to the existing coordinates of the rectangle.
|
inline |
Returns the bottom coordinate of the rectangle.
|
inline |
Returns the bottom-left position of the rectangle.
|
inline |
Returns the bottom-right position of the rectangle.
|
inline |
Returns the center point of the rectangle.
bool FRect::contains | ( | FPoint & | p, |
bool | proper = false |
||
) | const |
Returns TRUE if the point p is inside or on the edge of the rectangle; otherwise returns FALSE.
If proper is TRUE, this function returns TRUE only if p is inside (not on the edge).
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns TRUE if the point x, y is inside this rectangle; otherwise returns FALSE.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns TRUE if the point x, y is inside this rectangle; otherwise returns FALSE.
If proper is TRUE, this function returns TRUE only if the point is entirely inside (not on the edge).
bool FRect::contains | ( | const FRect & | r, |
bool | proper = false |
||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns TRUE if the rectangle r is inside this rectangle; otherwise returns FALSE.
If proper is TRUE, this function returns TRUE only if r is entirely inside (not on the edge).
void FRect::coords | ( | qreal * | xp1, |
qreal * | yp1, | ||
qreal * | xp2, | ||
qreal * | yp2 | ||
) | const |
Extracts the rectangle parameters as the top-left point *xp1, *yp1 and the bottom-right point *xp2, *yp2.
|
inline |
Returns the height of the rectangle. The height includes both the top and bottom edges, i.e. height = bottom - top + 1.
Returns the intersection of this rectangle and rectangle r. {r.intersect(s)} is equivalent to
{r&s}.
bool FRect::intersects | ( | const FRect & | r | ) | const |
Returns TRUE if this rectangle intersects with rectangle r (there is at least one pixel that is within both rectangles); otherwise returns FALSE.
|
inline |
|
inline |
Returns TRUE if the rectangle is a null rectangle; otherwise returns FALSE.
A null rectangle has both the width and the height set to 0, that is right() == left() - 1 and bottom() == top() - 1.
Note that if right() == left() and bottom() == top(), then the rectangle has width 1 and height 1.
A null rectangle is also empty.
A null rectangle is not valid.
|
inline |
|
inline |
Returns the left coordinate of the rectangle. Identical to x().
void FRect::moveBottom | ( | qreal | pos | ) |
Sets the bottom position of the rectangle to pos, leaving the size unchanged.
void FRect::moveBottomLeft | ( | FPoint & | p | ) |
Sets the bottom-left position of the rectangle to p, leaving the size unchanged.
void FRect::moveBottomRight | ( | FPoint & | p | ) |
Sets the bottom-right position of the rectangle to p, leaving the size unchanged.
void FRect::moveBy | ( | qreal | dx, |
qreal | dy | ||
) |
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.
void FRect::moveCenter | ( | FPoint & | p | ) |
Sets the center point of the rectangle to p, leaving the size unchanged.
void FRect::moveLeft | ( | qreal | pos | ) |
Sets the left position of the rectangle to pos, leaving the size unchanged.
void FRect::moveRight | ( | qreal | pos | ) |
Sets the right position of the rectangle to pos, leaving the size unchanged.
void FRect::moveTop | ( | qreal | pos | ) |
Sets the top position of the rectangle to pos, leaving the size unchanged.
void FRect::moveTopLeft | ( | FPoint & | p | ) |
Sets the top-left position of the rectangle to p, leaving the size unchanged.
void FRect::moveTopRight | ( | FPoint & | p | ) |
Sets the top-right position of the rectangle to p, leaving the size unchanged.
FRect FRect::normalize | ( | ) | const |
Returns the intersection of this rectangle and rectangle r.
Returns an empty rectangle if there is no intersection.
Returns the bounding rectangle of this rectangle and rectangle r.
The bounding rectangle of a nonempty rectangle and an empty or invalid rectangle is defined to be the nonempty rectangle.
|
inline |
void FRect::rect | ( | qreal * | x, |
qreal * | y, | ||
qreal * | w, | ||
qreal * | h | ||
) | const |
|
inline |
Returns the right coordinate of the rectangle.
|
inline |
|
inline |
|
inline |
|
inline |
Sets the bottom edge of the rectangle to pos. May change the height, but will never change the top edge of the rectangle.
void FRect::setBottomLeft | ( | FPoint & | p | ) |
Set the bottom-left corner of the rectangle to p. May change the size, but will the never change the top-right corner of the rectangle.
void FRect::setBottomRight | ( | FPoint & | p | ) |
Set the bottom-right corner of the rectangle to p. May change the size, but will the never change the top-left corner of the rectangle.
void FRect::setCoords | ( | qreal | xp1, |
qreal | yp1, | ||
qreal | xp2, | ||
qreal | yp2 | ||
) |
void FRect::setHeight | ( | qreal | h | ) |
Sets the height of the rectangle to h. The top edge is not moved, but the bottom edge may be moved.
|
inline |
Sets the left edge of the rectangle to pos. May change the width, but will never change the right edge of the rectangle.
Identical to setX().
void FRect::setRect | ( | qreal | x, |
qreal | y, | ||
qreal | w, | ||
qreal | h | ||
) |
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to (w, h).
|
inline |
Sets the right edge of the rectangle to pos. May change the width, but will never change the left edge of the rectangle.
void FRect::setSize | ( | const FSize & | s | ) |
Sets the size of the rectangle to s. The top-left corner is not moved.
|
inline |
Sets the top edge of the rectangle to pos. May change the height, but will never change the bottom edge of the rectangle.
Identical to setY().
void FRect::setTopLeft | ( | FPoint & | p | ) |
Set the top-left corner of the rectangle to p. May change the size, but will the never change the bottom-right corner of the rectangle.
void FRect::setTopRight | ( | FPoint & | p | ) |
Set the top-right corner of the rectangle to p. May change the size, but will the never change the bottom-left corner of the rectangle.
void FRect::setWidth | ( | qreal | w | ) |
Sets the width of the rectangle to w. The right edge is changed, but not the left edge.
|
inline |
|
inline |
|
inline |
Returns the top coordinate of the rectangle. Identical to y().
|
inline |
Returns the top-left position of the rectangle.
|
inline |
Returns the top-right position of the rectangle.
Returns the bounding rectangle of this rectangle and rectangle r. {r.unite(s)} is equivalent to
{r|s}.
|
inline |
Returns the width of the rectangle. The width includes both the left and right edges, i.e. width = right - left + 1.
|
inline |
|
inline |
Returns TRUE if r1 and r2 are different; otherwise returns FALSE.
Returns TRUE if r1 and r2 are equal; otherwise returns FALSE.