Chemical Data Processing Library C++ API - Version 1.1.1
Public Member Functions | List of all members
CDPL::Vis::Rectangle2D Class Reference

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::Vector2DgetMin () const
 Returns the minimum point of the rectangle. More...
 
const Math::Vector2DgetMax () 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...
 

Detailed Description

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} \).

Constructor & Destructor Documentation

◆ Rectangle2D() [1/3]

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().

◆ Rectangle2D() [2/3]

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.

Parameters
minThe minimum point.
maxThe maximum point.

◆ Rectangle2D() [3/3]

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).

Parameters
min_xThe x-coordinate of the minimum point.
min_yThe y-coordinate of the minimum point.
max_xThe x-coordinate of the maximum point.
max_yThe y-coordinate of the maximum point.

◆ ~Rectangle2D()

virtual CDPL::Vis::Rectangle2D::~Rectangle2D ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

◆ isDefined()

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.

Returns
true if the rectangle is defined, and false otherwise.
See also
getWidth(), getHeight()

◆ addPoint() [1/2]

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.

Parameters
ptThe point to add.

◆ addPoint() [2/2]

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).

Parameters
xThe x-coordinate of the point to add.
yThe y-coordinate of the point to add.

◆ addMargin()

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).

Parameters
widthThe amount the rectangle will be extended horizontally.
heightThe amount the rectangle will be extended vertically.

◆ addRectangle()

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.

Parameters
rectThe other rectangle to add.

◆ containsPoint() [1/2]

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.

Parameters
ptThe point to test.
Returns
true if pt is within the boundary of the rectangle, and false otherwise.

◆ containsPoint() [2/2]

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.

Parameters
xThe x-coordinate of the point to test.
yThe y-coordinate of the point to test.
Returns
true if the point (x, y) is within the boundary of the rectangle, and false otherwise.

◆ containsRectangle()

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())).

Parameters
rectThe rectangle to test.
Returns
true if the rectangle rect is within the boundary of this rectangle, and false otherwise.

◆ intersectsRectangle()

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.

Parameters
rectThe rectangle to test.
Returns
true if the rectangles intersect, and false otherwise.

◆ setMin() [1/2]

void CDPL::Vis::Rectangle2D::setMin ( const Math::Vector2D pt)

Sets the minimum point of the rectangle to pt.

Parameters
ptThe new minimum point.

◆ setMin() [2/2]

void CDPL::Vis::Rectangle2D::setMin ( double  x,
double  y 
)

Sets the minimum point of the rectangle to (x, y).

Parameters
xThe x-coordinate of the new minimum point.
yThe y-coordinate of the new minimum point.

◆ setMax() [1/2]

void CDPL::Vis::Rectangle2D::setMax ( const Math::Vector2D pt)

Sets the maximum point of the rectangle to pt.

Parameters
ptThe new maximum point.

◆ setMax() [2/2]

void CDPL::Vis::Rectangle2D::setMax ( double  x,
double  y 
)

Sets the maximum point of the rectangle to (x, y).

Parameters
xThe x-coordinate of the new maximum point.
yThe y-coordinate of the new maximum point.

◆ setBounds() [1/2]

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).

Parameters
min_xThe x-coordinate of the new minimum point.
min_yThe y-coordinate of the new minimum point.
max_xThe x-coordinate of the new maximum point.
max_yThe y-coordinate of the new maximum point.

◆ setBounds() [2/2]

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.

Parameters
minThe new minimum point.
maxThe new maximum point.

◆ getMin()

const Math::Vector2D& CDPL::Vis::Rectangle2D::getMin ( ) const

Returns the minimum point of the rectangle.

Returns
The minimum point of the rectangle.

◆ getMax()

const Math::Vector2D& CDPL::Vis::Rectangle2D::getMax ( ) const

Returns the maximum point of the rectangle.

Returns
The maximum point of the rectangle.

◆ getCenter() [1/2]

Math::Vector2D CDPL::Vis::Rectangle2D::getCenter ( ) const

Calculates the center of the rectangle.

Returns
The center of the rectangle.

◆ getCenter() [2/2]

void CDPL::Vis::Rectangle2D::getCenter ( Math::Vector2D ctr) const

Calculates the center of the rectangle and stores the result in ctr.

Parameters
ctrA vector storing the calculated center point.

◆ getWidth()

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} \).

Returns
The width of the rectangle.

◆ getHeight()

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} \).

Returns
The height of the rectangle.

◆ getArea()

double CDPL::Vis::Rectangle2D::getArea ( ) const

Calculates the area of the rectangle.

Returns
The calculated area of the rectangle.

◆ reset()

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().

◆ translate()

void CDPL::Vis::Rectangle2D::translate ( const Math::Vector2D vec)

Translates the minimum and maximum point of the rectangle by vec.

Parameters
vecThe translation vector.

◆ scale()

void CDPL::Vis::Rectangle2D::scale ( double  factor)

Scales the minimum and maximum point of the rectangle by the specified factor.

Parameters
factorThe scaling factor.

◆ operator==()

bool CDPL::Vis::Rectangle2D::operator== ( const Rectangle2D rect) const

Equality comparison operator.

Parameters
rectThe other Rectangle2D object to be compared with.
Returns
true if the minimum and maximum points compare equal, and false otherwise.

◆ operator!=()

bool CDPL::Vis::Rectangle2D::operator!= ( const Rectangle2D rect) const

Inequality comparison operator.

The result is equivalent to !(*this == rect).

Parameters
rectThe other Rectangle2D object to be compared with.
Returns
true if either the minimum or maximum points compare non-equal, and false otherwise.

The documentation for this class was generated from the following file: