[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
![]() |
Rect2D [Two-dimensional Ranges and Points] |
![]() |
Two dimensional rectangle. More...
#include <vigra/diff2d.hxx>
Public Member Functions | |
void | addBorder (int borderWidth, int borderHeight) |
void | addBorder (int borderWidth) |
void | addSize (Size2D const &offset) |
int | area () const |
int | bottom () const |
bool | contains (Rect2D const &r) const |
bool | contains (Point2D const &p) const |
int | height () const |
bool | intersects (Rect2D const &r) const |
bool | isEmpty () const |
int | left () const |
Point2D const & | lowerRight () const |
void | moveBy (int xOffset, int yOffset) |
void | moveBy (Diff2D const &offset) |
void | moveTo (int left, int top) |
void | moveTo (Point2D const &newUpperLeft) |
Rect2D | operator & (Rect2D const &r) const |
Rect2D | operator & (Point2D const &p) const |
Rect2D & | operator &= (Rect2D const &r) |
Rect2D & | operator &= (Point2D const &p) |
bool | operator!= (Rect2D const &r) const |
inequality check | |
Rect2D | operator* (double factor) const |
Rect2D | operator* (int factor) const |
Rect2D & | operator*= (double factor) |
Rect2D & | operator*= (int factor) |
bool | operator== (Rect2D const &r) const |
equality check | |
Rect2D | operator| (Rect2D const &r) const |
Rect2D | operator| (Point2D const &p) const |
Rect2D & | operator|= (Rect2D const &r) |
Rect2D & | operator|= (Point2D const &p) |
Rect2D (Size2D const &size) | |
Rect2D (Point2D const &upperLeft, Size2D const &size) | |
Rect2D (int left, int top, int right, int bottom) | |
Rect2D (Point2D const &upperLeft, Point2D const &lowerRight) | |
Rect2D () | |
int | right () const |
void | setLowerRight (Point2D const &lr) |
void | setSize (int width, int height) |
void | setSize (Size2D const &size) |
void | setUpperLeft (Point2D const &ul) |
Size2D | size () const |
int | top () const |
Point2D const & | upperLeft () const |
int | width () const |
This class stores a 2-dimensional rectangular range or region. Thus, it follows the VIGRA convention that the upper left corner is inside the rectangle, while the lower right is 1 pixel to the right and below the last pixel in the rectangle.
A major advantage of this class is that it can be constructed from either a pair of Point2D, or from a Point2D and an extend (Size2D). Rect2D overloads operators |=, &=, |, & to realize set union (in the sense of a minimal bounding rectangle) and set intersection.
Rect2D r1(Point2D(0,0), Point2D(10, 20)), r2(Point2D(10, 15), Size2D(20, 20)); Point2D p(0,100); Rect2D r3 = r1 | r2; // upper left is (0,0), lower right is (30, 35) assert(r3.contains(r2)); assert(!r3.contains(p)); r3 |= p; // lower right now (30,101) so that p is inside r3 assert(r3.contains(p));
#include <vigra/utilities.hxx>
Namespace: vigra
Construct a rectangle representing the given range (lowerRight is considered to be outside the rectangle as usual in the VIGRA)
Rect2D | ( | int | left, | |
int | top, | |||
int | right, | |||
int | bottom | |||
) |
Construct a rectangle representing the given range
Construct a rectangle of given position and size
void addBorder | ( | int | borderWidth, | |
int | borderHeight | |||
) |
Adds a border with possibly different widths in x- and y-directions around the rectangle. That means, each x component is moved borderWidth pixels and each y component is moved borderHeight pixels to the outside. (If borderWidth is negative, the rectangle will get smaller accordingly.)
void addBorder | ( | int | borderWidth | ) |
Adds a border of the given width around the rectangle. That means, upperLeft()'s components are moved by -borderWidth and lowerRight()'s by borderWidth. (If borderWidth is negative, the rectangle will get smaller accordingly.)
void addSize | ( | Size2D const & | offset | ) |
Increase the size of the rectangle by the given offset. This will move the lower right corner only. (If any of offset's components is negative, the rectangle will get smaller accordingly.)
int area | ( | ) | const |
int bottom | ( | ) | const |
Return the bottom coordinate of this rectangle. That is the first row below the rectangle.
bool contains | ( | Rect2D const & | r | ) | const |
Return whether this rectangle contains the given one. r1.contains(r2)
returns the same as r1 == (r1|r2)
(but is of course more efficient). That also means, a rectangle (even an empty one!) contains() any empty rectangle.
bool contains | ( | Point2D const & | p | ) | const |
Return whether this rectangle contains the given point. That is, if the point lies within the valid range of an ImageIterator walking from upperLeft() to lowerRight() (excluding the latter).
int height | ( | ) | const |
Determine and return the height of this rectangle. It might be zero or even negative, and if so, isEmpty() will return true.
bool intersects | ( | Rect2D const & | r | ) | const |
Return whether this rectangle overlaps with the given one. r1.intersects(r2)
returns the same as !(r1&r2).isEmpty()
(but is of course much more efficient).
bool isEmpty | ( | ) | const |
Return whether this rectangle is considered empty. It is non-empty if both coordinates of the lower right corner are greater than the corresponding coordinate of the upper left corner. Uniting an empty rectangle with something will return the bounding rectangle of the 'something', intersecting with an empty rectangle will yield again an empty rectangle.
int left | ( | ) | const |
Return the left coordinate of this rectangle.
Point2D const& lowerRight | ( | ) | const |
Return the first point to the right and below the rectangle.
void moveBy | ( | int | xOffset, | |
int | yOffset | |||
) |
Move the whole rectangle by the given x- and y-offsets.
void moveBy | ( | Diff2D const & | offset | ) |
Move the whole rectangle by the given 2D offset.
void moveTo | ( | int | left, | |
int | top | |||
) |
Move the whole rectangle so that upperLeft() will become Point2D(left, top) afterwards.
void moveTo | ( | Point2D const & | newUpperLeft | ) |
Move the whole rectangle so that the given point will be upperLeft() afterwards.
Intersects this rectangle with the given one. The result is the maximal rectangle contained in both original ones. Intersecting with an empty rectangle will yield again an empty rectangle.
Intersects this rectangle with the given point. The result is the bounding rect of the point (with width and height equal to 1) if it was contained in the original rect, or an empty rect otherwise.
Modifies this rectangle by intersecting it with the given one. The result is the maximal rectangle contained in both original ones. Intersecting with an empty rectangle will yield again an empty rectangle.
Modifies this rectangle by intersecting it with the given point. The result is the bounding rect of the point (with width and height equal to 1) if it was contained in the original rect, or an empty rect otherwise.
Rect2D operator* | ( | double | factor | ) | const |
Return rectangle scaled by the given factor. To be specific, both upperLeft() and lowerRight() are multiplicated by `factor`.
Rect2D operator* | ( | int | factor | ) | const |
Return rectangle scaled by the given factor. To be specific, both upperLeft() and lowerRight() are multiplicated by `factor`.
Rect2D& operator*= | ( | double | factor | ) |
Scale this rectangle by the given factor. To be specific, both upperLeft() and lowerRight() are multiplicated by `factor`.
Rect2D& operator*= | ( | int | factor | ) |
Scale this rectangle by the given factor. To be specific, both upperLeft() and lowerRight() are multiplicated by `factor`.
Returns the union of this rectangle and the given one. The result is the bounding rectangle of both rectangles. If one of the rectangles isEmpty(), the union will be the other one.
Returns the union of this rectangle and the given point. The result is the bounding rectangle of the rectangle and the point. If isEmpty returns true, the union will be a rectangle containing only the given point.
Modifies this rectangle by uniting it with the given one. The result is the bounding rectangle of both rectangles. If one of the rectangles isEmpty(), the union will be the other one.
Modifies this rectangle by including the given point. The result is the bounding rectangle of the rectangle and the point. If isEmpty returns true, the union will be a rectangle containing only the given point.
int right | ( | ) | const |
Return the right coordinate of this rectangle. That is the first column to the right of the rectangle.
void setLowerRight | ( | Point2D const & | lr | ) |
Change lowerRight() without changing upperLeft(), which will change the size most probably.
void setSize | ( | int | width, | |
int | height | |||
) |
Resize this rectangle to the given extents. This will move the lower right corner only.
void setSize | ( | Size2D const & | size | ) |
Resize this rectangle to the given extents. This will move the lower right corner only.
void setUpperLeft | ( | Point2D const & | ul | ) |
Change upperLeft() without changing lowerRight(), which will change the size most probably.
Size2D size | ( | ) | const |
Determine and return the size of this rectangle. The width and/or height might be zero or even negative, and if so, isEmpty() will return true.
int top | ( | ) | const |
Return the top coordinate of this rectangle.
Point2D const& upperLeft | ( | ) | const |
Return the first point (scan-order wise) which is considered to be "in" the rectangle.
int width | ( | ) | const |
Determine and return the width of this rectangle. It might be zero or even negative, and if so, isEmpty() will return true.
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|