Chemical Data Processing Library C++ API - Version 1.2.0
|
Provides a container for painting operations, enabling arbitrary graphical shapes to be constructed and reused. More...
#include <Path2D.hpp>
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... | |
Path2D & | operator+= (const Path2D &path) |
Appends the elements stored in the Path2D instance path to this path. More... | |
Path2D & | operator= (const Path2D &path) |
Assignment operator. More... | |
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.
Specifies which method to use for filling closed shapes described by the Path2D
object.
CDPL::Vis::Path2D::Path2D | ( | ) |
Constructs an empty Path2D
instance.
CDPL::Vis::Path2D::Path2D | ( | const Path2D & | path | ) |
Constructs a copy of the Path2D
instance path.
path | The Path2D instance to copy. |
|
virtual |
Virtual destructor.
bool CDPL::Vis::Path2D::isEmpty | ( | ) | const |
Tells whether the Path2D
instance does not contain any elements.
true
is no elements have been added to the Path2D
instance so far, and false
otherwise. bool CDPL::Vis::Path2D::hasDrawingElements | ( | ) | const |
Tells whether the Path2D
instance contains any elements representing drawing operations (lines and arcs).
true
if the Path2D
instance contains any visual elements, and false
otherwise. void CDPL::Vis::Path2D::clear | ( | ) |
Deletes all path elements added so far and sets the fill rule to its default.
void CDPL::Vis::Path2D::setFillRule | ( | FillRule | rule | ) |
Sets the fill rule of the path to the specified value.
rule | The new fill rule. |
FillRule CDPL::Vis::Path2D::getFillRule | ( | ) | const |
Returns the currently set fill rule.
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.
x | Specifies the x-coordinate of the new position. |
y | Specifies the y-coordinate of the new position. |
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.
pos | A 2D vector specifying the new position. |
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.
cx | The x-coordinate of the ellipse center. |
cy | The y-coordinate of the ellipse center. |
rx | The x-radius of the ellipse. |
ry | The y-radius of the ellipse. |
start_ang | The start angle of the arg in degrees. |
sweep | The length of the arg in degrees. |
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.
ctr | A 2D vector specifying the ellipse center. |
rx | The x-radius of the ellipse. |
ry | The y-radius of the ellipse. |
start_ang | The start angle of the arg in degrees. |
sweep | The length of the arg in degrees. |
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.
cx | The x-coordinate of the ellipse center. |
cy | The y-coordinate of the ellipse center. |
rx | The x-radius of the ellipse. |
ry | The y-radius of the ellipse. |
start_ang | The start angle of the arg in degrees. |
sweep | The length of the arg in degrees. |
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.
ctr | A 2D vector specifying the ellipse center. |
rx | The x-radius of the ellipse. |
ry | The y-radius of the ellipse. |
start_ang | The start angle of the arg in degrees. |
sweep | The length of the arg in degrees. |
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.
x | Specifies the x-coordinate of the line's end point. |
y | Specifies the y-coordinate of the line's end point. |
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.
pos | A 2D vector specifying the line end point. |
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.
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.
x | The x-coordinate of the ellipse center. |
y | The y-coordinate of the ellipse center. |
width | The width of the ellipse. |
height | The height of the ellipse. |
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.
pos | A 2D vector specifying the ellipse center. |
width | The width of the ellipse. |
height | The height of the ellipse. |
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.
x | The x-coordinate of the top-left corner. |
y | The y-coordinate of the top-left corner. |
width | The width of the rectangle. |
height | The height of the rectangle. |
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.
pos | A 2D vector specifying the top-left corner. |
width | The width of the rectangle. |
height | The height of the rectangle. |
void CDPL::Vis::Path2D::getBounds | ( | Rectangle2D & | bounds | ) | const |
Calculates the axis-aligned bounding box of the path.
bounds | The Vis::Rectangle2D instance storing the calculated bounding box. |
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.
conv | An instance of a class implementing the Vis::Path2DConverter interface. |
Equality comparison operator.
path | The Path2D instance to compare with. |
true
if this path is equal to path, and false
otherwise. Non-equality comparison operator.
path | The Path2D instance to compare with. |
true
if this path is not equal to path, and false
otherwise. Appends the elements stored in the Path2D
instance path to this path.
path | The Path2D instance providing the elements to append. |
Assignment operator.
path | The Path2D instance to copy. |