|
|
Donner
C++20 SVG rendering library
|
Container for a spline, which is a series of points connected by lines and curves. More...
#include "donner/svg/core/PathSpline.h"
Classes | |
| struct | Command |
| Metadata for a command, which describes how to connect the points. More... | |
| struct | Vertex |
| Vertex of the path, including the orientation. More... | |
Public Types | |
| enum class | CommandType : uint8_t { MoveTo , LineTo , CurveTo , ClosePath } |
| Type of command to connect the points. More... | |
Public Member Functions | |
| PathSpline ()=default | |
| Construct a new empty PathSpline. | |
| bool | empty () const |
| Returns true if the spline is empty. | |
| const std::vector< Vector2d > & | points () const |
| Returns the points in the spline. | |
| const std::vector< Command > & | commands () const |
| Returns the commands in the spline. | |
| double | pathLength () const |
| Returns the length of the spline. | |
| Vector2d | currentPoint () const |
| Get the end point of the path, where new draw commands will originate. | |
| Boxd | bounds () const |
| Returns the bounding box for this spline in local space. | |
| Boxd | transformedBounds (const Transformd &pathFromTarget) const |
| Returns the tight bounding box for this spline transformed to a target coordinate system. | |
| Boxd | strokeMiterBounds (double strokeWidth, double miterLimit) const |
| Get the bounds of critical points created by miter joints when applying a stroke to this path. | |
| Vector2d | pointAt (size_t index, double t) const |
| Get a point on the spline. | |
| Vector2d | tangentAt (size_t index, double t) const |
| Get the un-normalized tangent vector on the spline. | |
| Vector2d | normalAt (size_t index, double t) const |
| Get the normal vector on the spline. | |
| std::vector< Vertex > | vertices () const |
| Get the vertices of the path, including the orientation. | |
| bool | isInside (const Vector2d &point, FillRule fillRule=FillRule::NonZero) const |
| Returns true if this path contains the given point within its fill. | |
| bool | isOnPath (const Vector2d &point, double strokeWidth) const |
| Returns true if this path contains the given point within its stroke. | |
Modification | |
| void | moveTo (const Vector2d &point) |
| Move the starting point of the spline to a new point, creating a new subpath. | |
| void | lineTo (const Vector2d &point) |
| Draw a line from the current point to a new point. | |
| void | curveTo (const Vector2d &control1, const Vector2d &control2, const Vector2d &endPoint) |
| Draw a cubic Bézier curve from the current point to a new point. | |
| void | arcTo (const Vector2d &radius, double rotationRadians, bool largeArcFlag, bool sweepFlag, const Vector2d &endPoint) |
| Add an elliptical arc to the path. | |
| void | closePath () |
| Close the path. | |
| void | ellipse (const Vector2d ¢er, const Vector2d &radius) |
| Draw an ellipse (uses multiple curve segments). | |
| void | circle (const Vector2d ¢er, double radius) |
| Draw a circle (uses multiple curve segments). | |
| void | appendJoin (const PathSpline &spline, bool asInternalPath=false) |
| Append an existing spline to this spline, joining the two splines together. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, PathSpline::CommandType type) |
| Ostream operator for CommandType, e.g. | |
| std::ostream & | operator<< (std::ostream &os, const PathSpline &spline) |
| Ostream output operator, outputs a human-readable representation of the spline. | |
Container for a spline, which is a series of points connected by lines and curves.
This is used to represent the d attribute of the SVGPathElement ("<path>"), see https://www.w3.org/TR/SVG2/paths.html#PathData. To parse SVG path data into a PathSpline, use the donner::svg::parser::PathParser.
The spline is composed of a series of CommandType commands, which describe how to connect the points. The points are stored in a separate vector, and the commands reference the points by index.
|
strong |
Type of command to connect the points.
Note that these may not map 1:1 to the SVG path commands, as the commands are decomposed into simpler curves.
| void donner::svg::PathSpline::appendJoin | ( | const PathSpline & | spline, |
| bool | asInternalPath = false ) |
Append an existing spline to this spline, joining the two splines together.
This will ignore the moveTo comand at the start of spline.
| spline | Spline to append. |
| asInternalPath | True if the spline should be treated as an internal path, which means that markers will not be rendered onto its segments. |
| void donner::svg::PathSpline::arcTo | ( | const Vector2d & | radius, |
| double | rotationRadians, | ||
| bool | largeArcFlag, | ||
| bool | sweepFlag, | ||
| const Vector2d & | endPoint ) |
Add an elliptical arc to the path.
| radius | Radius before rotation. |
| rotationRadians | Rotation of the x-axis of the ellipse. |
| largeArcFlag | False for arc length ≤ 180°, true for arc length ≥ 180°. |
| sweepFlag | False for negative angle, true for positive angle. |
| endPoint | End point of the arc. |
| void donner::svg::PathSpline::circle | ( | const Vector2d & | center, |
| double | radius ) |
Draw a circle (uses multiple curve segments).
| center | Center of the circle. |
| radius | Radius. |
| void donner::svg::PathSpline::closePath | ( | ) |
Close the path.
An automatic straight line is drawn from the current point back to the initial point of the current subpath.
| void donner::svg::PathSpline::curveTo | ( | const Vector2d & | control1, |
| const Vector2d & | control2, | ||
| const Vector2d & | endPoint ) |
Draw a cubic Bézier curve from the current point to a new point.
| control1 | First control point. |
| control2 | Second control point. |
| endPoint | End point of the curve. |
Draw an ellipse (uses multiple curve segments).
| center | Center of the ellipse. |
| radius | Ellipse radius, for both the x and y axis. |
| bool donner::svg::PathSpline::isInside | ( | const Vector2d & | point, |
| FillRule | fillRule = FillRule::NonZero ) const |
Returns true if this path contains the given point within its fill.
| point | Point to check. |
| fillRule | Fill rule to use, defaults to FillRule::NonZero. |
| bool donner::svg::PathSpline::isOnPath | ( | const Vector2d & | point, |
| double | strokeWidth ) const |
Returns true if this path contains the given point within its stroke.
| point | Point to check. |
| strokeWidth | Width of the stroke. |
| void donner::svg::PathSpline::lineTo | ( | const Vector2d & | point | ) |
Draw a line from the current point to a new point.
| point | End point of the line. |
| void donner::svg::PathSpline::moveTo | ( | const Vector2d & | point | ) |
Move the starting point of the spline to a new point, creating a new subpath.
If this is called multiple times in a row, subsequent calls will replace the previous.
| point | Point to move to. |
| Vector2d donner::svg::PathSpline::normalAt | ( | size_t | index, |
| double | t ) const |
Get the normal vector on the spline.
| index | Index of the command in the spline. |
| t | Position on the segment, between 0.0 and 1.0. |
| Vector2d donner::svg::PathSpline::pointAt | ( | size_t | index, |
| double | t ) const |
Get a point on the spline.
| index | Index of the command in the spline. |
| t | Position on the segment, between 0.0 and 1.0. |
| Boxd donner::svg::PathSpline::strokeMiterBounds | ( | double | strokeWidth, |
| double | miterLimit ) const |
Get the bounds of critical points created by miter joints when applying a stroke to this path.
| strokeWidth | Width of stroke. |
| miterLimit | Miter limit of the stroke. |
| Vector2d donner::svg::PathSpline::tangentAt | ( | size_t | index, |
| double | t ) const |
Get the un-normalized tangent vector on the spline.
| index | Index of the command in the spline. |
| t | Position on the segment, between 0.0 and 1.0. |
| Boxd donner::svg::PathSpline::transformedBounds | ( | const Transformd & | pathFromTarget | ) | const |
Returns the tight bounding box for this spline transformed to a target coordinate system.
| pathFromTarget | Transform to transform the path to the target coordinate system. |
| std::vector< PathSpline::Vertex > donner::svg::PathSpline::vertices | ( | ) | const |
Get the vertices of the path, including the orientation.
Used to place markers for "<marker>".
|
friend |
Ostream output operator, outputs a human-readable representation of the spline.
| os | Output stream. |
| spline | Spline to output. |
|
friend |
Ostream operator for CommandType, e.g.
| os | Output stream. |
| type | Command type. |