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

Specifies a line segment in 2D space. More...

+ Inheritance diagram for CDPL.Vis.Line2D:

Public Member Functions

None __init__ ()
 Constructs a line whose starting and end point is set to (0, 0).
 
None __init__ (Line2D line)
 Initializes a copy of the Line2D instance line. More...
 
None __init__ (Math.Vector2D beg, Math.Vector2D end)
 Constructs a line with the specified starting and end point. More...
 
None __init__ (float beg_x, float beg_y, float end_x, float end_y)
 Constructs a line with the starting point set to (beg_x, beg_y) and the end point set to (end_x, end_y). More...
 
int getObjectID ()
 Returns the numeric identifier (ID) of the wrapped C++ class instance. More...
 
Line2D assign (Line2D line)
 Replaces the current state of self with a copy of the state of the Line2D instance line. More...
 
None setBegin (Math.Vector2D pt)
 Sets the starting point of the line to pt. More...
 
None setBegin (float x, float y)
 Sets the starting point of the line to (x, y). More...
 
Math.Vector2D getBegin ()
 Returns the starting point of the line. More...
 
None setEnd (Math.Vector2D pt)
 Sets the end point of the line to pt. More...
 
None setEnd (float x, float y)
 Sets the end point of the line to (x, y). More...
 
Math.Vector2D getEnd ()
 Returns the end point of the line. More...
 
None setPoints (Math.Vector2D beg, Math.Vector2D end)
 Sets the starting point of the line to beg and the end point to end. More...
 
None setPoints (float beg_x, float beg_y, float end_x, float end_y)
 Sets the starting point of the line to (beg_x, beg_y) and the end point to (end_x, end_y). More...
 
None swapPoints ()
 Swaps the starting and end point of the line. More...
 
Math.Vector2D getDirection ()
 Calculates the normalized direction vector of the line. More...
 
None getDirection (Math.Vector2D dir)
 Calculates the normalized direction vector of the line and stores the result in dir. More...
 
Math.Vector2D getCCWPerpDirection ()
 Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction. More...
 
None getCCWPerpDirection (Math.Vector2D dir)
 Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction and stores the result in dir. More...
 
Math.Vector2D getCWPerpDirection ()
 Calculates the normalized direction vector rotated by 90 degrees in clockwise direction. More...
 
None getCWPerpDirection (Math.Vector2D dir)
 Calculates the normalized direction vector rotated by 90 degrees in clockwise direction and stores the result in dir. More...
 
Math.Vector2D getCenter ()
 Calculates the center point of the line. More...
 
None getCenter (Math.Vector2D ctr)
 Calculates the center point of the line and stores the result in ctr. More...
 
float getLength ()
 Returns the length of the line segment. More...
 
None translate (Math.Vector2D vec)
 Translates the starting and end point of the line by vec. More...
 
None translateBegin (Math.Vector2D vec)
 Translates the starting point of the line by vec. More...
 
None translateEnd (Math.Vector2D vec)
 Translates the end of the line point by vec. More...
 
bool containsPoint (Math.Vector2D pt)
 Tests if the point pt is contained within the boundary of the line segment. More...
 
object getIntersectionPoint (Line2D pt)
 
bool clipBeginAgainstLineSeg (Line2D line)
 Sets the starting point of the line to the point of intersection with the specified line segment. More...
 
bool clipEndAgainstLineSeg (Line2D line)
 Sets the end point of the line to the point of intersection with the specified line segment. More...
 
bool setBeginToLineSegIntersection (Line2D line)
 Sets the starting point of the line to the point of intersection with the specified line segment. More...
 
bool setEndToLineSegIntersection (Line2D line)
 Sets the end point of the line to the point of intersection with the specified line segment. More...
 
bool clipBeginAgainstRectangle (Rectangle2D rect)
 Sets the starting point of the line to the point of intersection between this line segment and the edges of the rectangle rect. More...
 
bool clipEndAgainstRectangle (Rectangle2D rect)
 Sets the end point of the line to the point of intersection between this line segment and the edges of the rectangle rect. More...
 
float getDistance (Math.Vector2D pt)
 Returns the perpendicular distance of the point pt to this line. More...
 
bool __eq__ (Line2D line)
 Equality comparison operator. More...
 
bool __ne__ (Line2D line)
 Inequality comparison operator. More...
 
bool __contains__ (Math.Vector2D pt)
 Returns the result of the membership test operation pt in self. More...
 

Properties

 objectID = property(getObjectID)
 
 length = property(getLength)
 
 begin = property(getBegin, setBegin)
 
 end = property(getEnd, setEnd)
 
 direction = property(getDirection)
 
 ccwPerpDirection = property(getCCWPerpDirection)
 
 cwPerpDirection = property(getCWPerpDirection)
 
 center = property(getCenter)
 

Detailed Description

Specifies a line segment in 2D space.

Constructor & Destructor Documentation

◆ __init__() [1/3]

None CDPL.Vis.Line2D.__init__ ( Line2D  line)

Initializes a copy of the Line2D instance line.

Parameters
lineThe Line2D instance to copy.

Reimplemented in CDPL.Vis.LinePrimitive2D.

◆ __init__() [2/3]

None CDPL.Vis.Line2D.__init__ ( Math.Vector2D  beg,
Math.Vector2D  end 
)

Constructs a line with the specified starting and end point.

Parameters
begThe starting point.
endThe end point.

Reimplemented in CDPL.Vis.LinePrimitive2D.

◆ __init__() [3/3]

None CDPL.Vis.Line2D.__init__ ( float  beg_x,
float  beg_y,
float  end_x,
float  end_y 
)

Constructs a line with the starting point set to (beg_x, beg_y) and the end point set to (end_x, end_y).

Parameters
beg_xThe x-coordinate of the starting point.
beg_yThe y-coordinate of the starting point.
end_xThe x-coordinate of the end point.
end_yThe y-coordinate of the end point.

Member Function Documentation

◆ getObjectID()

int CDPL.Vis.Line2D.getObjectID ( )

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

Different Python Line2D 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 Line2D 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()

Line2D CDPL.Vis.Line2D.assign ( Line2D  line)

Replaces the current state of self with a copy of the state of the Line2D instance line.

Parameters
lineThe Line2D instance to copy.
Returns
self

◆ setBegin() [1/2]

None CDPL.Vis.Line2D.setBegin ( Math.Vector2D  pt)

Sets the starting point of the line to pt.

Parameters
ptThe new starting point of the line.

◆ setBegin() [2/2]

None CDPL.Vis.Line2D.setBegin ( float  x,
float  y 
)

Sets the starting point of the line to (x, y).

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

◆ getBegin()

Math.Vector2D CDPL.Vis.Line2D.getBegin ( )

Returns the starting point of the line.

Returns
The starting point of the line.

◆ setEnd() [1/2]

None CDPL.Vis.Line2D.setEnd ( Math.Vector2D  pt)

Sets the end point of the line to pt.

Parameters
ptThe new end point of the line.

◆ setEnd() [2/2]

None CDPL.Vis.Line2D.setEnd ( float  x,
float  y 
)

Sets the end point of the line to (x, y).

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

◆ getEnd()

Math.Vector2D CDPL.Vis.Line2D.getEnd ( )

Returns the end point of the line.

Returns
The end point of the line.

◆ setPoints() [1/2]

None CDPL.Vis.Line2D.setPoints ( Math.Vector2D  beg,
Math.Vector2D  end 
)

Sets the starting point of the line to beg and the end point to end.

Parameters
begThe new starting point.
endThe new end point.

◆ setPoints() [2/2]

None CDPL.Vis.Line2D.setPoints ( float  beg_x,
float  beg_y,
float  end_x,
float  end_y 
)

Sets the starting point of the line to (beg_x, beg_y) and the end point to (end_x, end_y).

Parameters
beg_xThe x-coordinate of the new starting point.
beg_yThe y-coordinate of the new starting point.
end_xThe x-coordinate of the new end point.
end_yThe y-coordinate of the new end point.

◆ swapPoints()

None CDPL.Vis.Line2D.swapPoints ( )

Swaps the starting and end point of the line.

The old starting point becomes the new end point and the old end point becomes the new starting point.

◆ getDirection() [1/2]

Math.Vector2D CDPL.Vis.Line2D.getDirection ( )

Calculates the normalized direction vector of the line.

Returns
The calculated direction vector.

◆ getDirection() [2/2]

None CDPL.Vis.Line2D.getDirection ( Math.Vector2D  dir)

Calculates the normalized direction vector of the line and stores the result in dir.

Parameters
dirHolds the calculated direction vector.

◆ getCCWPerpDirection() [1/2]

Math.Vector2D CDPL.Vis.Line2D.getCCWPerpDirection ( )

Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction.

Returns
The calculated rotated direction vector.

◆ getCCWPerpDirection() [2/2]

None CDPL.Vis.Line2D.getCCWPerpDirection ( Math.Vector2D  dir)

Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction and stores the result in dir.

Parameters
dirHolds the calculated rotated direction vector.

◆ getCWPerpDirection() [1/2]

Math.Vector2D CDPL.Vis.Line2D.getCWPerpDirection ( )

Calculates the normalized direction vector rotated by 90 degrees in clockwise direction.

Returns
The calculated rotated direction vector.

◆ getCWPerpDirection() [2/2]

None CDPL.Vis.Line2D.getCWPerpDirection ( Math.Vector2D  dir)

Calculates the normalized direction vector rotated by 90 degrees in clockwise direction and stores the result in dir.

Parameters
dirHolds the calculated rotated direction vector.

◆ getCenter() [1/2]

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

Calculates the center point of the line.

Returns
The calculated center point of the line.

◆ getCenter() [2/2]

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

Calculates the center point of the line and stores the result in ctr.

Parameters
ctrHolds the calculated center point of the line.

◆ getLength()

float CDPL.Vis.Line2D.getLength ( )

Returns the length of the line segment.

Returns
The length of the line segment.

◆ translate()

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

Translates the starting and end point of the line by vec.

