Chemical Data Processing Library C++ API - Version 1.2.0
|
Specifies an axis aligned rectangular area in 2D space. More...
#include <Rectangle2D.hpp>
Public Member Functions | |
Rectangle2D () | |
Constructs an undefined rectangle. More... | |
Rectangle2D (const Math::Vector2D &min, const Math::Vector2D &max) | |
Constructs a rectangle with the minimum point set to min and the maximum point set to max. More... | |
Rectangle2D (double min_x, double min_y, double max_x, double max_y) | |
Constructs a rectangle with the minimum point set to (min_x, min_y) and the maximum point set to (max_x, max_y). More... | |
virtual | ~Rectangle2D () |
Virtual destructor. More... | |
bool | isDefined () const |
Tells if the rectangle is well defined. More... | |
void | addPoint (const Math::Vector2D &pt) |
Adds the point pt to the current rectangle. More... | |
void | addPoint (double x, double y) |
Adds the point (x, y) to the current rectangle. More... | |
void | addMargin (double width, double height) |
Extends the rectangle by adding a margin with the specified width and height. More... | |
void | addRectangle (const Rectangle2D &rect) |
Adds the rectangle rect to the current rectangle. More... | |
bool | containsPoint (const Math::Vector2D &pt) const |
Tests if the point pt is within the boundary of the rectangle. More... | |
bool | containsPoint (double x, double y) const |
Tests if the point (x, y) is within the boundary of the rectangle. More... | |
bool | containsRectangle (const Rectangle2D &rect) const |
Tests if the specified rectangle rect is within the boundary of this rectangle. More... | |
bool | intersectsRectangle (const Rectangle2D &rect) const |
Tests if the interior of this rectangle intersects the rectangle rect. More... | |
void | setMin (const Math::Vector2D &pt) |
Sets the minimum point of the rectangle to pt. More... | |
void | setMin (double x, double y) |
Sets the minimum point of the rectangle to (x, y). More... | |
void | setMax (const Math::Vector2D &pt) |
Sets the maximum point of the rectangle to pt. More... | |
void | setMax (double x, double y) |
Sets the maximum point of the rectangle to (x, y). More... | |
void | setBounds (double min_x, double min_y, double max_x, double max_y) |
Sets the minimum point of the rectangle to (min_x, min_y) and the maximum point to (max_x, max_y). More... | |
void | setBounds (const Math::Vector2D &min, const Math::Vector2D &max) |
Sets the minimum point of the rectangle to min and the maximum point to max. More... | |
const Math::Vector2D & | getMin () const |
Returns the minimum point of the rectangle. More... | |
const Math::Vector2D & | getMax () const |
Returns the maximum point of the rectangle. More... | |
Math::Vector2D | getCenter () const |
Calculates the center of the rectangle. More... | |
void | getCenter (Math::Vector2D &ctr) const |
Calculates the center of the rectangle and stores the result in ctr. More... | |
double | getWidth () const |
Returns the width of the rectangle. More... | |
double | getHeight () const |
Returns the height of the rectangle. More... | |
double | getArea () const |
Calculates the area of the rectangle. More... | |
void | reset () |
Resets the rectangle to an undefinded state. More... | |
void | translate (const Math::Vector2D &vec) |
Translates the minimum and maximum point of the rectangle by vec. More... | |
void | scale (double factor) |
Scales the minimum and maximum point of the rectangle by the specified factor. More... | |
bool | operator== (const Rectangle2D &rect) const |
Equality comparison operator. More... | |
bool | operator!= (const Rectangle2D &rect) const |
Inequality comparison operator. More... | |
Specifies an axis aligned rectangular area in 2D space.
The rectangle is defined by a minimum point \( (x_{min}, y_{min}) \) and a maximum point \( (x_{max}, y_{max}) \). For a well defined rectangle the coordinates of the minimum and maximum point must satisfy the follwing inequalities: \( x_{min} \leq x_{max} \) and \( y_{min} \leq y_{max} \).
CDPL::Vis::Rectangle2D::Rectangle2D | ( | ) |
Constructs an undefined rectangle.
The coordinates of the minimum point are set to std::numeric_limits<double>::max()
and the coordinates of the maximum point are set to -
. std::numeric_limits<double>::max()
CDPL::Vis::Rectangle2D::Rectangle2D | ( | const Math::Vector2D & | min, |
const Math::Vector2D & | max | ||
) |
Constructs a rectangle with the minimum point set to min and the maximum point set to max.
min | The minimum point. |
max | The maximum point. |
CDPL::Vis::Rectangle2D::Rectangle2D | ( | double | min_x, |
double | min_y, | ||
double | max_x, | ||
double | max_y | ||
) |
Constructs a rectangle with the minimum point set to (min_x, min_y) and the maximum point set to (max_x, max_y).
min_x | The x-coordinate of the minimum point. |
min_y | The y-coordinate of the minimum point. |
max_x | The x-coordinate of the maximum point. |
max_y | The y-coordinate of the maximum point. |
|
inlinevirtual |
Virtual destructor.
bool CDPL::Vis::Rectangle2D::isDefined | ( | ) | const |
Tells if the rectangle is well defined.
The rectangle is well defined if neither the height nor the width of the rectangle is negative.
true
if the rectangle is defined, and false
otherwise. void CDPL::Vis::Rectangle2D::addPoint | ( | const Math::Vector2D & | pt | ) |
Adds the point pt to the current rectangle.
The resulting (adjusted) rectangle represents the smallest rectangular area that contains both the original rectangle and the specified point pt.
pt | The point to add. |
void CDPL::Vis::Rectangle2D::addPoint | ( | double | x, |
double | y | ||
) |
Adds the point (x, y) to the current rectangle.
The resulting (adjusted) rectangle represents the smallest rectangular area that contains both the original rectangle and the specified point (x, y).
x | The x-coordinate of the point to add. |
y | The y-coordinate of the point to add. |
void CDPL::Vis::Rectangle2D::addMargin | ( | double | width, |
double | height | ||
) |
Extends the rectangle by adding a margin with the specified width and height.
The minimum point gets translated by (-width, -height) and the maximum point by (width, height).
width | The amount the rectangle will be extended horizontally. |
height | The amount the rectangle will be extended vertically. |
void CDPL::Vis::Rectangle2D::addRectangle | ( | const Rectangle2D & | rect | ) |
Adds the rectangle rect to the current rectangle.
The resulting rectangle is the union of the two rectangle objects and contains both the original rectangle and the specified rectangle rect.
rect | The other rectangle to add. |
bool CDPL::Vis::Rectangle2D::containsPoint | ( | const Math::Vector2D & | pt | ) | const |
Tests if the point pt is within the boundary of the rectangle.
A point lying exactly on one of the edges or corners is also considered to be within the boundaries.
pt | The point to test. |
true
if pt is within the boundary of the rectangle, and false
otherwise. bool CDPL::Vis::Rectangle2D::containsPoint | ( | double | x, |
double | y | ||
) | const |
Tests if the point (x, y) is within the boundary of the rectangle.
A point lying exactly on one of the edges or corners is also considered to be within the boundaries.
x | The x-coordinate of the point to test. |
y | The y-coordinate of the point to test. |
true
if the point (x, y) is within the boundary of the rectangle, and false
otherwise. bool CDPL::Vis::Rectangle2D::containsRectangle | ( | const Rectangle2D & | rect | ) | const |
Tests if the specified rectangle rect is within the boundary of this rectangle.
The result is equivalent to (this->containsPoint(rect.getMin()) && this->containsPoint(rect.getMax()))
.
rect | The rectangle to test. |
true
if the rectangle rect is within the boundary of this rectangle, and false
otherwise. bool CDPL::Vis::Rectangle2D::intersectsRectangle | ( | const Rectangle2D & | rect | ) | const |
Tests if the interior of this rectangle intersects the rectangle rect.
If the rectangles overlap only on one of their edges or corners, they are also considered to intersect.
rect | The rectangle to test. |
true
if the rectangles intersect, and false
otherwise. void CDPL::Vis::Rectangle2D::setMin | ( | const Math::Vector2D & | pt | ) |
Sets the minimum point of the rectangle to pt.
pt | The new minimum point. |
void CDPL::Vis::Rectangle2D::setMin | ( | double | x, |
double | y | ||
) |
Sets the minimum point of the rectangle to (x, y).
x | The x-coordinate of the new minimum point. |
y | The y-coordinate of the new minimum point. |
void CDPL::Vis::Rectangle2D::setMax | ( | const Math::Vector2D & | pt | ) |
Sets the maximum point of the rectangle to pt.
pt | The new maximum point. |
void CDPL::Vis::Rectangle2D::setMax | ( | double | x, |
double | y | ||
) |
Sets the maximum point of the rectangle to (x, y).
x | The x-coordinate of the new maximum point. |
y | The y-coordinate of the new maximum point. |
void CDPL::Vis::Rectangle2D::setBounds | ( | double | min_x, |
double | min_y, | ||
double | max_x, | ||
double | max_y | ||
) |
Sets the minimum point of the rectangle to (min_x, min_y) and the maximum point to (max_x, max_y).
min_x | The x-coordinate of the new minimum point. |
min_y | The y-coordinate of the new minimum point. |
max_x | The x-coordinate of the new maximum point. |
max_y | The y-coordinate of the new maximum point. |
void CDPL::Vis::Rectangle2D::setBounds | ( | const Math::Vector2D & | min, |
const Math::Vector2D & | max | ||
) |
Sets the minimum point of the rectangle to min and the maximum point to max.
min | The new minimum point. |
max | The new maximum point. |
const Math::Vector2D& CDPL::Vis::Rectangle2D::getMin | ( | ) | const |
Returns the minimum point of the rectangle.
const Math::Vector2D& CDPL::Vis::Rectangle2D::getMax | ( | ) | const |
Returns the maximum point of the rectangle.
Math::Vector2D CDPL::Vis::Rectangle2D::getCenter | ( | ) | const |
Calculates the center of the rectangle.
void CDPL::Vis::Rectangle2D::getCenter | ( | Math::Vector2D & | ctr | ) | const |
Calculates the center of the rectangle and stores the result in ctr.
ctr | A vector storing the calculated center point. |
double CDPL::Vis::Rectangle2D::getWidth | ( | ) | const |
Returns the width of the rectangle.
The width of the rectangle is the difference \( x_{max} - x_{min} \) between the x-coordinate of the maximum point \( x_{max} \) and the x-coordinate of the minimum point \( x_{min} \).
double CDPL::Vis::Rectangle2D::getHeight | ( | ) | const |
Returns the height of the rectangle.
The height of the rectangle is the difference \( y_{max} - y_{min} \) between the y-coordinate of the maximum point \( y_{max} \) and the y-coordinate of the minimum point \( y_{min} \).
double CDPL::Vis::Rectangle2D::getArea | ( | ) | const |
Calculates the area of the rectangle.
void CDPL::Vis::Rectangle2D::reset | ( | ) |
Resets the rectangle to an undefinded state.
The coordinates of the minimum point are set to std::numeric_limits<double>::max()
and the coordinates of the maximum point are set to -
. std::numeric_limits<double>::max()
void CDPL::Vis::Rectangle2D::translate | ( | const Math::Vector2D & | vec | ) |
Translates the minimum and maximum point of the rectangle by vec.
vec | The translation vector. |
void CDPL::Vis::Rectangle2D::scale | ( | double | factor | ) |
Scales the minimum and maximum point of the rectangle by the specified factor.
factor | The scaling factor. |
bool CDPL::Vis::Rectangle2D::operator== | ( | const Rectangle2D & | rect | ) | const |
Equality comparison operator.
rect | The other Rectangle2D object to be compared with. |
true
if the minimum and maximum points compare equal, and false
otherwise. bool CDPL::Vis::Rectangle2D::operator!= | ( | const Rectangle2D & | rect | ) | const |
Inequality comparison operator.
The result is equivalent to !(*this == rect)
.
rect | The other Rectangle2D object to be compared with. |
true
if either the minimum or maximum points compare non-equal, and false
otherwise.