[ VIGRA Homepage |
Class Index |
Function Index |
File Index |
Main Page ]
|
Rect2D Class Reference
|
 |
Two dimensional rectangle.
More...
#include "vigra/diff2d.hxx"
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.
Rect2D r1(Point2D(0,0), Point2D(10, 20)),
r2(Point2D(10, 15), Size2D(20, 20));
Point2D p(0,100);
Rect2D r3 = r1 | r2;
assert(r3.contains(r2));
assert(!r3.contains(p));
r3 |= p;
assert(r3.contains(p));
#include "vigra/utilities.hxx"
Namespace: vigra
Constructor & Destructor Documentation
|
Construct a null rectangle (isEmpty() will return true) |
Rect2D |
( |
Point2D const & |
upperLeft, |
|
|
Point2D const & |
lowerRight |
|
) |
[inline] |
|
|
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 |
|
) |
[inline] |
|
|
Construct a rectangle representing the given range |
Rect2D |
( |
Point2D const & |
upperLeft, |
|
|
Size2D const & |
size |
|
) |
[inline] |
|
|
Construct a rectangle of given position and size |
Rect2D |
( |
Size2D const & |
size |
) |
[inline, explicit] |
|
|
Construct a rectangle of given size at position (0,0) |
Member Function Documentation
void addBorder |
( |
int |
borderWidth, |
|
|
int |
borderHeight |
|
) |
[inline] |
|
|
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 |
) |
[inline] |
|
|
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 |
) |
[inline] |
|
|
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 [inline] |
|
|
Determine and return the area of this rectangle. That is, if this rect isEmpty(), returns zero, otherwise returns width()*height(). |
int bottom |
( |
|
) |
const [inline] |
|
|
Return the bottom coordinate of this rectangle. That is the first row below the rectangle. |
bool contains |
( |
Rect2D const & |
r |
) |
const [inline] |
|
|
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 [inline] |
|
|
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 [inline] |
|
|
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 [inline] |
|
|
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 [inline] |
|
|
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 [inline] |
|
|
Return the left coordinate of this rectangle. |
Point2D const& lowerRight |
( |
|
) |
const [inline] |
|
|
Return the first point to the right and below the rectangle. |
void moveBy |
( |
int |
xOffset, |
|
|
int |
yOffset |
|
) |
[inline] |
|
|
Move the whole rectangle by the given x- and y-offsets. |
void moveBy |
( |
Diff2D const & |
offset |
) |
[inline] |
|
|
Move the whole rectangle by the given 2D offset. |
void moveTo |
( |
int |
left, |
|
|
int |
top |
|
) |
[inline] |
|
|
Move the whole rectangle so that upperLeft() will become Point2D(left, top) afterwards. |
void moveTo |
( |
Point2D const & |
newUpperLeft |
) |
[inline] |
|
|
Move the whole rectangle so that the given point will be upperLeft() afterwards. |
Rect2D operator & |
( |
Rect2D const & |
r |
) |
const [inline] |
|
|
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. |
Rect2D operator & |
( |
Point2D const & |
p |
) |
const [inline] |
|
|
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. |
Rect2D& operator &= |
( |
Rect2D const & |
r |
) |
[inline] |
|
|
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 &= |
( |
Point2D const & |
p |
) |
[inline] |
|
|
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| |
( |
Rect2D const & |
r |
) |
const [inline] |
|
|
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. |
Rect2D operator| |
( |
Point2D const & |
p |
) |
[inline] |
|
|
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. |
Rect2D& operator|= |
( |
Rect2D const & |
r |
) |
[inline] |
|
|
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. |
Rect2D& operator|= |
( |
Point2D const & |
p |
) |
[inline] |
|
|
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 [inline] |
|
|
Return the right coordinate of this rectangle. That is the first column to the right of the rectangle. |
void setLowerRight |
( |
Point2D const & |
lr |
) |
[inline] |
|
void setSize |
( |
int |
width, |
|
|
int |
height |
|
) |
[inline] |
|
|
Resize this rectangle to the given extents. This will move the lower right corner only. |
void setSize |
( |
Size2D const & |
size |
) |
[inline] |
|
|
Resize this rectangle to the given extents. This will move the lower right corner only. |
void setUpperLeft |
( |
Point2D const & |
ul |
) |
[inline] |
|
Size2D size |
( |
|
) |
const [inline] |
|
|
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 [inline] |
|
|
Return the top coordinate of this rectangle. |
Point2D const& upperLeft |
( |
|
) |
const [inline] |
|
|
Return the first point (scan-order wise) which is considered to be "in" the rectangle. |
int width |
( |
|
) |
const [inline] |
|
|
Determine and return the width of this rectangle. It might be zero or even negative, and if so, isEmpty() will return true. |
The documentation for this class was generated from the following file: