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

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

#include <Line2D.hpp>

+ Inheritance diagram for CDPL::Vis::Line2D:

Public Member Functions

 Line2D ()
 Constructs a line whose starting and end point is set to (0, 0). More...
 
 Line2D (const Math::Vector2D &beg, const Math::Vector2D &end)
 Constructs a line with the specified starting and end point. More...
 
 Line2D (double beg_x, double beg_y, double end_x, double 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...
 
virtual ~Line2D ()
 Virtual destructor. More...
 
void setBegin (const Math::Vector2D &pt)
 Sets the starting point of the line to pt. More...
 
void setBegin (double x, double y)
 Sets the starting point of the line to (x, y). More...
 
const Math::Vector2DgetBegin () const
 Returns the starting point of the line. More...
 
void setEnd (const Math::Vector2D &pt)
 Sets the end point of the line to pt. More...
 
void setEnd (double x, double y)
 Sets the end point of the line to (x, y). More...
 
const Math::Vector2DgetEnd () const
 Returns the end point of the line. More...
 
void setPoints (double beg_x, double beg_y, double end_x, double end_y)
 Sets the starting point of the line to (beg_x, beg_y) and the end point to (end_x, end_y). More...
 
void setPoints (const Math::Vector2D &beg, const Math::Vector2D &end)
 Sets the starting point of the line to beg and the end point to end. More...
 
void swapPoints ()
 Swaps the starting and end point of the line. More...
 
void getDirection (Math::Vector2D &dir) const
 Calculates the normalized direction vector of the line and stores the result in dir. More...
 
Math::Vector2D getDirection () const
 Calculates the normalized direction vector of the line. More...
 
void getCCWPerpDirection (Math::Vector2D &dir) const
 Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction and stores the result in dir. More...
 
Math::Vector2D getCCWPerpDirection () const
 Calculates the normalized direction vector rotated by 90 degrees in counter-clockwise direction. More...
 
void getCWPerpDirection (Math::Vector2D &dir) const
 Calculates the normalized direction vector rotated by 90 degrees in clockwise direction and stores the result in dir. More...
 
Math::Vector2D getCWPerpDirection () const
 Calculates the normalized direction vector rotated by 90 degrees in clockwise direction. More...
 
void getCenter (Math::Vector2D &ctr) const
 Calculates the center point of the line and stores the result in ctr. More...
 
Math::Vector2D getCenter () const
 Calculates the center point of the line. More...
 
double getLength () const
 Returns the length of the line segment. More...
 
void translate (const Math::Vector2D &vec)
 Translates the starting and end point of the line by vec. More...
 
void translateBegin (const Math::Vector2D &vec)
 Translates the starting point of the line by vec. More...
 
void translateEnd (const Math::Vector2D &vec)
 Translates the end of the line point by vec. More...
 
bool containsPoint (const Math::Vector2D &pt) const
 Tests if the point pt is contained within the boundary of the line segment. More...
 
bool getIntersectionPoint (const Line2D &line, Math::Vector2D &pt) const
 Calculates the point of intersection with the specified line and stores the result in pt. More...
 
bool clipBeginAgainstLineSeg (const Line2D &line)
 Sets the starting point of the line to the point of intersection with the specified line segment. More...
 
bool clipEndAgainstLineSeg (const Line2D &line)
 Sets the end point of the line to the point of intersection with the specified line segment. More...
 
bool setBeginToLineSegIntersection (const Line2D &line)
 Sets the starting point of the line to the point of intersection with the specified line segment. More...
 
bool setEndToLineSegIntersection (const Line2D &line)
 Sets the end point of the line to the point of intersection with the specified line segment. More...
 
bool clipBeginAgainstRectangle (const 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 (const 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...
 
double getDistance (const Math::Vector2D &pt) const
 Returns the perpendicular distance of the point pt to this line. More...
 
bool operator== (const Line2D &line) const
 Equality comparison operator. More...
 
bool operator!= (const Line2D &line) const
 Inequality comparison operator. More...
 

Detailed Description

Specifies a line segment in 2D space.

Constructor & Destructor Documentation

◆ Line2D() [1/3]

CDPL::Vis::Line2D::Line2D ( )

Constructs a line whose starting and end point is set to (0, 0).

◆ Line2D() [2/3]

CDPL::Vis::Line2D::Line2D ( const Math::Vector2D beg,
const Math::Vector2D end 
)

Constructs a line with the specified starting and end point.

Parameters
begThe starting point.
endThe end point.

◆ Line2D() [3/3]

CDPL::Vis::Line2D::Line2D ( double  beg_x,
double  beg_y,
double  end_x,
double  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.

◆ ~Line2D()

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

Virtual destructor.

Member Function Documentation

◆ setBegin() [1/2]

void CDPL::Vis::Line2D::setBegin ( const Math::Vector2D pt)

Sets the starting point of the line to pt.

Parameters
ptThe new starting point of the line.

◆ setBegin() [2/2]

void CDPL::Vis::Line2D::setBegin ( double  x,
double  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()

const Math::Vector2D& CDPL::Vis::Line2D::getBegin ( ) const

Returns the starting point of the line.

Returns
The starting point of the line.

◆ setEnd() [1/2]

void CDPL::Vis::Line2D::setEnd ( const Math::Vector2D pt)

Sets the end point of the line to pt.

Parameters
ptThe new end point of the line.

◆ setEnd() [2/2]

void CDPL::Vis::Line2D::setEnd ( double  x,
double  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()

const Math::Vector2D& CDPL::Vis::Line2D::getEnd ( ) const

Returns the end point of the line.

Returns
The end point of the line.

◆ setPoints() [1/2]

void CDPL::Vis::Line2D::setPoints ( double  beg_x,
double  beg_y,
double  end_x,
double  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.

◆ setPoints() [2/2]

void CDPL::Vis::Line2D::setPoints ( const Math::Vector2D beg,
const 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.

◆ swapPoints()

void 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]

void CDPL::Vis::Line2D::getDirection ( Math::Vector2D dir) const

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

Parameters
dirHolds the calculated direction vector.

◆ getDirection() [2/2]

Math::Vector2D CDPL::Vis::Line2D::getDirection ( ) const

Calculates the normalized direction vector of the line.

Returns
The calculated direction vector.

◆ getCCWPerpDirection() [1/2]

void CDPL::Vis::Line2D::getCCWPerpDirection ( Math::Vector2D dir) const

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.

◆ getCCWPerpDirection() [2/2]

Math::Vector2D CDPL::Vis::Line2D::getCCWPerpDirection ( ) const

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

Returns
The calculated rotated direction vector.

◆ getCWPerpDirection() [1/2]

void CDPL::Vis::Line2D::getCWPerpDirection ( Math::Vector2D dir) const

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.

◆ getCWPerpDirection() [2/2]

Math::Vector2D CDPL::Vis::Line2D::getCWPerpDirection ( ) const

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

Returns
The calculated rotated direction vector.

◆ getCenter() [1/2]

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

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

Parameters
ctrHolds the calculated center point of the line.

◆ getCenter() [2/2]

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

Calculates the center point of the line.

Returns
The calculated center point of the line.

◆ getLength()

double CDPL::Vis::Line2D::getLength ( ) const

Returns the length of the line segment.

Returns
The length of the line segment.

◆ translate()

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

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

Parameters
vecThe translation vector.

◆ translateBegin()

void CDPL::Vis::Line2D::translateBegin ( const Math::Vector2D vec)

Translates the starting point of the line by vec.

Parameters
vecThe translation vector.

◆ translateEnd()

void CDPL::Vis::Line2D::translateEnd ( const Math::Vector2D vec)

Translates the end of the line point by vec.

Parameters
vecThe translation vector.

◆ containsPoint()

bool CDPL::Vis::Line2D::containsPoint ( const Math::Vector2D pt) const

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

bool CDPL::Vis::Line2D::getIntersectionPoint ( const Line2D line,
Math::Vector2D pt 
) const

Calculates the point of intersection with the specified line and stores the result in pt.

Parameters
lineThe other line for which the point of intersection will be calculated.
ptHolds the calculated intersection point.
Returns
false if the two lines are parallel, and true otherwise.

◆ clipBeginAgainstLineSeg()

bool CDPL::Vis::Line2D::clipBeginAgainstLineSeg ( const 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 ( const 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 ( const 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 ( const 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 ( const 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 ( const 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()

double CDPL::Vis::Line2D::getDistance ( const Math::Vector2D pt) const

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.

◆ operator==()

bool CDPL::Vis::Line2D::operator== ( const Line2D line) const

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.

◆ operator!=()

bool CDPL::Vis::Line2D::operator!= ( const Line2D line) const

Inequality comparison operator.

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

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