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

Provides a container for painting operations, enabling arbitrary graphical shapes to be constructed and reused. More...

#include <Path2D.hpp>

+ Inheritance diagram for CDPL::Vis::Path2D:

Public Types

enum  FillRule {
  EVEN_ODD,
  WINDING
}
 Specifies which method to use for filling closed shapes described by the Path2D object. More...
 

Public Member Functions

 Path2D ()
 Constructs an empty Path2D instance. More...
 
 Path2D (const Path2D &path)
 Constructs a copy of the Path2D instance path. More...
 
virtual ~Path2D ()
 Virtual destructor. More...
 
bool isEmpty () const
 Tells whether the Path2D instance does not contain any elements. More...
 
bool hasDrawingElements () const
 Tells whether the Path2D instance contains any elements representing drawing operations (lines and arcs). More...
 
void clear ()
 Deletes all path elements added so far and sets the fill rule to its default. More...
 
void setFillRule (FillRule rule)
 Sets the fill rule of the path to the specified value. More...
 
FillRule getFillRule () const
 Returns the currently set fill rule. More...
 
void moveTo (double x, double y)
 Sets the current position to (x, y) and starts a new subpath, implicitly closing the previous path. More...
 
void moveTo (const Math::Vector2D &pos)
 Sets the current position to pos and starts a new subpath, implicitly closing the previous path. More...
 
void arc (double cx, double cy, double rx, double ry, double start_ang, double sweep)
 Creates an elliptical arc centered at (cx, cy) with ellipse radii rx and ry beginning at the angle start_ang and extending sweep degrees clockwise. More...
 
void arc (const Math::Vector2D &ctr, double rx, double ry, double start_ang, double sweep)
 Creates an elliptical arc centered at ctr with ellipse radii rx and ry beginning at the angle start_ang and extending sweep degrees clockwise. More...
 
void arcTo (double cx, double cy, double rx, double ry, double start_ang, double sweep)
 Creates an elliptical arc centered at (cx, cy) with ellipse radii rx and ry beginning at the angle start_ang and extending sweep degrees clockwise. More...
 
void arcTo (const Math::Vector2D &ctr, double rx, double ry, double start_ang, double sweep)
 Creates an elliptical arc centered at ctr with ellipse radii rx and ry beginning at the angle start_ang and extending sweep degrees clockwise. More...
 
void lineTo (double x, double y)
 Adds a straight line from the current position to the point (x, y). More...
 
void lineTo (const Math::Vector2D &pos)
 Adds a straight line from the current position to the point (x, y). More...
 
void closePath ()
 Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting a new path. More...
 
void addEllipse (double x, double y, double width, double height)
 Creates an ellipse positioned at (x, y) with the specified width and height, and adds it to this path as a closed subpath. More...
 
void addEllipse (const Math::Vector2D &pos, double width, double height)
 Creates an ellipse positioned at pos with the specified width and height, and adds it to this path as a closed subpath. More...
 
void addRectangle (double x, double y, double width, double height)
 Creates a rectangle positioned at (x, y) with the specified width and height, and adds it to this path as a closed subpath. More...
 
void addRectangle (const Math::Vector2D &pos, double width, double height)
 Creates a rectangle positioned at pos with the specified width and height, and adds it to this path as a closed subpath. More...
 
void getBounds (Rectangle2D &bounds) const
 Calculates the axis-aligned bounding box of the path. More...
 
void convert (Path2DConverter &conv) const
 Iterates over the stored path elements and calls the corresponding method of conv for each visited element. More...
 
bool operator== (const Path2D &path) const
 Equality comparison operator. More...
 
bool operator!= (const Path2D &path) const
 Non-equality comparison operator. More...
 
Path2Doperator+= (const Path2D &path)
 Appends the elements stored in the Path2D instance path to this path. More...
 
Path2Doperator= (const Path2D &path)
 Assignment operator. More...
 

Detailed Description

Provides a container for painting operations, enabling arbitrary graphical shapes to be constructed and reused.

A path consits of a number of graphical building blocks, such as rectangles, ellipses, lines and arcs. Building blocks can be joined to form closed subpaths, for example a rounded rectangle, or they can exist independently as unclosed subpaths, such as lines and curves. A closed path has coinciding start and end points.

Path2D objects can be used for filling, outlining, and clipping. The main advantage over a sequence of basic drawing operations is that complex shapes need to be created only once and can be stored for repeated later uses.

A Path2D object can be constructed as an empty path, or as a copy of another Path2D instance. Once created, lines and curves can be added to the path using the lineTo(), arcTo() and arc() functions. The lines and curves stretch from the current position to the position passed as argument. The current position is always the end point of the last drawing operation. Use the moveTo() method to move the current position without adding a component. The moveTo() method implicitly starts a new subpath, and closes the previous one. Another way of starting a new subpath is to call the closePath() method which closes the current path by adding a line from the current position back to the path's start position. The Path2D class also provides convenience methods for the generation of common shapes: addEllipse() and addRectangle(). The generation of these shapes is implemented by executing a sequence of appropriate moveTo(), lineTo() and arcTo() calls. The axis-aligned bounding box of a path constructed in this way can be calculated by the method getBounds().

Whether or not a Path2D object contains any elements can be queried by the method isEmpty(). Whether the path also features visual elements (lines and arcs) can be queried by the method hasDrawingElements(). The method clear() deletes all elements added so far and sets the default fill rule (see setFillRule() and getFillRule()).

Elements added to a Path2D object cannot inspected directly. For path analysis and rendering the method convert() is available which calls element type specific methods on a provided instance of a class implementing the Vis::Path2DConverter interface.

Since
1.1

Member Enumeration Documentation

◆ FillRule

Specifies which method to use for filling closed shapes described by the Path2D object.

Enumerator
EVEN_ODD 

Specifies that the path has to be filled using the odd even fill rule.

With this rule, the question whether a point is inside the shape can be answered by the following method: Draw a horizontal line from the point to a location outside the shape, and count the number of intersections. If the number of intersections is an odd number, the point is inside the shape.

WINDING 

Specifies that the path has to be filled using the non-zero winding rule.

With this rule, the question whether a point is inside the shape can be answered by the following method: Draw a horizontal line from the point to a location outside the shape. Determine whether the direction of the line at each intersection point is up or down. The winding number is determined by summing the direction of each intersection. If the number is non-zero, the point is inside the shape.

Constructor & Destructor Documentation

◆ Path2D() [1/2]

CDPL::Vis::Path2D::Path2D ( )

Constructs an empty Path2D instance.

◆ Path2D() [2/2]

CDPL::Vis::Path2D::Path2D ( const Path2D path)

Constructs a copy of the Path2D instance path.

Parameters
pathThe Path2D instance to copy.

◆ ~Path2D()

virtual CDPL::Vis::Path2D::~Path2D ( )
virtual

Virtual destructor.

Member Function Documentation

◆ isEmpty()

bool CDPL::Vis::Path2D::isEmpty ( ) const

Tells whether the Path2D instance does not contain any elements.

Returns
true is no elements have been added to the Path2D instance so far, and false otherwise.

◆ hasDrawingElements()

bool CDPL::Vis::Path2D::hasDrawingElements ( ) const

Tells whether the Path2D instance contains any elements representing drawing operations (lines and arcs).

Returns
true if the Path2D instance contains any visual elements, and false otherwise.

◆ clear()

void CDPL::Vis::Path2D::clear ( )

Deletes all path elements added so far and sets the fill rule to its default.

See also
setFillRule()

◆ setFillRule()

void CDPL::Vis::Path2D::setFillRule ( FillRule  rule)

Sets the fill rule of the path to the specified value.

Parameters
ruleThe new fill rule.
Note
The default fill rule is Path2D::EVEN_ODD.

◆ getFillRule()

FillRule CDPL::Vis::Path2D::getFillRule ( ) const

Returns the currently set fill rule.

Returns
The currently set fill rule.

◆ moveTo() [1/2]

void CDPL::Vis::Path2D::moveTo ( double  x,
double  y 
)