Parameters
vecThe translation vector.

◆ translateBegin()

None CDPL.Vis.Line2D.translateBegin ( Math.Vector2D  vec)

Translates the starting point of the line by vec.

Parameters
vecThe translation vector.

◆ translateEnd()

None CDPL.Vis.Line2D.translateEnd ( Math.Vector2D  vec)

Translates the end of the line point by vec.

Parameters
vecThe translation vector.

◆ containsPoint()

bool CDPL.Vis.Line2D.containsPoint ( Math.Vector2D  pt)

Tests if the point pt is contained within the boundary of the line segment.

The point pt is considered to be contained within the boundary of the line segment if the dot product of the line's direction vector and the vector from the starting point to pt is positive or zero, and furthermore the dot product of the direction vector and the vector from the end point to pt is negative or zero.

Parameters
ptThe point to test.
Returns
True if pt is contained within the boundary of the line segment, and False otherwise.

◆ getIntersectionPoint()

object CDPL.Vis.Line2D.getIntersectionPoint ( Line2D  pt)
Parameters
pt
Returns

◆ clipBeginAgainstLineSeg()

bool CDPL.Vis.Line2D.clipBeginAgainstLineSeg ( Line2D  line)

Sets the starting point of the line to the point of intersection with the specified line segment.

If the lines are parallel or the point of intersection is not within the boundaries of both line segments, the starting point of the line is left unaltered and False is returned.

Parameters
lineThe other line segment to clip against.
Returns
False if the lines are parallel or the intersection point is not within the boundaries of both line segments, and True otherwise.

◆ clipEndAgainstLineSeg()

bool CDPL.Vis.Line2D.clipEndAgainstLineSeg ( Line2D  line)

Sets the end point of the line to the point of intersection with the specified line segment.

If the lines are parallel or the point of intersection is not within the boundaries of both line segments, the end point of the line is left unaltered and False is returned.

Parameters
lineThe other line segment to clip against.
Returns
False if the lines are parallel or the intersection point is not within the boundaries of both line segments, and True otherwise.

◆ setBeginToLineSegIntersection()

bool CDPL.Vis.Line2D.setBeginToLineSegIntersection ( Line2D  line)

Sets the starting point of the line to the point of intersection with the specified line segment.

If the lines are parallel or the point of intersection is not within the boundary of the line segment line, the starting point of the line is left unaltered and False is returned.

Parameters
lineThe other line segment.
Returns
False if the lines are parallel or the intersection point is not within the boundary of line, and True otherwise.

◆ setEndToLineSegIntersection()

bool CDPL.Vis.Line2D.setEndToLineSegIntersection ( Line2D  line)

Sets the end point of the line to the point of intersection with the specified line segment.

If the lines are parallel or the point of intersection is not within the boundary of the line segment line, the end point of the line is left unaltered and False is returned.

Parameters
lineThe other line segment.
Returns
False if the lines are parallel or the intersection point is not within the boundary of line, and True otherwise.

◆ clipBeginAgainstRectangle()

bool CDPL.Vis.Line2D.clipBeginAgainstRectangle ( Rectangle2D  rect)

Sets the starting point of the line to the point of intersection between this line segment and the edges of the rectangle rect.

If the line segment intersects with more than one edge of rect, the starting point is set to the intersection point which results in the shortest clipped line segment. If the line segment does not intersect with an edge of rect, the starting point is left unaltered and False is returned.

Parameters
rectThe rectangle to clip againts.
Returns
True if the line segment was clipped against an edge of rect, and False otherwise.

◆ clipEndAgainstRectangle()

bool CDPL.Vis.Line2D.clipEndAgainstRectangle ( Rectangle2D  rect)

Sets the end point of the line to the point of intersection between this line segment and the edges of the rectangle rect.

If the line segment intersects with more than one edge of rect, the end point is set to the intersection point which results in the shortest clipped line segment. If the line segment does not intersect with an edge of rect, the end point is left unaltered and False is returned.

Parameters
rectThe rectangle to clip againts.
Returns
True if the line segment was clipped against an edge of rect, and False otherwise.

◆ getDistance()

float CDPL.Vis.Line2D.getDistance ( Math.Vector2D  pt)

Returns the perpendicular distance of the point pt to this line.

The measured distance is the distance between the point pt and the closest point on the infinitely extended line. If pt intersects the line, the method returns 0.0.

Parameters
ptThe point for which to calculate the shortest distance.
Returns
The shortest distance between pt and the infinitely extended line.

◆ __eq__()

bool CDPL.Vis.Line2D.__eq__ ( Line2D  line)

Equality comparison operator.

Parameters
lineThe other Line2D object to be compared with.
Returns
True if the starting and end points compare equal, and False otherwise.

◆ __ne__()

bool CDPL.Vis.Line2D.__ne__ ( Line2D  line)

Inequality comparison operator.

The result is equivalent to !(self == line).

Parameters
lineThe other Line2D object to be compared with.
Returns
True if either the starting or end points compare non-equal, and False otherwise.

◆ __contains__()

bool CDPL.Vis.Line2D.__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.