Chemical Data Processing Library Python API - Version 1.1.1
Public Member Functions | Properties | List of all members
CDPL.Vis.Rectangle2D Class Reference

Specifies an axis aligned rectangular area in 2D space. More...

+ Inheritance diagram for CDPL.Vis.Rectangle2D:

Public Member Functions

None __init__ ()
 Constructs an undefined rectangle. More...
 
None __init__ (Rectangle2D rect)
 Initializes a copy of the Rectangle2D instance rect. More...
 
None __init__ (Math.Vector2D min, Math.Vector2D max)
 Constructs a rectangle with the minimum point set to min and the maximum point set to max. More...
 
None __init__ (float min_x, float min_y, float max_x, float 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...
 
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
Rectangle2D assign (Rectangle2D rect)
 Replaces the current state of self with a copy of the state of the Rectangle2D instance rect. More...
 
bool isDefined ()
 Tells if the rectangle is well defined. More...
 
None addPoint (Math.Vector2D pt)
 Adds the point pt to the current rectangle. More...
 
None addPoint (float x, float y)
 Adds the point (x, y) to the current rectangle. More...
 
None addMargin (float width, float height)
 Extends the rectangle by adding a margin with the specified width and height. More...
 
None addRectangle (Rectangle2D rect)
 Adds the rectangle rect to the current rectangle. More...
 
bool containsPoint (Math.Vector2D pt)
 Tests if the point pt is within the boundary of the rectangle. More...
 
bool containsPoint (float x, float y)
 Tests if the point (x, y) is within the boundary of the rectangle. More...
 
bool containsRectangle (Rectangle2D rect)
 Tests if the specified rectangle rect is within the boundary of this rectangle. More...
 
bool intersectsRectangle (Rectangle2D rect)
 Tests if the interior of this rectangle intersects the rectangle rect. More...
 
None setMin (Math.Vector2D pt)
 Sets the minimum point of the rectangle to pt. More...
 
None setMin (float x, float y)
 Sets the minimum point of the rectangle to (x, y). More...
 
None setMax (Math.Vector2D pt)
 Sets the maximum point of the rectangle to pt. More...
 
None setMax (float x, float y)
 Sets the maximum point of the rectangle to (x, y). More...
 
None setBounds (Math.Vector2D min, Math.Vector2D max)
 Sets the minimum point of the rectangle to min and the maximum point to max. More...
 
None setBounds (float min_x, float min_y, float max_x, float max_y)
 Sets the minimum point of the rectangle to (min_x, min_y) and the maximum point to (max_x, max_y). More...
 
Math.Vector2D getMin ()
 Returns the minimum point of the rectangle. More...
 
Math.Vector2D getMax ()
 Returns the maximum point of the rectangle. More...
 
Math.Vector2D getCenter ()
 Calculates the center of the rectangle. More...
 
None getCenter (Math.Vector2D ctr)
 Calculates the center of the rectangle and stores the result in ctr. More...
 
float getArea ()
 Calculates the area of the rectangle. More...
 
float getWidth ()
 Returns the width of the rectangle. More...
 
float getHeight ()
 Returns the height of the rectangle. More...
 
None reset ()
 Resets the rectangle to an undefinded state. More...
 
None scale (float factor)
 Scales the minimum and maximum point of the rectangle by the specified factor. More...
 
None translate (Math.Vector2D vec)
 Translates the minimum and maximum point of the rectangle by vec. More...
 
str __str__ ()
 Returns a string representation of the Rectangle2D instance. More...
 
bool __eq__ (Rectangle2D rect)
 Equality comparison operator. More...
 
bool __ne__ (Rectangle2D rect)
 Inequality comparison operator. More...
 
bool __contains__ (Math.Vector2D pt)
 Returns the result of the membership test operation pt in self. More...
 
bool __contains__ (Rectangle2D rect)
 Returns the result of the membership test operation rect in self. More...
 

Properties

 objectID = property(getObjectID)
 
 defined = property(isDefined)
 
 min = property(getMin, setMin)
 
 max = property(getMax, setMax)
 
 center = property(getCenter)
 
 width = property(getWidth)
 
 height = property(getHeight)
 
 area = property(getArea)
 

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

◆ __init__() [1/4]

None CDPL.Vis.Rectangle2D.__init__ ( )

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

◆ __init__() [2/4]

None CDPL.Vis.Rectangle2D.__init__ ( Rectangle2D  rect)

Initializes a copy of the Rectangle2D instance rect.

Parameters
rectThe Rectangle2D instance to copy.

◆ __init__() [3/4]

None CDPL.Vis.Rectangle2D.__init__ ( Math.Vector2D  min,
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.

◆ __init__() [4/4]

None CDPL.Vis.Rectangle2D.__init__ ( float  min_x,
float  min_y,
float  max_x,
float  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.

Member Function Documentation

◆ getObjectID()

int CDPL.Vis.Rectangle2D.getObjectID ( )

Returns the numeric identifier (ID) of the wrapped C++ class instance.

Different Python Rectangle2D instances may reference the same underlying C++ class instance. The commonly used Python expression a is not b thus cannot tell reliably whether the two Rectangle2D instances a and b reference different C++ objects. The numeric identifier returned by this method allows to correctly implement such an identity test via the simple expression a.getObjectID() != b.getObjectID().

Returns
The numeric ID of the internally referenced C++ class instance.

◆ assign()

Rectangle2D CDPL.Vis.Rectangle2D.assign ( Rectangle2D  rect)

Replaces the current state of self with a copy of the state of the Rectangle2D instance rect.

Parameters
rectThe Rectangle2D instance to copy.
Returns
self

◆ isDefined()

bool CDPL.Vis.Rectangle2D.isDefined ( )

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]

None CDPL.Vis.Rectangle2D.addPoint ( 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]

None CDPL.Vis.Rectangle2D.addPoint ( float  x,
float  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()

None CDPL.Vis.Rectangle2D.addMargin ( float  width,
float  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()

None CDPL.Vis.Rectangle2D.addRectangle ( 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 ( Math.Vector2D  pt)

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 ( float  x,
float  y 
)

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 ( Rectangle2D  rect)

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 ( Rectangle2D  rect)

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]

None CDPL.Vis.Rectangle2D.setMin ( Math.Vector2D  pt)

Sets the minimum point of the rectangle to pt.

Parameters
ptThe new minimum point.

◆ setMin() [2/2]

None CDPL.Vis.Rectangle2D.setMin ( float  x,
float  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]

None CDPL.Vis.Rectangle2D.setMax ( Math.Vector2D  pt)

Sets the maximum point of the rectangle to pt.

Parameters
ptThe new maximum point.

◆ setMax() [2/2]

None CDPL.Vis.Rectangle2D.setMax ( float  x,
float  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]

None CDPL.Vis.Rectangle2D.setBounds ( Math.Vector2D  min,
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.

◆ setBounds() [2/2]

None CDPL.Vis.Rectangle2D.setBounds ( float  min_x,
float  min_y,
float  max_x,
float  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.

◆ getMin()

Math.Vector2D CDPL.Vis.Rectangle2D.getMin ( )

Returns the minimum point of the rectangle.

Returns
The minimum point of the rectangle.

◆ getMax()

Math.Vector2D CDPL.Vis.Rectangle2D.getMax ( )

Returns the maximum point of the rectangle.

Returns
The maximum point of the rectangle.

◆ getCenter() [1/2]

Math.Vector2D CDPL.Vis.Rectangle2D.getCenter ( )

Calculates the center of the rectangle.

Returns
The center of the rectangle.

◆ getCenter() [2/2]

None CDPL.Vis.Rectangle2D.getCenter ( Math.Vector2D  ctr)

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

Parameters
ctrA vector storing the calculated center point.

◆ getArea()

float CDPL.Vis.Rectangle2D.getArea ( )

Calculates the area of the rectangle.

Returns
The calculated area of the rectangle.

◆ getWidth()

float CDPL.Vis.Rectangle2D.getWidth ( )

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

float CDPL.Vis.Rectangle2D.getHeight ( )

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.

◆ reset()

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

◆ scale()

None CDPL.Vis.Rectangle2D.scale ( float  factor)

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

Parameters
factorThe scaling factor.

◆ translate()

None CDPL.Vis.Rectangle2D.translate ( Math.Vector2D  vec)

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

Parameters
vecThe translation vector.

◆ __str__()

str CDPL.Vis.Rectangle2D.__str__ ( )

Returns a string representation of the Rectangle2D instance.

Returns
The generated string representation.

◆ __eq__()

bool CDPL.Vis.Rectangle2D.__eq__ ( Rectangle2D  rect)

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.

◆ __ne__()

bool CDPL.Vis.Rectangle2D.__ne__ ( Rectangle2D  rect)

Inequality comparison operator.

The result is equivalent to !(self == 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.

◆ __contains__() [1/2]

bool CDPL.Vis.Rectangle2D.__contains__ ( Math.Vector2D  pt)

Returns the result of the membership test operation pt in self.

Parameters
ptThe value to test for membership.
Returns
The result of the membership test operation.

◆ __contains__() [2/2]

bool CDPL.Vis.Rectangle2D.__contains__ ( Rectangle2D  rect)

Returns the result of the membership test operation rect in self.

Parameters
rectThe value to test for membership.
Returns
The result of the membership test operation.