Donner SVG 0.8.0
0.8.0 · ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::PathBuilder Class Reference

Mutable builder for constructing immutable Path objects. More...

#include "donner/base/Path.h"

Public Member Functions

 PathBuilder ()=default
 Create a builder with no point limit.
 PathBuilder (std::size_t maximumPoints)
 Create a builder that holds at most maximumPoints points.
Path build ()
 Build the immutable Path. The builder is reset after this call.
Path construction
PathBuilder & moveTo (const Vector2d &point)
 Start a new subpath at point.
PathBuilder & lineTo (const Vector2d &point)
 Line from the current point to point.
PathBuilder & quadTo (const Vector2d &control, const Vector2d &end)
 Quadratic Bézier from the current point through control to end.
PathBuilder & curveTo (const Vector2d &c1, const Vector2d &c2, const Vector2d &end)
 Cubic Bézier from the current point through c1, c2 to end.
PathBuilder & arcTo (const Vector2d &radius, double rotationRadians, bool largeArc, bool sweep, const Vector2d &end)
 Elliptical arc from the current point to end.
PathBuilder & closePath ()
 Close the current subpath with a straight line back to the last moveTo point. Has no effect when there is no open subpath.
Shape helpers
PathBuilder & addRect (const Box2d &rect)
 Add an axis-aligned rectangle.
PathBuilder & addRoundedRect (const Box2d &rect, double rx, double ry)
 Add a rounded rectangle with corner radii rx and ry. The radii are clamped to half the width and height of rect; if either is not positive, a plain rectangle is added.
PathBuilder & addEllipse (const Box2d &bounds)
 Add an ellipse inscribed in bounds.
PathBuilder & addCircle (const Vector2d &center, double radius)
 Add a circle with center center and radius radius.
PathBuilder & addPath (const Path &path)
 Append all commands from path.
State
Vector2d currentPoint () const
 Returns the last point appended to the path, or (0,0) if empty. closePath appends no point, so after it this is still the point before the close, not the subpath start.
bool empty () const
 Returns true if no commands have been added.
bool exceededMaximumPoints () const
 Returns true if a command was rejected because the configured point limit was reached, or after rejectRemainingCommands.
void rejectRemainingCommands ()
 Refuse every further command, reported through exceededMaximumPoints. A caller uses this when it cannot represent its geometry, so the caller can fail closed instead of building a partial path. build still returns the commands accepted before the rejection and clears the flag, so a caller that needs a fail-closed result checks exceededMaximumPoints first and discards the partial path.

Detailed Description

Mutable builder for constructing immutable Path objects.

Usage:

Path path = PathBuilder()
.moveTo({0, 0})
.lineTo({100, 0})
.quadTo({100, 100}, {0, 100})
.build();
PathBuilder()=default
Create a builder with no point limit.
Path build()
Build the immutable Path. The builder is reset after this call.
PathBuilder & quadTo(const Vector2d &control, const Vector2d &end)
Quadratic Bézier from the current point through control to end.
PathBuilder & lineTo(const Vector2d &point)
Line from the current point to point.
PathBuilder & closePath()
Close the current subpath with a straight line back to the last moveTo point. Has no effect when ther...
Immutable 2D vector path.
Definition Path.h:98

Constructor & Destructor Documentation

◆ PathBuilder()

donner::PathBuilder::PathBuilder ( std::size_t maximumPoints)
inlineexplicit

Create a builder that holds at most maximumPoints points.

A command that would exceed the limit is rejected, along with every later command, and exceededMaximumPoints reports true.

Parameters
maximumPointsMaximum number of points the built path may hold.

Member Function Documentation

◆ arcTo()

PathBuilder & donner::PathBuilder::arcTo ( const Vector2d & radius,
double rotationRadians,
bool largeArc,
bool sweep,
const Vector2d & end )

Elliptical arc from the current point to end.

The arc is decomposed into cubic Bézier curves internally.

Out-of-range parameters are handled as in the SVG arc implementation notes: an arc whose end point equals the current point is omitted, a zero radius produces a straight line to end, negative radii use their absolute values, and radii too small to reach end are scaled up.

Parameters
radiusEllipse radius (before rotation).
rotationRadiansX-axis rotation of the ellipse in radians.
largeArcTrue for arc length >= 180 degrees.
sweepTrue for positive-angle arc direction.
endEnd point of the arc.

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