Donner
Embeddable browser-grade SVG2 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

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.
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.
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 current point (end point of the last command), or (0,0) if empty.
bool empty () const
 Returns true if no commands have been added.

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();
Path build()
Build the immutable Path. The builder is reset after this call.
Definition Path.cc:1909
PathBuilder & quadTo(const Vector2d &control, const Vector2d &end)
Quadratic Bézier from the current point through control to end.
Definition Path.cc:1680
PathBuilder & lineTo(const Vector2d &point)
Line from the current point to point.
Definition Path.cc:1673
PathBuilder & closePath()
Close the current subpath with a straight line back to the last moveTo point.
Definition Path.cc:1803
Immutable 2D vector path.
Definition Path.h:69

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.

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 files:
  • donner/base/Path.h
  • donner/base/Path.cc