Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg::PathSpline Class Reference

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 {
  MoveTo ,
  LineTo ,
  CurveTo ,
  ClosePath
}
 Type of command to connect the points. More...
 

Public Member Functions

 PathSpline ()=default
 Construct a new empty PathSpline.
 
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 &center, const Vector2d &radius)
 Draw an ellipse (uses multiple curve segments).
 
void circle (const Vector2d &center, 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.
 
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.
 
size_t size () const
 Returns the number of 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< Vertexvertices () 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.
 

Friends

std::ostream & operator<< (std::ostream &os, 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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ CommandType

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.

Enumerator
MoveTo 

Move the starting point of the spline to a new point, creating a new subpath.

Consumes 1 point:

  • 1: New starting point.
LineTo 

Draw a line from the current point to a new point.

Consumes 1 point:

  • 1: End point of the line.
CurveTo 

Draw a cubic Bézier curve from the current point to a new point.

Consumes 3 points:

  • 1: First control point.
  • 2: Second control point.
  • 3: End point of the curve.
ClosePath 

Close the path.

An automatic straight line is drawn from the current point back to the initial point of the current subpath.

Consumes 0 points.

Member Function Documentation

◆ isInside()

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.

Parameters
pointPoint to check.
fillRuleFill rule to use, defaults to FillRule::NonZero.

◆ isOnPath()

bool donner::svg::PathSpline::isOnPath ( const Vector2d & point,
double strokeWidth ) const

Returns true if this path contains the given point within its stroke.

Parameters
pointPoint to check.
strokeWidthWidth of the stroke.

◆ normalAt()

Vector2d donner::svg::PathSpline::normalAt ( size_t index,
double t ) const

Get the normal vector on the spline.

Parameters
indexIndex of the command in the spline.
tPosition on the segment, between 0.0 and 1.0.
Returns
Vector2d Normal vector at the specified position.

◆ pointAt()

Vector2d donner::svg::PathSpline::pointAt ( size_t index,
double t ) const

Get a point on the spline.

Parameters
indexIndex of the command in the spline.
tPosition on the segment, between 0.0 and 1.0.
Returns
Vector2d Point at the specified position.

◆ strokeMiterBounds()

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.

Parameters
strokeWidthWidth of stroke.
miterLimitMiter limit of the stroke.

◆ tangentAt()

Vector2d donner::svg::PathSpline::tangentAt ( size_t index,
double t ) const

Get the un-normalized tangent vector on the spline.

Parameters
indexIndex of the command in the spline.
tPosition on the segment, between 0.0 and 1.0.
Returns
Vector2d Tangent vector at the specified position.

◆ transformedBounds()

Boxd donner::svg::PathSpline::transformedBounds ( const Transformd & pathFromTarget) const

Returns the tight bounding box for this spline transformed to a target coordinate system.

Parameters
pathFromTargetTransform to transform the path to the target coordinate system.

◆ vertices()

std::vector< PathSpline::Vertex > donner::svg::PathSpline::vertices ( ) const

Get the vertices of the path, including the orientation.

Used to place markers for "<marker>".

Friends And Related Symbol Documentation

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & os,
PathSpline::CommandType type )
friend

Ostream operator for CommandType, e.g.

CommandType::MoveTo.

Parameters
osOutput stream.
typeCommand type.

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream & os,
const PathSpline & spline )
friend

Ostream output operator, outputs a human-readable representation of the spline.

Parameters
osOutput stream.
splineSpline to output.

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