PathDataBuilder
class PathDataBuilder
A builder for constructing SVG path data strings.
This class provides a fluent API for building SVG path data, which can be used to create Path2D objects or passed to other renderers like Rough.js.
Examples
Constructors
constructor
public new PathDataBuilder(): PathDataBuilder
Methods
arc
public arcx: numbery: numberradius: numberstartAngle: numberendAngle: numbercounterclockwise: boolean = false: this
Draw a circular arc using the arc command.
This is a convenience method that calls ellipse with equal radii.
Parameters
x: numberCenter x coordinate
y: numberCenter y coordinate
radius: numberArc radius
startAngle: numberStart angle in radians
endAngle: numberEnd angle in radians
counterclockwise: boolean = falseWhether to draw counterclockwise
arcTo
Draw an arc to a point with a given radius.
This matches the Canvas API's arcTo method. It draws a straight line from the current point to the start of an arc, then draws an arc with the given radius that is tangent to the line from the current point to (x1, y1) and the line from (x1, y1) to (x2, y2).
Parameters
x1: numberFirst control point x
y1: numberFirst control point y
x2: numberSecond control point x
y2: numberSecond control point y
radius: numberArc radius
bezierCurveTo
Draw a cubic Bezier curve.
Parameters
cp1x: numberFirst control point x
cp1y: numberFirst control point y
cp2x: numberSecond control point x
cp2y: numberSecond control point y
x: numberEnd point x
y: numberEnd point y
clear
public clear(): this
Reset the builder to empty state.
closePath
public closePath(): this
Close the current path.
ellipse
public ellipsex: numbery: numberradiusX: numberradiusY: numberrotation: numberstartAngle: numberendAngle: numbercounterclockwise: boolean = false: this
Draw an elliptical arc.
Converts canvas ellipse parameters to SVG arc commands. For full ellipses, this generates two arc commands to work around SVG's limitation of 180-degree maximum arc sweeps.
Parameters
x: numberCenter x coordinate
y: numberCenter y coordinate
radiusX: numberHorizontal radius
radiusY: numberVertical radius
rotation: numberRotation angle in radians
startAngle: numberStart angle in radians
endAngle: numberEnd angle in radians
counterclockwise: boolean = falseWhether to draw counterclockwise
lineTo
Draw a line to a point.
Parameters
moveTo
Move to a point without drawing.
Parameters
quadraticCurveTo
Draw a quadratic Bezier curve.
Parameters
toString
public toString(): string
Get the SVG path data string.