[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
![]() |
Rect2D Class Reference | ![]() |
Two dimensional rectangle. More...
#include <vigra/diff2d.hxx>
Public Member Functions | |
void | addBorder (int borderWidth) |
void | addBorder (int borderWidth, int borderHeight) |
void | addSize (Size2D const &offset) |
int | area () const |
int | bottom () const |
bool | contains (Point2D const &p) const |
bool | contains (Rect2D const &r) const |
int | height () const |
bool | intersects (Rect2D const &r) const |
bool | isEmpty () const |
int | left () const |
Point2D const & | lowerRight () const |
void | moveBy (Diff2D const &offset) |
void | moveBy (int xOffset, int yOffset) |
void | moveTo (Point2D const &newUpperLeft) |
void | moveTo (int left, int top) |
bool | operator!= (Rect2D const &r) const |
inequality check | |
Rect2D | operator& (Point2D const &p) const |
Rect2D | operator& (Rect2D const &r) const |
Rect2D & | operator&= (Point2D const &p) |
Rect2D & | operator&= (Rect2D const &r) |
Rect2D | operator* (int factor) const |
Rect2D | operator* (double factor) const |
Rect2D & | operator*= (int factor) |
Rect2D & | operator*= (double factor) |
bool | operator== (Rect2D const &r) const |
equality check | |
Rect2D | operator| (Point2D const &p) const |
Rect2D | operator| (Rect2D const &r) const |
Rect2D & | operator|= (Point2D const &p) |
Rect2D & | operator|= (Rect2D const &r) |
Rect2D () | |
Rect2D (Point2D const &upperLeft, Point2D const &lowerRight) | |
Rect2D (int left, int top, int right, int bottom) | |
Rect2D (Point2D const &upperLeft, Size2D const &size) | |
Rect2D (Size2D const &size) | |
int | right () const |
void | setLowerRight (Point2D const &lr) |
void | setSize (Size2D const &size) |
void | setSize (int width, int height) |
void | setUpperLeft (Point2D const &ul) |
Size2D | size () const |
int | top () const |
Point2D const & | upperLeft () const |
int | width () const |
Two dimensional rectangle.
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.
#include <vigra/diff2d.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
Point2D const& upperLeft | ( | ) | const |
Return the first point (scan-order wise) which is considered to be "in" the rectangle.
Point2D const& lowerRight | ( | ) | const |
Return the first point to the right and below the rectangle.
void setUpperLeft | ( | Point2D const & | ul | ) |
Change upperLeft() without changing lowerRight(), which will change the size most probably.
void setLowerRight | ( | Point2D const & | lr | ) |
Change lowerRight() without changing upperLeft(), which will change the size most probably.
void moveTo | ( | Point2D const & | newUpperLeft | ) |
Move the whole rectangle so that the given point will be upperLeft() afterwards.
void moveTo | ( | int | left, |
int | top | ||
) |
Move the whole rectangle so that upperLeft() will become Point2D(left, top) afterwards.
void moveBy | ( | Diff2D const & | offset | ) |
Move the whole rectangle by the given 2D offset.
void moveBy | ( | int | xOffset, |
int | yOffset | ||
) |
Move the whole rectangle by the given x- and y-offsets.
int left | ( | ) | const |
Return the left coordinate of this rectangle.
int top | ( | ) | const |
Return the top coordinate of this rectangle.
int right | ( | ) | const |
Return the right coordinate of this rectangle. That is the first column to the right of the rectangle.
int bottom | ( | ) | const |
Return the bottom coordinate of this rectangle. That is the first row below 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.
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.
int area | ( | ) | const |
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.
void setSize | ( | Size2D const & | size | ) |
Resize this rectangle to the given extents. This will move the lower right corner only.
void setSize | ( | int | width, |
int | height | ||
) |
Resize this rectangle to the given extents. This will move the lower right corner only.
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.)
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 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.)
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.
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).
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 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).
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.
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.
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.
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.
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.
Rect2D& operator*= | ( | int | factor | ) |
Scale this rectangle by the given factor. To be specific, both upperLeft() and lowerRight() are multiplied by factor
.
Rect2D& operator*= | ( | double | factor | ) |
Scale this rectangle by the given factor. To be specific, both upperLeft() and lowerRight() are multiplied by factor
.
Rect2D operator* | ( | int | factor | ) | const |
Return rectangle scaled by the given factor. To be specific, both upperLeft() and lowerRight() are multiplied by factor
.
Rect2D operator* | ( | double | factor | ) | const |
Return rectangle scaled by the given factor. To be specific, both upperLeft() and lowerRight() are multiplied by factor
.
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.
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|