Sets the current position to (x, y) and starts a new subpath, implicitly closing the previous path.

Parameters
xSpecifies the x-coordinate of the new position.
ySpecifies the y-coordinate of the new position.

◆ moveTo() [2/2]

void CDPL::Vis::Path2D::moveTo ( const Math::Vector2D pos)

Sets the current position to pos and starts a new subpath, implicitly closing the previous path.

Parameters
posA 2D vector specifying the new position.

◆ arc() [1/2]

void CDPL::Vis::Path2D::arc ( double  cx,
double  cy,
double  rx,
double  ry,
double  start_ang,
double  sweep 
)

Creates an elliptical arc centered at (cx, cy) with ellipse radii rx and ry beginning at the angle start_ang and extending sweep degrees clockwise.

Angles are specified in degrees. Counter-clockwise arcs can be specified using negative angles. After the arc has been added, the current position is the end point of the arc. To draw a line back to the first point, use the closePath() method.

Parameters
cxThe x-coordinate of the ellipse center.
cyThe y-coordinate of the ellipse center.
rxThe x-radius of the ellipse.
ryThe y-radius of the ellipse.
start_angThe start angle of the arg in degrees.
sweepThe length of the arg in degrees.
Note
The method first performs a moveTo() call with the starting point of the arc as argument and thus avoids an implicit line being drawn from the current position to the arc's starting position (see arcTo()).

◆ arc() [2/2]

void CDPL::Vis::Path2D::arc ( const Math::Vector2D ctr,
double  rx,
double  ry,
double  start_ang,
double  sweep 
)

Creates an elliptical arc centered at ctr with ellipse radii rx and ry beginning at the angle start_ang and extending sweep degrees clockwise.

Angles are specified in degrees. Counter-clockwise arcs can be specified using negative angles. After the arc has been added, the current position is the end point of the arc. To draw a line back to the first point, use the closePath() method.

Parameters
ctrA 2D vector specifying the ellipse center.
rxThe x-radius of the ellipse.
ryThe y-radius of the ellipse.
start_angThe start angle of the arg in degrees.
sweepThe length of the arg in degrees.
Note
The method first performs a moveTo() call with the starting point of the arc as argument and thus avoids an implicit line being drawn from the current position to the arc's starting position (see arcTo()).

◆ arcTo() [1/2]

void CDPL::Vis::Path2D::arcTo ( double  cx,
double  cy,
double  rx,
double  ry,
double  start_ang,
double  sweep 
)

Creates an elliptical arc centered at (cx, cy) with ellipse radii rx and ry beginning at the angle start_ang and extending sweep degrees clockwise.

Angles are specified in degrees. Counter-clockwise arcs can be specified using negative angles. After the arc has been added, the current position is the end point of the arc. To draw a line back to the first point, use the closePath() method.

Parameters
cxThe x-coordinate of the ellipse center.
cyThe y-coordinate of the ellipse center.
rxThe x-radius of the ellipse.
ryThe y-radius of the ellipse.
start_angThe start angle of the arg in degrees.
sweepThe length of the arg in degrees.
Note
The method implicitly connects the starting point of the arc to the current position if they are not already connected. The rendering result is undefined if no subpath starting point has been specified (see moveTo())!

◆ arcTo() [2/2]

void CDPL::Vis::Path2D::arcTo ( const Math::Vector2D ctr,
double  rx,
double  ry,
double  start_ang,
double  sweep 
)

Creates an elliptical arc centered at ctr with ellipse radii rx and ry beginning at the angle start_ang and extending sweep degrees clockwise.

Angles are specified in degrees. Counter-clockwise arcs can be specified using negative angles. After the arc has been added, the current position is the end point of the arc. To draw a line back to the first point, use the closePath() method.

Parameters
ctrA 2D vector specifying the ellipse center.
rxThe x-radius of the ellipse.
ryThe y-radius of the ellipse.
start_angThe start angle of the arg in degrees.
sweepThe length of the arg in degrees.
Note
The method implicitly connects the starting point of the arc to the current position if they are not already connected. The rendering result is undefined if no subpath starting point has been specified (see moveTo())!

◆ lineTo() [1/2]

void CDPL::Vis::Path2D::lineTo ( double  x,
double  y 
)

Adds a straight line from the current position to the point (x, y).

After the line is drawn, the current position is updated to be at the end point of the line.

Parameters
xSpecifies the x-coordinate of the line's end point.
ySpecifies the y-coordinate of the line's end point.
Note
The rendering result is undefined if no subpath starting point has been specified (see moveTo())!

◆ lineTo() [2/2]

void CDPL::Vis::Path2D::lineTo ( const Math::Vector2D pos)

Adds a straight line from the current position to the point (x, y).

After the line is drawn, the current position is updated to be at the end point of the line.

Parameters
posA 2D vector specifying the line end point.
Note
The rendering result is undefined if no subpath starting point has been specified (see moveTo())!

◆ closePath()

void CDPL::Vis::Path2D::closePath ( )

Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting a new path.

A call to this methods has no effect if the current subpath does not contain any elements.

Note
After closing the subpath the current point is undefined!

◆ addEllipse() [1/2]

void CDPL::Vis::Path2D::addEllipse ( double  x,
double  y,
double  width,
double  height 
)

Creates an ellipse positioned at (x, y) with the specified width and height, and adds it to this path as a closed subpath.

Parameters
xThe x-coordinate of the ellipse center.
yThe y-coordinate of the ellipse center.
widthThe width of the ellipse.
heightThe height of the ellipse.

◆ addEllipse() [2/2]

void CDPL::Vis::Path2D::addEllipse ( const Math::Vector2D pos,
double  width,
double  height 
)

Creates an ellipse positioned at pos with the specified width and height, and adds it to this path as a closed subpath.

Parameters
posA 2D vector specifying the ellipse center.
widthThe width of the ellipse.
heightThe height of the ellipse.

◆ addRectangle() [1/2]

void CDPL::Vis::Path2D::addRectangle ( double  x,
double  y,
double  width,
double  height 
)

Creates a rectangle positioned at (x, y) with the specified width and height, and adds it to this path as a closed subpath.

Parameters
xThe x-coordinate of the top-left corner.
yThe y-coordinate of the top-left corner.
widthThe width of the rectangle.
heightThe height of the rectangle.

◆ addRectangle() [2/2]

void CDPL::Vis::Path2D::addRectangle ( const Math::Vector2D pos,
double  width,
double  height 
)

Creates a rectangle positioned at pos with the specified width and height, and adds it to this path as a closed subpath.

Parameters
posA 2D vector specifying the top-left corner.
widthThe width of the rectangle.
heightThe height of the rectangle.

◆ getBounds()

void CDPL::Vis::Path2D::getBounds ( Rectangle2D bounds) const

Calculates the axis-aligned bounding box of the path.

Parameters
boundsThe Vis::Rectangle2D instance storing the calculated bounding box.

◆ convert()

void CDPL::Vis::Path2D::convert ( Path2DConverter conv) const

Iterates over the stored path elements and calls the corresponding method of conv for each visited element.

Parameters
convAn instance of a class implementing the Vis::Path2DConverter interface.

◆ operator==()

bool CDPL::Vis::Path2D::operator== ( const Path2D path) const

Equality comparison operator.

Parameters
pathThe Path2D instance to compare with.
Returns
true if this path is equal to path, and false otherwise.

◆ operator!=()

bool CDPL::Vis::Path2D::operator!= ( const Path2D path) const

Non-equality comparison operator.

Parameters
pathThe Path2D instance to compare with.
Returns
true if this path is not equal to path, and false otherwise.

◆ operator+=()

Path2D& CDPL::Vis::Path2D::operator+= ( const Path2D path)

Appends the elements stored in the Path2D instance path to this path.

Parameters
pathThe Path2D instance providing the elements to append.
Returns
A reference to itself.

◆ operator=()

Path2D& CDPL::Vis::Path2D::operator= ( const Path2D path)

Assignment operator.

Parameters
pathThe Path2D instance to copy.
Returns
A reference to itself.

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