FRect Class Reference
The FRect class defines a rectangle in the plane. More...
#include <frect.h>
Public Member Functions | |
| FRect () | |
| FRect (FPoint &topleft, FPoint &bottomright) | |
| FRect (FPoint &topleft, FSize &size) | |
| FRect (double left, double top, double width, double height) | |
| bool | isNull () const |
| bool | isEmpty () const |
| bool | isValid () const |
| FRect | normalize () const |
| double | left () const |
| double | top () const |
| double | right () const |
| double | bottom () const |
| double & | rLeft () |
| double & | rTop () |
| double & | rRight () |
| double & | rBottom () |
| double | x () const |
| double | y () const |
| void | setLeft (double pos) |
| void | setTop (double pos) |
| void | setRight (double pos) |
| void | setBottom (double pos) |
| void | setX (double x) |
| void | setY (double 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 (double *x, double *y, double *w, double *h) const |
| void | coords (double *x1, double *y1, double *x2, double *y2) const |
| void | moveLeft (double pos) |
| void | moveTop (double pos) |
| void | moveRight (double pos) |
| void | moveBottom (double pos) |
| void | moveTopLeft (FPoint &p) |
| void | moveBottomRight (FPoint &p) |
| void | moveTopRight (FPoint &p) |
| void | moveBottomLeft (FPoint &p) |
| void | moveCenter (FPoint &p) |
| void | moveBy (double dx, double dy) |
| void | setRect (double x, double y, double w, double h) |
| void | setCoords (double x1, double y1, double x2, double y2) |
| void | addCoords (double x1, double y1, double x2, double y2) |
| FSize | size () const |
| double | width () const |
| double | height () const |
| void | setWidth (double w) |
| void | setHeight (double 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 (double x, double y) const |
| bool | contains (double x, double 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 |
Private Attributes | |
| double | x1 |
| double | y1 |
| double | x2 |
| double | y2 |
Friends | |
| bool | operator== (const FRect &, const FRect &) |
| bool | operator!= (const FRect &, const FRect &) |
Detailed Description
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 double (defined in qwindowdefs.h as int). The minimum value of double is double_MIN (-2147483648) and the maximum value is double_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().
Definition at line 50 of file frect.h.
Constructor & Destructor Documentation
| FRect::FRect | ( | ) | [inline] |
Constructs a rectangle with topLeft as the top-left corner and bottomRight as the bottom-right corner.
Definition at line 106 of file frect.cpp.
References FPoint::x(), x1, x2, FPoint::y(), y1, and y2.
Constructs a rectangle with topLeft as the top-left corner and size as the rectangle size.
Definition at line 119 of file frect.cpp.
References FSize::height(), FSize::width(), FPoint::x(), x1, x2, FPoint::y(), y1, and y2.
| FRect::FRect | ( | double | left, | |
| double | top, | |||
| double | width, | |||
| double | height | |||
| ) | [inline] |
Member Function Documentation
| bool FRect::isNull | ( | ) | const [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.
| bool FRect::isEmpty | ( | ) | const [inline] |
| bool FRect::isValid | ( | ) | const [inline] |
Returns TRUE if the rectangle is valid; otherwise returns FALSE.
A valid rectangle has a left() <= right() and top() <= bottom().
Note that non-trivial operations like intersections are not defined for invalid rectangles.
{isValid() == !isEmpty()}
- See also:
- isNull(), isEmpty(), normalize()
Definition at line 176 of file frect.h.
References x1, x2, y1, and y2.
Referenced by operator|().
| FRect FRect::normalize | ( | ) | const |
| double FRect::left | ( | ) | const [inline] |
| double FRect::top | ( | void | ) | const [inline] |
| double FRect::right | ( | ) | const [inline] |
Returns the right coordinate of the rectangle.
- See also:
- setRight(), left(), topRight(), bottomRight()
Definition at line 185 of file frect.h.
References x2.
| double FRect::bottom | ( | void | ) | const [inline] |
Returns the bottom coordinate of the rectangle.
- See also:
- setBottom(), top(), bottomLeft(), bottomRight()
Definition at line 188 of file frect.h.
References y2.
| double & FRect::rLeft | ( | ) | [inline] |
| double & FRect::rTop | ( | ) | [inline] |
| double & FRect::rRight | ( | ) | [inline] |
| double & FRect::rBottom | ( | ) | [inline] |
| double FRect::x | ( | ) | const [inline] |
| double FRect::y | ( | ) | const [inline] |
| void FRect::setLeft | ( | double | pos | ) | [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().
- See also:
- left(), setTop(), setWidth()
Definition at line 209 of file frect.h.
References x1.
Referenced by operator|(), setBottomLeft(), and setTopLeft().
| void FRect::setTop | ( | double | pos | ) | [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().
- See also:
- top(), setBottom(), setHeight()
Definition at line 212 of file frect.h.
References y1.
Referenced by operator|(), setTopLeft(), and setTopRight().
| void FRect::setRight | ( | double | pos | ) | [inline] |
Sets the right edge of the rectangle to pos. May change the width, but will never change the left edge of the rectangle.
- See also:
- right(), setLeft(), setWidth()
Definition at line 215 of file frect.h.
References x2.
Referenced by operator|(), setBottomRight(), and setTopRight().
| void FRect::setBottom | ( | double | pos | ) | [inline] |
Sets the bottom edge of the rectangle to pos. May change the height, but will never change the top edge of the rectangle.
- See also:
- bottom(), setTop(), setHeight()
Definition at line 218 of file frect.h.
References y2.
Referenced by operator|(), setBottomLeft(), and setBottomRight().
| void FRect::setX | ( | double | x | ) | [inline] |
| void FRect::setY | ( | double | y | ) | [inline] |
| 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.
- See also:
- topLeft(), moveTopLeft(), setBottomRight(), setTopRight(), setBottomLeft()
Definition at line 371 of file frect.cpp.
References setLeft(), setTop(), FPoint::x(), and FPoint::y().
| 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.
Definition at line 384 of file frect.cpp.
References setBottom(), setRight(), FPoint::x(), and FPoint::y().
| 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.
- See also:
- topRight(), moveTopRight(), setTopLeft(), setBottomRight(), setBottomLeft()
Definition at line 397 of file frect.cpp.
References setRight(), setTop(), FPoint::x(), and FPoint::y().
| 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.
Definition at line 410 of file frect.cpp.
References setBottom(), setLeft(), FPoint::x(), and FPoint::y().
| FPoint FRect::topLeft | ( | ) | const [inline] |
Returns the top-left position of the rectangle.
- See also:
- setTopLeft(), moveTopLeft(), bottomRight(), left(), top()
| FPoint FRect::bottomRight | ( | ) | const [inline] |
Returns the bottom-right position of the rectangle.
- See also:
- setBottomRight(), moveBottomRight(), topLeft(), right(), bottom()
| FPoint FRect::topRight | ( | ) | const [inline] |
Returns the top-right position of the rectangle.
- See also:
- setTopRight(), moveTopRight(), bottomLeft(), top(), right()
| FPoint FRect::bottomLeft | ( | ) | const [inline] |
Returns the bottom-left position of the rectangle.
- See also:
- setBottomLeft(), moveBottomLeft(), topRight(), bottom(), left()
| FPoint FRect::center | ( | ) | const [inline] |
Returns the center point of the rectangle.
- See also:
- moveCenter(), topLeft(), bottomRight(), topRight(), bottomLeft()
| void FRect::rect | ( | double * | x, | |
| double * | y, | |||
| double * | w, | |||
| double * | h | |||
| ) | const |
| void FRect::coords | ( | double * | xp1, | |
| double * | yp1, | |||
| double * | xp2, | |||
| double * | yp2 | |||
| ) | const |
| void FRect::moveLeft | ( | double | pos | ) |
Sets the left position of the rectangle to pos, leaving the size unchanged.
- See also:
- left(), setLeft(), moveTop(), moveRight(), moveBottom()
Definition at line 494 of file frect.cpp.
Referenced by moveBottomLeft(), and moveTopLeft().
| void FRect::moveTop | ( | double | pos | ) |
Sets the top position of the rectangle to pos, leaving the size unchanged.
- See also:
- top(), setTop(), moveLeft(), moveRight(), moveBottom()
Definition at line 507 of file frect.cpp.
Referenced by moveTopLeft(), and moveTopRight().
| void FRect::moveRight | ( | double | pos | ) |
Sets the right position of the rectangle to pos, leaving the size unchanged.
- See also:
- right(), setRight(), moveLeft(), moveTop(), moveBottom()
Definition at line 520 of file frect.cpp.
Referenced by moveBottomRight(), and moveTopRight().
| void FRect::moveBottom | ( | double | pos | ) |
Sets the bottom position of the rectangle to pos, leaving the size unchanged.
- See also:
- bottom(), setBottom(), moveLeft(), moveTop(), moveRight()
Definition at line 533 of file frect.cpp.
Referenced by moveBottomLeft(), and moveBottomRight().
| void FRect::moveTopLeft | ( | FPoint & | p | ) |
Sets the top-left position of the rectangle to p, leaving the size unchanged.
- See also:
- topLeft(), setTopLeft(), moveBottomRight(), moveTopRight(), moveBottomLeft()
Definition at line 546 of file frect.cpp.
References moveLeft(), moveTop(), FPoint::x(), and FPoint::y().
| void FRect::moveBottomRight | ( | FPoint & | p | ) |
Sets the bottom-right position of the rectangle to p, leaving the size unchanged.
Definition at line 559 of file frect.cpp.
References moveBottom(), moveRight(), FPoint::x(), and FPoint::y().
| void FRect::moveTopRight | ( | FPoint & | p | ) |
Sets the top-right position of the rectangle to p, leaving the size unchanged.
Definition at line 572 of file frect.cpp.
References moveRight(), moveTop(), FPoint::x(), and FPoint::y().
| void FRect::moveBottomLeft | ( | FPoint & | p | ) |
Sets the bottom-left position of the rectangle to p, leaving the size unchanged.
Definition at line 585 of file frect.cpp.
References moveBottom(), moveLeft(), FPoint::x(), and FPoint::y().
| void FRect::moveCenter | ( | FPoint & | p | ) |
Sets the center point of the rectangle to p, leaving the size unchanged.
- See also:
- center(), moveTopLeft(), moveBottomRight(), moveTopRight(), moveBottomLeft()
Definition at line 599 of file frect.cpp.
References FPoint::x(), x1, x2, FPoint::y(), y1, and y2.
| void FRect::moveBy | ( | double | dx, | |
| double | dy | |||
| ) |
| void FRect::setRect | ( | double | x, | |
| double | y, | |||
| double | w, | |||
| double | h | |||
| ) |
Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to (w, h).
- See also:
- rect(), setCoords()
Definition at line 633 of file frect.cpp.
References x1, x2, y1, and y2.
Referenced by StoryText::boundingBox().
| void FRect::setCoords | ( | double | xp1, | |
| double | yp1, | |||
| double | xp2, | |||
| double | yp2 | |||
| ) |
| void FRect::addCoords | ( | double | xp1, | |
| double | yp1, | |||
| double | xp2, | |||
| double | yp2 | |||
| ) |
| FSize FRect::size | ( | ) | const [inline] |
| double FRect::width | ( | ) | const [inline] |
| double FRect::height | ( | ) | const [inline] |
Returns the height of the rectangle. The height includes both the top and bottom edges, i.e. height = bottom - top + 1.
- See also:
- width(), size(), setHeight()
Definition at line 245 of file frect.h.
Referenced by LegacyMode::drawTextCursor().
| void FRect::setWidth | ( | double | w | ) |
| void FRect::setHeight | ( | double | h | ) |
| void FRect::setSize | ( | const FSize & | s | ) |
Sets the size of the rectangle to s. The top-left corner is not moved.
- See also:
- size(), setWidth(), setHeight()
Definition at line 727 of file frect.cpp.
References FSize::height(), FSize::width(), x1, x2, y1, and y2.
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.
- See also:
- operator|=(), operator&(), intersects(), contains()
Definition at line 817 of file frect.cpp.
References isValid(), setBottom(), setLeft(), setRight(), setTop(), x1, x2, y1, and y2.
Returns the intersection of this rectangle and rectangle r.
Returns an empty rectangle if there is no intersection.
- See also:
- operator&=(), operator|(), isEmpty(), intersects(), contains()
| 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).
Definition at line 741 of file frect.cpp.
References FPoint::x(), x1, x2, FPoint::y(), y1, and y2.
| bool FRect::contains | ( | double | x, | |
| double | y | |||
| ) | const [inline] |
| bool FRect::contains | ( | double | x, | |
| double | y, | |||
| bool | proper | |||
| ) | const [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).
- See also:
- unite(), intersect(), intersects()
| 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.
- See also:
- intersect(), contains()
Friends And Related Function Documentation
Member Data Documentation
double FRect::x1 [private] |
Definition at line 139 of file frect.h.
Referenced by addCoords(), bottomLeft(), center(), contains(),
