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

class  Builder
 Builder to construct a new PathSpline. More...
 
struct  Command
 Metadata for a command, which describes how to connect the points. More...
 

Public Types

enum class  CommandType {
  MoveTo ,
  CurveTo ,
  LineTo ,
  ClosePath
}
 Type of command to connect the points. More...
 

Public Member Functions

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.
 
Boxd bounds () const
 Returns the bounding box for this spline.
 
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 tangent vector on the spline.
 
Vector2d normalAt (size_t index, double t) const
 Get the normal vector on the spline.
 
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 do not map 1:1 to the SVG path commands, since SVG path commands can be simplified into these basic commands.

Enumerator
MoveTo 

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

Consumes 1 point:

  • 1: New starting point.
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.
LineTo 

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

Consumes 1 point:

  • 1: End point of the line.
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.

◆ normalAt()

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

Get the normal vector on the spline.

Parameters
indexSpline index.
tPosition on spline, between 0.0 and 1.0.

◆ pointAt()

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

Get a point on the spline.

Parameters
indexSpline index.
tPosition on spline, between 0.0 and 1.0.
Returns
Vector2d

◆ 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 tangent vector on the spline.

Parameters
indexSpline index.
tPosition on spline, between 0.0 and 1.0.

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: