PavePave
Home
Guide
API
Sandbox
  • English
  • 日本語
GitHub
Home
Guide
API
Sandbox
  • English
  • 日本語
GitHub
  • Path

@baku89/pave v1.0.1


@baku89/pave / Path

Path

Functions for manipulating paths represented as Path.

For creating new paths, see Primitives. Getting intrinsic properties of paths, see Properties. Manipulating existing paths, such as transforming, styling, deforming, etc., see Modifiers.

Inputs are never mutated; returned paths are new objects unless noted otherwise.

Primitives

arc()

arc(center, radius, startAngle, endAngle, options): Path

Defined in: path/primitives.ts:370

Creates an arc path.

Parameters

ParameterTypeDescription
centervec2The center of the arc
radiusnumberThe radius of the arc
startAnglenumberThe start angle in degrees (Y-down: 0° = +X, increasing clockwise)
endAnglenumberThe end angle in degrees
optionsArcOptions-

Returns

Path

The newly created path

Example


arcByPoints()

arcByPoints(start, through, end): Path

Defined in: path/primitives.ts:417

Creates an arc path from the given three points. If the points are collinear, it will create a straight line path.

Parameters

ParameterTypeDescription
startvec2The start point
throughvec2The point that the arc passes through
endvec2The end point

Returns

Path

The newly created path


arcByPointsAngle()

arcByPointsAngle(start, end, angle): Path

Defined in: path/primitives.ts:523

Creates an arc path from two points and an angle.

Parameters

ParameterTypeDescription
startvec2The start point
endvec2The end point
anglenumberThe angle of arc in degrees. If the angle is positive, the arc will be drawn in the sweep direction (clockwise in Y-down coordinate system).

Returns

Path

The newly created path


arcByPointsTangent()

arcByPointsTangent(start, startTangent, end): Path

Defined in: path/primitives.ts:488

Creates an arc path from start point, start tangent, and end point.

Parameters

ParameterTypeDescription
startvec2The start point
startTangentvec2The tangent at the start point
endvec2The end point

Returns

Path

A newly created open arc path


capsule()

capsule(start, end, radius): Path

Defined in: path/primitives.ts:772

Creates a capsule, also known as a stadium: the area within a distance from a line segment, with round ends. It is made of two lines and two arcs, so it keeps exact. When the two points are the same it is a circle.

Parameters

ParameterTypeDescription
startvec2The center of the round end at the start
endvec2The center of the round end at the end
radiusnumberThe radius of the round ends, which is the half of the width

Returns

Path

The newly created path

Example


circle()

circle(center, radius): Path

Defined in: path/primitives.ts:189

Creates a circle path from the given center and radius.

Parameters

ParameterTypeDescription
centervec2The center of the circle
radiusnumberThe radius of the circle

Returns

Path

The newly created path

Example


clothoid()

clothoid(start, startAngle, length, startCurvature, endCurvature, options): Path

Defined in: path/spirals.ts:131

Creates a clothoid, also known as an Euler spiral: the curve whose curvature changes in proportion to the distance traveled. Railways and roads use it to ease into a bend, because a vehicle following it turns its wheel at a constant speed. A positive curvature turns towards increasing angles, which is clockwise on a Y-down canvas, and its reciprocal is the radius of the bend.

Parameters

ParameterTypeDescription
startvec2The start point
startAnglenumberThe direction of travel at the start, in degrees
lengthnumberThe length of the curve
startCurvaturenumberThe curvature at the start
endCurvaturenumberThe curvature at the end
optionsClothoidOptionsThe options

Returns

Path

The newly created open path

Example


cubicBezier()

cubicBezier(start, control1, control2, point): Path

Defined in: path/primitives.ts:852

Creates a path consisting of a single C command.

Parameters

ParameterTypeDescription
startvec2The start point
control1vec2The first control point
control2vec2The second control point
pointvec2The end point

Returns

Path

The newly created path


dot()

dot(point): PathL

Defined in: path/primitives.ts:637

Creates a “dot“ path, which consists of only a M command to the specified point followed by Z command. This will be rendered only if the lineCap of the drawing context is set to 'round' or 'square'.

Parameters

ParameterTypeDescription
pointvec2The center point of the dot

Returns

PathL

The newly created paths

Example


dubins()

dubins(start, startAngle, end, endAngle, radius, options): Path

Defined in: path/dubins.ts:141

Creates the shortest path between two directed points with a limited turning radius, like the track of a car that cannot go backwards. It consists of arcs and at most one straight line, so it is smooth, and its curvature never exceeds 1 / radius.

Parameters

ParameterTypeDescription
startvec2The start point
startAnglenumberThe direction of travel at the start, in degrees
endvec2The end point
endAnglenumberThe direction of travel at the end, in degrees
radiusnumberThe minimum turning radius
optionsDubinsOptionsThe options

Returns

Path

The newly created path

Example


ellipse()

ellipse(center, radius): Path

Defined in: path/primitives.ts:331

Creates an ellipse path from the given center and radius.

Parameters

ParameterTypeDescription
centervec2The center of the ellipse
radiusvec2The horizontal and vertical radii (rx, ry)

Returns

Path

The newly created path

Example


fan()

fan(center, innerRadius, outerRadius, startAngle, endAngle): Path

Defined in: path/primitives.ts:587

Creates a fan path.

Parameters

ParameterTypeDescription
centervec2The center of the fan
innerRadiusnumberThe inner radius of the fan
outerRadiusnumberThe outer radius of the fan
startAnglenumberThe start angle in degrees (see arc)
endAnglenumberThe end angle in degrees

Returns

Path

The newly created path

Example


fit()

fit(points, options): Path

Defined in: path/fitting.ts:476

Fits a smooth sequence of cubic Bézier curves to the given points, so that every point lies within tolerance of the result. The curve is split wherever a single cubic cannot follow the points, so the smaller the tolerance, the more vertices the result has. The algorithm is Schneider’s: the points are parameterized by chord length, the handle lengths are solved in the least-squares sense, the parameters are refined by Newton–Raphson, and the range is split at the point of the largest error when that is not enough.

Sharp corners are kept: where the points turn by 60° or more between chords longer than the tolerance, the curve gets a corner vertex with independent tangents on each side. A run of points that is straight within the tolerance becomes a line (L) rather than a cubic. Consecutive duplicate points are ignored. With fewer than two distinct points the result is an empty path or a dot; with exactly two it is a line.

Parameters

ParameterTypeDescription
pointsreadonly vec2[]The points to fit
optionsFitOptionsThe options

Returns

Path

The fitted path with a single curve

Example


fromSegment()

fromSegment(segment): Path

Defined in: path/compound.ts:11

Creates an open path consist of only a single command.

Parameters

ParameterTypeDescription
segmentSegmentThe segment to create

Returns

Path

The newly created path


grid()

grid(rect, divs): PathL

Defined in: path/primitives.ts:812

Parameters

ParameterType
rectRect
divsvec2

Returns

PathL


halfLine()

halfLine(point, through, distance): Path

Defined in: path/primitives.ts:228

Creates a half-line, infinite line in one direction from a starting point and a point that the line passes through. It is not actually an inifinite, but one with a very large length.

Parameters

ParameterTypeDefault valueDescription
pointvec2undefinedThe starting point
throughvec2undefinedThe point that the line passes through
distancenumber1e8The length of the half-line

Returns

Path

The half-line path


infiniteLine()

infiniteLine(point0, point1, distance): Path

Defined in: path/primitives.ts:213

Creates an infinite line path from the given two points. Unlike line, the line will be drawn nearly infinitely in both directions.

Parameters

ParameterTypeDefault valueDescription
point0vec2undefinedThe first point
point1vec2undefinedThe second point
distancenumber1e8The length of the infinite line for each direction

Returns

Path

The infinite line path


line()

line(start, end): PathL

Defined in: path/primitives.ts:612

Creates a linear path from two points describing a line.

Parameters

ParameterTypeDescription
startvec2The line’s starting point
endvec2The line’s ending point

Returns

PathL

The newly created path

Example


nBezier()

nBezier(points): Path

Defined in: path/primitives.ts:891

Create a path consisting of cubic Bézier curves approximating the arbitrary higher-order Bézier curve.

Parameters

ParameterTypeDescription
pointsvec2[]The control points of the Bézier curve

Returns

Path

The newly created path


ngon()

ngon(center, radius, sides): PathL

Defined in: path/primitives.ts:722

Alias for regularPolygon

Parameters

ParameterTypeDescription
centervec2The center of the polygon
radiusnumberThe radius of the circumcircle of the polygon
sidesnumberThe number o sides of the polygon

Returns

PathL

The newly created path

Example


polygon()

polygon(…points): PathL

Defined in: path/primitives.ts:685

Creates a closed polyline from the given points.

Parameters

ParameterTypeDescription
…pointsvec2[]The points describing the polygon

Returns

PathL

The newly created path

Example


quadraticBezier()

quadraticBezier(start, control, point): Path

Defined in: path/primitives.ts:879

Creates a quadratic Bézier curve path from the given points.

Parameters

ParameterTypeDescription
startvec2The start point
controlvec2The control point
pointvec2The end point

Returns

Path

THe newly created path


rect()

rect(start, end): Path

Defined in: path/primitives.ts:91

Alias for rectangle

Parameters

ParameterTypeDescription
startvec2The first point defining the rectangle
endvec2The second point defining the rectangle

Returns

Path

The newly created path

Example


rectangle()

rectangle(start, end): Path

Defined in: path/primitives.ts:71

Creates a rectangle path from the given two points.

Parameters

ParameterTypeDescription
startvec2The first point defining the rectangle
endvec2The second point defining the rectangle

Returns

Path

The newly created path

Example


rectFromCenter()

rectFromCenter(center, size): Path

Defined in: path/primitives.ts:100

Creates a rectangle path from the given center and size.

Parameters

ParameterTypeDescription
centervec2The center of the rectangle
sizevec2The size of the rectangle

Returns

Path

The newly created path


regularPolygon()

regularPolygon(center, radius, sides): PathL

Defined in: path/primitives.ts:702

Creates a regular polygon. The first vertex will be placed at the +X axis relative to the center.

Parameters

ParameterTypeDescription
centervec2The center of the polygon
radiusnumberThe radius of the circumcircle of the polygon
sidesnumberThe number o sides of the polygon

Returns

PathL

The newly created path

Example


roundRect()

roundRect(start, end, radii): Path

Defined in: path/primitives.ts:112

Creates a rounded rectangle. The arguments are almost the same as the CanvasRenderingContext2D’s roundRect method.

Parameters

ParameterType
startvec2
endvec2
radiinumber | [number] | [number, number] | [number, number, number] | [number, number, number, number]

Returns

Path

See

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect


semicircle()

semicircle(start, end, closed): Path

Defined in: path/primitives.ts:197

Creates a semicircle path from the given start and end points.

Parameters

ParameterTypeDefault value
startvec2undefined
endvec2undefined
closedbooleantrue

Returns

Path


spiral()

spiral(center, startRadius, endRadius, turns, options): Path

Defined in: path/spirals.ts:66

Creates a spiral around a point.

Parameters

ParameterTypeDescription
centervec2The center of the spiral
startRadiusnumberThe radius at the start
endRadiusnumberThe radius at the end
turnsnumberThe number of the turns, which can be fractional. A positive value runs towards increasing angles, which is clockwise on a Y-down canvas, and a negative one runs the other way.
optionsSpiralOptionsThe options

Returns

Path

The newly created open path

Example


spline()

spline(points, options): Path

Defined in: path/fitting.ts:605

Creates a smooth curve passing through all of the points, a cardinal (Catmull-Rom) spline converted to cubic Béziers. The handles of each point are parallel to the line between its neighbours; at the ends of an open spline, the missing neighbour is the reflection of the other one, so the curve leaves the end along the first chord.

Parameters

ParameterTypeDescription
pointsreadonly vec2[]The points to pass through
optionsSplineOptionsThe options

Returns

Path

The newly created path with a single curve

Example


star()

star(center, outerRadius, innerRadius, points): PathL

Defined in: path/primitives.ts:738

Creates a star, alternating between two radii. The first vertex will be placed at the +X axis relative to the center, on the outer radius.

Parameters

ParameterTypeDescription
centervec2The center of the star
outerRadiusnumberThe radius of the tips
innerRadiusnumberThe radius of the notches between the tips
pointsnumberThe number of the tips, an integer of 2 or more

Returns

PathL

The newly created path

Example


superellipse()

superellipse(center, radius, shape, options): Path

Defined in: path/superellipse.ts:85

Creates a closed superellipse, or a squircle with the default shape. Its outline is |x / rx|^e + |y / ry|^e = 1 with e = 2^shape, the same parameter as cornerShape and the CSS superellipse(): 1 is an ellipse, 2 a squircle, 0 a diamond, Infinity a rectangle, and the negative values make the sides concave. The first vertex will be placed at the +X axis relative to the center.

Parameters

ParameterTypeDefault valueDescription
centervec2undefinedThe center of the superellipse
radiusvec2undefinedThe radii along X and Y
shapenumber2The shape, as above
optionsSuperellipseOptions{}The options

Returns

Path

The newly created path

Example

Properties

area()

area(arg): number

Defined in: path/metrics.ts:55

Calculates an area of the given path (absolute value of the Green’s-theorem sum over closed subpaths). A path containing a cubic Bézier that crosses itself is measured by what gets filled under the non-zero rule, so the overlap of a loop counts once.

Parameters

ParameterTypeDescription
argPathThe path to calculate

Returns

number

The area of the path


bounds()

bounds(arg): Rect

Defined in: path/metrics.ts:45

Calculates the bound of the given path.

Parameters

ParameterTypeDescription
argPathThe path to calculate

Returns

Rect

The rect of the path

Example


centroid()

centroid(path, tolerance): null | vec2

Defined in: path/queries.ts:341

The centroid of the area enclosed by the path. Open curves are regarded as closed by a straight line. When the path encloses no area, the mean of its vertices is returned instead.

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe path
tolerancenumber0.05How finely curves are flattened for the computation

Returns

null | vec2

The centroid, or null for an empty path


contains()

contains(path, point, options): boolean

Defined in: path/queries.ts:109

Whether the point lies inside the path. Open curves are regarded as closed by a straight line.

Parameters

ParameterTypeDescription
pathPathThe path
pointvec2The point to test
optionsContainsOptionsThe options

Returns

boolean


convexHull()

convexHull(path, options): Path

Defined in: path/hull.ts:407

The exact convex hull of the path. Unlike the hull of the control points or of a flattened polygon, the result keeps the curved parts of the path that lie on the hull, joining them with the common tangents.

The hull is traced by sweeping the support direction around: while the farthest point stays on one segment the hull follows that segment, and when it jumps to another segment the two support points are joined by a line.

Parameters

ParameterTypeDescription
pathPathThe path to wrap
optionsConvexHullOptionsThe options

Returns

Path

A closed path. An empty path for an empty input.


derivative()

derivative(path, loc): vec2

Defined in: path/location.ts:166

Calculates the normalized tangent vector of the path at the given location.

Parameters

ParameterTypeDescription
pathPathThe path to calcuate
locPathLocationThe location on the path

Returns

vec2

The tangent vector


hitTest()

hitTest(path, point, options): null | HitTestResult

Defined in: path/queries.ts:150

Finds what lies under a point, the way a node tool would: a vertex, then a handle of a cubic Bézier, then the stroke, then the fill.

Parameters

ParameterTypeDescription
pathPathThe path
pointvec2The point to test, usually the pointer
optionsHitTestOptionsThe options

Returns

null | HitTestResult

What was hit, or null


intersections()

intersections(a, b, options): PathIntersection[]

Defined in: path/queries.ts:228

Where two paths cross or touch.

Parameters

ParameterTypeDescription
aPathThe first path
bPathThe second path
optionsIntersectionsOptionsThe options

Returns

PathIntersection[]

The intersections, ordered along the first path


length()

length(arg): number

Defined in: path/metrics.ts:23

Returns the length of the given path. The returned value is memoized.

Parameters

ParameterTypeDescription
argPathThe path to measure

Returns

number

The length of the path


nearest()

nearest(path, point): null | NearestPoint

Defined in: path/queries.ts:125

The point of the path nearest to point.

Parameters

ParameterTypeDescription
pathPathThe path
pointvec2The point to measure from

Returns

null | NearestPoint

The nearest point, or null for an empty path


normal()

normal(path, loc): vec2

Defined in: path/location.ts:190

Calculates the normalized tangent vector of the path at the given location.

Parameters

ParameterTypeDescription
pathPathThe path to calcuate
locPathLocationThe location on the path

Returns

vec2

The tangent vector


orientation()

orientation(path, loc): mat2d

Defined in: path/location.ts:202

Calculates the transformation matrix of the path at the given location. The x-axis of the matrix is the tangent vector and the y-axis is the normal vector, and the translation is the point on the path.

Parameters

ParameterTypeDescription
pathPathThe path to calculate
locPathLocationThe location on the path

Returns

mat2d

The transformation matrix at the given offset


orientedBounds()

orientedBounds(path, tolerance): null | OrientedRect

Defined in: path/hull.ts:577

The smallest rectangle of any rotation that contains the path, found by rotating calipers over the flattened convex hull.

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe path to bound
tolerancenumber0.05How finely curved parts of the hull are flattened

Returns

null | OrientedRect

The rectangle, or null for an empty path


point()

point(path, loc): vec2

Defined in: path/location.ts:154

Calculates the position on the path at the given location.

Parameters

ParameterTypeDescription
pathPathThe path to calculate
locPathLocationThe location on the path

Returns

vec2

The position at the given offset


raycast()

raycast(path, origin, direction, options): RayHit[]

Defined in: path/raycast.ts:58

Casts a ray from origin along direction and returns where it hits the path, nearest first.

Parameters

ParameterTypeDescription
pathPathThe path to cast against
originvec2The start of the ray
directionvec2The direction of the ray. Its length does not matter.
optionsRaycastOptionsThe options

Returns

RayHit[]

The hits sorted by distance


segment()

segment(path, curveIndex, segmentIndex?): Segment

Defined in: path/metrics.ts:128

Returns the segment of the path by indices. If the segmentIndex is omitted, the curveIndex is treated as the linear segment index of the whole path. It also supports negative indices, which count from the end of the path or curve.

Parameters

ParameterTypeDescription
pathPathThe path that contains the segment
curveIndexnumberThe index of the curve.
segmentIndex?numberThe index of the segment in the curve.

Returns

Segment

The segment


segmentCount()

segmentCount(arg): number

Defined in: path/metrics.ts:78

Returns the count of segments in the given path.

Parameters

ParameterTypeDescription
argPathThe path to measure

Returns

number

The count of segments in the path


segments()

segments(arg): Segment[]

Defined in: path/metrics.ts:14

Returns all segments

Parameters

ParameterTypeDescription
argPathThe path to iterate

Returns

Segment[]


selfIntersections()

selfIntersections(path, options): PathIntersection[]

Defined in: path/queries.ts:265

Where the path crosses itself, including a cubic Bézier looping through its own point.

Parameters

ParameterTypeDescription
pathPathThe path
optionsIntersectionsOptionsThe options

Returns

PathIntersection[]

The self-intersections, ordered along the path. a comes before b along the path.


supportPoint()

supportPoint(path, direction): null | PathPoint

Defined in: path/hull.ts:233

The point of the path farthest along direction: the support point of the path in that direction. Ties are broken by the first found.

Parameters

ParameterTypeDescription
pathPathThe path to query
directionvec2The direction to measure along. Its length does not matter.

Returns

null | PathPoint

The farthest point, or null for an empty path


tangent()

tangent(path, loc): vec2

Defined in: path/location.ts:178

Calculates the normalized tangent vector of the path at the given location.

Parameters

ParameterTypeDescription
pathPathThe path to calcuate
locPathLocationThe location on the path

Returns

vec2

The tangent vector


tangentsAlong()

tangentsAlong(path, direction, options): TangentHit[]

Defined in: path/hull.ts:262

Where lines parallel to direction touch the path. With extreme, only the two lines that enclose the whole path are returned, which is the silhouette of the path under a parallel light along direction.

Parameters

ParameterTypeDescription
pathPathThe path to query
directionvec2The direction of the tangent lines
optionsTangentsOptionsThe options

Returns

TangentHit[]

The tangent hits, ordered along the path


tangentsFrom()

tangentsFrom(path, origin, options): TangentHit[]

Defined in: path/hull.ts:308

Where lines through origin touch the path. With extreme, only the two lines that enclose the whole path as seen from origin are returned, which is the silhouette of the path under a point light at origin; it is empty when origin is inside the path.

Parameters

ParameterTypeDescription
pathPathThe path to query
originvec2The point the tangent lines pass through
optionsTangentsOptionsThe options

Returns

TangentHit[]

The tangent hits, ordered along the path. The tangent of each points away from origin.


vertexType()

vertexType(path, address): VertexType

Defined in: path/vertexEdit.ts:187

Tells how the handles of a vertex relate: 'symmetric' when they are opposite and of equal length, 'smooth' when they are only opposite, and 'corner' otherwise. For a line or an arc, the handle is the one of the equivalent cubic Bézier: a third of a line, or a Hermite estimate of an arc. An end of an open curve, having a single handle, is always a corner.

Parameters

ParameterTypeDescription
pathPathThe path
addressVertexAddressThe vertex to inspect

Returns

VertexType

The type of the vertex

Modifiers

bulge()

bulge(path, center, radius, strength, __namedParameters): Path

Defined in: path/distortions.ts:143

Spherize-style radial stretch from center: strongest at the center, fading to none at radius. Points beyond radius are unchanged.

Parameters

ParameterTypeDescription
pathPathThe path to distort
centervec2Origin of the radial stretch
radiusnumberOutside this distance from center, the distortion does nothing
strengthnumberScale added along each ray from center at full falloff (0 = identity). Positive pushes outward, negative pinches inward.
__namedParametersRadialDistortOptions-

Returns

Path

The newly created path

Example


chamfer()

chamfer(path, distance, options): Path

Defined in: path/modifiers.ts:1003

Chamfers the path by replacing each corner with a straight cut. Distances are measured along segment arc length (line, cubic, or arc) from the joint, and both segments are trimmed there, so curved segments keep their exact shape up to the cut. The cut on each side is capped at what the segment can give (see fillet for the sharing rule). Smooth joints are left untouched.

Parameters

ParameterTypeDescription
pathPathThe path to chamfer
distanceAttributeLike<number>The distance of chamfer along each segment from the joint. It can vary per corner, as the name of an attribute or a function of the vertex at the corner.
optionsCornerOptionsThe options

Returns

Path

The newly created path


cleanup()

cleanup(path, options): Path

Defined in: path/structure.ts:222

Removes what does not contribute to the shape of the path: zero-length segments and the duplicated points they connect, line vertices lying on the line through their neighbours, and curved segments that are straight, which become lines. Curves without vertices are dropped, and curves of a single vertex can be.

Parameters

ParameterTypeDescription
pathPathThe path to clean up
optionsCleanupOptionsThe options

Returns

Path

The cleaned up path


convertVertex()

convertVertex(path, address, type, options): Path

Defined in: path/vertexEdit.ts:260

Changes how the handles of a vertex relate, keeping the anchor in place. Converting to smooth turns both handles onto their average direction, keeping each length; symmetric additionally gives both the same length, the mean of the two unless handleLength is given. Lines and arcs next to the vertex become cubic Béziers. Converting to corner changes nothing, since any pair of handles is a valid corner; drag one with Path.setHandle to bend it. An end of an open curve is left as it is.

Parameters

ParameterTypeDescription
pathPathThe path
addressVertexAddressThe vertex to convert
typeVertexTypeThe type to convert the vertex into
optionsConvertVertexOptionsThe options

Returns

Path

The path with the vertex converted


cornerCubic()

cornerCubic(path, trim, options): Path

Defined in: path/modifiers.ts:1151

Rounds corners by a cubic Bézier. Unlike fillet it is measured by the arc length to cut, and its handle length gives a family of shapes from a chamfer to a loop.

Parameters

ParameterTypeDescription
pathPathThe base path
trimAttributeLike<number>The arc length to cut from each side, which can vary per corner
optionsCornerCubicOptionsThe options

Returns

Path

The new path

Example


cornerShape()

cornerShape(path, trim, shape, options): Path

Defined in: path/modifiers.ts:1215

Shapes corners by a superellipse, as superellipse() of corner-shape in CSS: the curve x^e + y^e = 1 with e = 2^shape, between the cuts, by two to six cubic Béziers per corner at the default tolerance.

  • 0 is a chamfer (bevel).
  • 1 is an ellipse (round), which is a circular arc only at right angles. See fillet for an exact circle at any angle.
  • 2 is a squircle.
  • -1 is a concave curve (scoop).
  • Infinity keeps the corner (square), and -Infinity cuts it inwards (notch).

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe base path
trimAttributeLike<number>undefinedThe arc length to cut from each side, which can vary per corner
shapeAttributeLike<number>1The parameter of the superellipse, which can vary per corner
optionsCornerShapeOptions{}The options

Returns

Path

The new path

Example


cutCorners()

cutCorners(path, trim, fill, options): Path

Defined in: path/modifiers.ts:1070

Cuts each corner by the same arc length along both segments, and fills the gap with what the given function returns. Chamfers and other corner shapes can be made on it. Smooth joints are left untouched. How much a corner can cut is capped as in fillet.

Parameters

ParameterTypeDescription
pathPathThe base path
trimAttributeLike<number>The arc length to cut from each side, which can vary per corner
fill(corner) => Vertex[]Returns the vertices from corner.start to corner.end. The last one is moved onto corner.end exactly, and a straight line is drawn when there are none.
optionsCornerOptionsThe options

Returns

Path

The new path

Example


dash()

dash(path, pattern, options): Path

Defined in: path/dash.ts:34

Cuts the path into dashes, with the semantics of stroke-dasharray of SVG: the pattern is a sequence of alternating on and off lengths along the arc length, repeated as far as each curve goes. An odd number of lengths is repeated to make it even. A pattern that is empty or adds up to zero leaves the path as it is.

Every curve starts the pattern afresh at its first vertex. On a closed curve, the dash running over the seam between the last and the first vertex is joined into one, and a curve shorter than its first dash stays closed. The dashes are open curves, keeping the attributes of the ranges they were cut from.

Parameters

ParameterTypeDescription
pathPathThe path to dash
patternreadonly number[]The lengths of the dashes and the gaps between them, which must not be negative
optionsDashOptionsThe options

Returns

Path

The path consists of the dashes

Example


deleteVertex()

deleteVertex(path, address, options): Path

Defined in: path/vertexEdit.ts:441

Removes an anchor from the path. By default the two segments meeting there are replaced by a single cubic Bézier that follows them as closely as possible, keeping the tangents at the neighbouring anchors; two lines are replaced by a line. With preserveShape: false, the vertex is just dropped and the following segment keeps its command and handles, so the path reshapes. Removing an end of an open curve drops it either way. A curve left with no vertices is removed from the path.

Parameters

ParameterTypeDescription
pathPathThe path
addressVertexAddressThe vertex to remove
optionsDeleteVertexOptionsThe options

Returns

Path

The path with one vertex fewer


displace()

displace(path, displacement, options): Path

Defined in: path/displace.ts:76

Displaces the path in the local frame of its tangent and normal. Each point moves by what the given function returns: along the tangent, and across towards the normal. This is the base of waves, coils and scallops.

Where the source has a corner, the frame jumps, so the two sides are connected by a straight line. A closed curve is closed the same way if the displacement does not return to the same value.

Parameters

ParameterTypeDescription
pathPathThe path to displace
displacement(u, context) => readonly [number, number]Takes the unit along the curve (by arc length, from 0 to 1) and where it is, and returns [along, across]
optionsDisplaceOptionsThe options

Returns

Path

The new path

Example


distort()

distort(path, map, __namedParameters): Path<VertexC>

Defined in: path/modifiers.ts:491

Distorts path by the given point map. It assumes that the map is smooth in the spatial domain and has no singularities or cusps.

Every vertex is moved to map(point). Each Bézier handle h attached to a point p is re-estimated with the central difference (map(p + h) - map(p - h)) / 2, so the step is the handle itself and no unit-dependent epsilon is involved. Each segment is then subdivided until the fitted cubic stays within tolerance of the true image of the segment, so an affine map yields exactly Path.transform (with arcs approximated by cubics) without any extra vertices.

Parameters

ParameterTypeDescription
pathPathThe path to distort
map(position) => vec2A function that returns, for any point in the plane, its image after the distortion.
__namedParametersDistortOptions-

Returns

Path<VertexC>

The newly created path

Example


fillet()

fillet(path, radius, options): Path

Defined in: path/modifiers.ts:1296

Fillets corners with a circular arc of the given radius, tangent to both segments. For each corner the two tangent points are solved exactly, also on curved segments, by finding the circle of the given radius that touches both; the segments are trimmed there and the arc is emitted as an A command. When the radius does not fit, the largest radius that fits is used instead: a corner may consume a whole adjacent segment when its other end is a path end or a smooth joint; when that end is another corner, the two share the segment, each taking what the other leaves (half each when both are held back), so neighbouring fillets never overlap. Smooth joints are left untouched.

Parameters

ParameterTypeDescription
pathPathThe path to fillet
radiusAttributeLike<number>The radius of fillet. It can vary per corner, as the name of an attribute or a function of the vertex at the corner.
optionsCornerOptionsThe options

Returns

Path

The newly created path

Example


fitInto()

fitInto(path, rect, options): Path

Defined in: path/layout.ts:282

Scales and moves the path so that its bounds fit into the rect, like the object-fit property of CSS. A path with no extent on an axis is only scaled by the other.

Parameters

ParameterTypeDescription
pathPathThe path to fit
rectRectThe rect to fit the path into
optionsFitIntoOptionsThe options

Returns

Path

The fitted path

Example


flatten()

flatten(path, tolerance): Path

Defined in: path/modifiers.ts:430

Flattens the curves in path to straight lines (recursive midpoint split until chord / hull deviation ≤ tolerance).

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe path to flatten
tolerancenumber0.05The maximum distance between the path and the flattened path, in the same unit as the coordinates

Returns

Path

The flattened path consists of only M, L, and Z commands

Example


insertVertex()

insertVertex(path, location): Path

Defined in: path/vertexEdit.ts:407

Adds an anchor at the given location without changing the shape of the path, by dividing the segment there. When the location is already at an anchor, the path is returned as it is.

Parameters

ParameterTypeDescription
pathPathThe path
locationPathLocationThe location to add the anchor at

Returns

Path

The path with one more vertex

Example


join()

join(paths): Path

Defined in: path/modifiers.ts:399

Joins the given paths into a single open paths.

Parameters

ParameterTypeDescription
pathsPath[]The paths to join

Returns

Path

The joined path


merge()

merge(pathOrCurves): Path

Defined in: path/compound.ts:33

Merges the given paths into a single path. Unlike join or unite, the vertices are not connected, and it simply returns compound path.

Parameters

ParameterType
pathOrCurves(Path | Curve)[]

Returns

Path


mirror()

mirror(path, axis): Path

Defined in: path/mirror.ts:309

Makes the path symmetric across the axis: the part on the side the axis normal points to is kept, and the other side is replaced with its reflection. Use Line.invert of geome to keep the opposite side.

Curves are cut where they cross the axis, and new vertices are added there. Lines, cubic Béziers and arcs all stay as they are. The kept parts are joined with their reflections on the axis, so an open curve with both ends on the axis becomes a closed one. Closed curves keep their orientation, so holes stay holes.

Parameters

ParameterTypeDescription
pathPathThe path to symmetrize
axisMirrorAxisThe axis of symmetry

Returns

Path

The symmetric path. It is empty when nothing lies on the kept side.

Example


moveVertex()

moveVertex(path, address, point, options): Path

Defined in: path/vertexEdit.ts:359

Moves the anchor of a vertex to a new position. Its handles move along by default, so the segments around it keep their shape; with handles: false the handles stay in place and only the anchor moves.

Parameters

ParameterTypeDescription
pathPathThe path
addressVertexAddressThe vertex to move
pointvec2The new position of the anchor
optionsMoveVertexOptionsThe options

Returns

Path

The path with the vertex moved


normalizeWinding()

normalizeWinding(path, options): Path

Defined in: path/structure.ts:361

Resolves the self-intersections and the overlaps of the closed curves of the path. The result fills the same region as the input under the fill rule, with non-overlapping curves wound consistently: outer boundaries in the direction of positive signed area (the one of Path.rect, see Path.orient) and holes in the other, so that the result fills the same under either rule. Open curves are kept as they are and appended after the closed ones.

Parameters

ParameterTypeDescription
pathPathThe path to normalize
optionsNormalizeWindingOptionsThe options

Returns

Path

The normalized path

Example


offset()

offset(path, offset, options?): Path

Defined in: path/offset.ts:535

Creates an offset path from the given path.

Closed curves are treated as a filled region (non-zero winding): a positive offset dilates it and a negative one erodes it, regardless of the curves’ orientation. Open curves are offset to the side of their Segment.normal (positive) or the opposite side (negative), and the parts of the raw parallel curve that fold back are trimmed away.

Straight lines and circular arcs are offset exactly, so A commands are preserved; cubic Béziers and elliptic arcs are approximated by cubic Béziers within options.tolerance. Attributes follow the place on the source curve, and values on curves move down to the vertices.

Parameters

ParameterTypeDescription
pathPathThe path to offset
offsetnumberThe signed offset distance
options?OffsetOptionsThe options

Returns

Path

The newly created path

Example


offsetStroke()

offsetStroke(path, width, options?): Path

Defined in: path/offset.ts:623

Creates the outline of a stroke along the given path.

Straight lines and circular arcs are offset exactly, so A commands are preserved; cubic Béziers and elliptic arcs are approximated by cubic Béziers within options.tolerance.

Parameters

ParameterTypeDescription
pathPathThe path to stroke
widthAttributeLike<number>The width of stroke. It can vary along the path, as the name of an attribute or a function of the vertex: the width is read at the vertices and interpolated along the segments. A path whose curves each have one width keeps its A commands.
options?OffsetStrokeOptionsThe options

Returns

Path

The newly created path

Example


orient()

orient(path, orientation): Path

Defined in: path/structure.ts:335

Makes every closed curve of the path wind in the given direction, reversing the ones that do not. The direction is that of the signed area, which is positive for Path.rect: its vertices run clockwise on the screen in the y-down coordinates of SVG and canvas, so cw means visually clockwise there (and counter-clockwise with the y axis up). Open curves and curves without area are untouched.

Parameters

ParameterTypeDescription
pathPathThe path to orient
orientation"cw" | "ccw"The winding direction every closed curve should have

Returns

Path

The oriented path


reduce()

reduce(path, options): Path

Defined in: path/drawAppend.ts:180

Cleans up the path by removing redundant vertices and

Parameters

ParameterTypeDescription
pathPath
optionsReduceOptions-

Returns

Path


reflect()

reflect(path, axis): Path

Defined in: path/mirror.ts:289

Reflects the path across the axis. The orientation of the curves is flipped, as with any reflection.

Parameters

ParameterTypeDescription
pathPathThe path to reflect
axisMirrorAxisThe axis of the reflection

Returns

Path

The reflected path

Example


reverse()

reverse(path, options:): Path

Defined in: path/modifiers.ts:273

Reverses the given path.

Parameters

ParameterTypeDescription
pathPathThe path to reverse
options:ReverseOptionsThe options

Returns

Path

The reversed path


rotate()

rotate(path, degrees, pivot?): Path

Defined in: path/layout.ts:120

Rotates the path around the pivot. A positive angle rotates clockwise on the screen in the y-down coordinates of SVG and canvas.

Parameters

ParameterTypeDescription
pathPathThe path to rotate
degreesnumberThe angle in degrees
pivot?vec2The center of the rotation, which is the center of the bounds by default

Returns

Path

The rotated path


scale()

scale(path, factor, pivot?): Path

Defined in: path/layout.ts:136

Scales the path around the pivot.

Parameters

ParameterTypeDescription
pathPathThe path to scale
factornumber | vec2The scaling factor, either uniform or per axis
pivot?vec2The center of the scaling, which is the center of the bounds by default

Returns

Path

The scaled path


setHandle()

setHandle(path, address, side, handle, options): Path

Defined in: path/vertexEdit.ts:308

Moves one handle of a vertex to an absolute position, like dragging it with a node tool. Depending on link, the opposite handle turns to stay opposite (smooth), also matches the length (symmetric), or stays put (none); by default it follows the way the vertex currently is. The segment the handle belongs to becomes a cubic Bézier if it is a line or an arc. Nothing happens when there is no segment on that side of the vertex.

Parameters

ParameterTypeDescription
pathPathThe path
addressVertexAddressThe vertex whose handle to move
side"in" | "out"in for the handle of the segment arriving at the vertex, out for the one leaving it
handlevec2The new absolute position of the handle
optionsSetHandleOptionsThe options

Returns

Path

The path with the handle moved


setStart()

setStart(path, curveIndex, vertexIndex): Path

Defined in: path/structure.ts:71

Makes the given vertex the first one (the move-to) of a closed curve by rotating its vertices. The shape does not change; only where the curve starts does. An open curve is returned unchanged, since it cannot start anywhere else without changing its shape.

Parameters

ParameterTypeDescription
pathPathThe path
curveIndexnumberThe index of the curve, negative values counting from the end
vertexIndexnumberThe index of the vertex to become the first, negative values counting from the end

Returns

Path

The path with the curve rotated


shadow()

shadow(path, direction, length): Path

Defined in: path/shadow.ts:138

The shadow the path casts under a parallel light, as the region swept when the path is moved along direction by length. The result includes the path itself; subtract the path to get only the cast part. On an isometric drawing this is also the side face of an extruded shape.

Parameters

ParameterTypeDescription
pathPathThe path casting the shadow
directionvec2The direction of the light. Its length does not matter.
lengthnumberHow far the shadow reaches

Returns

Path

The closed path of the shadow

Example


shadowFrom()

shadowFrom(path, origin, scale): Path

Defined in: path/shadow.ts:156

The shadow the path casts under a point light at origin, as the region swept when the path is scaled about origin by scale. The result includes the path itself; subtract the path to get only the cast part.

Parameters

ParameterTypeDescription
pathPathThe path casting the shadow
originvec2The position of the light
scalenumberHow many times farther from the light the shadow reaches than the path. Values above 1 cast the shadow away from the light.

Returns

Path

The closed path of the shadow


simplify()

simplify(path, options): Path

Defined in: path/fitting.ts:566

Reduces the number of vertices of the path while keeping it within tolerance of the original. Each curve is flattened to points and then Path.fit to a new sequence of cubic Béziers, so collinear runs of lines collapse into one and dense polylines become a few smooth curves. Arcs are refit as cubics like everything else.

The attributes of the path and of the curves are kept; those of the vertices are dropped, since the vertices are replaced.

Parameters

ParameterTypeDescription
pathPathThe path to simplify
optionsSimplifyOptionsThe options

Returns

Path

The simplified path

Example


smooth()

smooth(path, options): Path

Defined in: path/fitting.ts:670

Makes the path smooth by recomputing the handles at every vertex from the neighbouring anchors, in the manner of a Catmull-Rom spline, while keeping the anchors in place. Every segment becomes a cubic Bézier, and the tangent is continuous at every vertex that has a neighbour on both sides, so Path.vertexType reports 'smooth' there. At the ends of an open curve, an existing cubic handle is kept and a line gets a handle a third of the way along it.

Arcs are first converted to cubic Béziers by Path.unarc, which may add vertices.

Parameters

ParameterTypeDescription
pathPathThe path to smooth
optionsSmoothOptionsThe options

Returns

Path

The smoothed path

Example


spawn()

spawn(path, fn, __namedParameters): Path

Defined in: path/modifiers.ts:171

Maps each segments in the path to a path and create a new path concatinating those paths.

Parameters

ParameterType
pathPath
fn(seg, segmentIndex, curve) => Path
__namedParametersSpawnOptions

Returns

Path


spawnCurve()

spawnCurve<V1, V2>(path, fn): Path<V2>

Defined in: path/modifiers.ts:149

Maps each curves in the path to a single or array of curves and creates a new path concatinating those curves. Unlike spawnVertex, you can also change the number of curves, or open/close state of the curves.

Type Parameters

Type ParameterDefault type
V1 extends VertexVertex
V2 extends VertexVertex

Parameters

ParameterTypeDescription
pathPath<V1>The path to map
fn(curve, curveIndex) => Curve<V2> | Curve<V2>[]The curve mapping function.

Returns

Path<V2>

The newly created path


split()

split(path, locs): Path[]

Defined in: path/modifiers.ts:466

Splits the path into multiple paths at the given locations.

Parameters

ParameterTypeDescription
pathPathThe path to split
locsIterable<PathLocation>The locations to split

Returns

Path[]

The splitted paths


subdiv()

subdiv(path, division): Path

Defined in: path/modifiers.ts:457

Alias for subdivide

Parameters

ParameterTypeDescription
pathPathThe path to subdivide
divisionnumberThe number of division for each segment

Returns

Path

The newly created path


subdivide()

subdivide(path, division): Path

Defined in: path/modifiers.ts:441

Subdivides each segment in the path into specific number of sub-segments.

Parameters

ParameterTypeDescription
pathPathThe path to subdivide
divisionnumberThe number of division for each segment

Returns

Path

The newly created path


toC()

toC(path, tolerance): PathC

Defined in: path/modifiers.ts:391

Alias for toCubicBezier

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe path to convert
tolerancenumber0.05The maximum deviation allowed when approximating arc commands by cubic Béziers

Returns

PathC

The new path with only cubic Bézier curve commands


toCubicBezier()

toCubicBezier(path, tolerance): PathC

Defined in: path/modifiers.ts:373

Converts all commands in the path to cubic Bézier curve commands.

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe path to convert
tolerancenumber0.05The maximum deviation allowed when approximating arc commands by cubic Béziers

Returns

PathC

The new path with only cubic Bézier curve commands


transform()

transform(path, matrix): Path

Defined in: path/modifiers.ts:248

Transforms the given path by the given matrix.

Parameters

ParameterTypeDescription
pathPathThe path to transform
matrixmat2dThe matrix to transform the path by

Returns

Path

The transformed path


translate()

translate(path, delta): Path

Defined in: path/layout.ts:108

Moves the path by the given delta.

Parameters

ParameterTypeDescription
pathPathThe path to move
deltavec2The translation

Returns

Path

The moved path


trim()

trim(path, from, to, crossFirstPoint): Path

Defined in: path/modifiers.ts:287

Trims the path from the given location to the given location.

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe path to trim
fromPathLocationundefinedThe start location
toPathLocationundefinedThe end location
crossFirstPointbooleantrue-

Returns

Path

The trimmed path


twirl()

twirl(path, center, radius, angle, __namedParameters): Path

Defined in: path/distortions.ts:104

Spins the plane around center: full rotation at the center, none past radius, blended in between. Points outside the radius are left as-is.

Parameters

ParameterTypeDescription
pathPathThe path to distort
centervec2Pivot of the rotation
radiusnumberOutside this distance from center, the distortion does nothing
anglenumberRotation at the center, in degrees (scaled by ramp toward the edge)
__namedParametersRadialDistortOptions-

Returns

Path

The newly created path

Example


unarc()

unarc(path, tolerance): UnarcPath

Defined in: path/modifiers.ts:356

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe path to convert
tolerancenumber0.05The maximum deviation allowed when approximating arcs by cubic Béziers

Returns

UnarcPath

The new path without arc commands

Example


wave()

wave(path, amplitude, wavelength, __namedParameters): Path

Defined in: path/distortions.ts:59

Pushes points side-to-side in a sine pattern: travel along one axis in the plane, offset along the perpendicular.

Parameters

ParameterTypeDescription
pathPathThe path to distort
amplitudenumberHow far points move perpendicular to the wave direction
wavelengthnumberDistance along the wave for one full cycle (non-zero)
__namedParametersWaveOptions-

Returns

Path

The newly created path

Example


zigzag()

zigzag(path, amplitude, wavelength, options): Path

Defined in: path/modifiers.ts:856

Makes the path zigzag along its normal. The peaks are evenly spaced along each curve, and a whole number of them fits: open curves keep their ends in place, and closed curves get an even number so that they stay closed.

Parameters

ParameterTypeDescription
pathPathThe path to make zigzag
amplitudeAttributeLike<number>The distance of the peaks from the path, towards its normal first. It can vary along the path, as the name of an attribute or a function of the vertex; the value between the vertices is interpolated.
wavelengthnumberThe approximate length along the path of one period, of two peaks
optionsZigzagOptionsThe options

Returns

Path

The new path

Example

Boolean Operations

exclude()

exclude(paths): Path

Defined in: path/boolean.ts:120

Excludes the overlapping regions, keeping the region inside an odd number of paths (XOR).

Parameters

ParameterTypeDescription
pathsPath[]The paths to exclude

Returns

Path

The resulting path

Example


intersect()

intersect(paths): Path

Defined in: path/boolean.ts:101

Intersects the given paths, keeping only the region inside all of them.

Parameters

ParameterTypeDescription
pathsPath[]The paths to intersect

Returns

Path

The resulting path

Example


subtract()

subtract(subject, tools): Path

Defined in: path/boolean.ts:80

Subtracts the tools from the subject.

Parameters

ParameterTypeDescription
subjectPathThe target path to be subtracted
toolsPath[]The paths to subtract

Returns

Path

The resulting path

Example


unite()

unite(paths): Path

Defined in: path/boolean.ts:61

Unites the given paths (non-zero winding). Passing a single path removes its self-intersections and normalizes the orientation of its curves.

Parameters

ParameterTypeDescription
pathsPath[]The paths to unite

Returns

Path

The resulting path

Example

Converters

arcify()

arcify(path, options): Path<VertexL | VertexA>

Defined in: path/arcify.ts:74

Converts the cubic Bézier curves in the path to circular arcs. Each cubic is approximated by biarcs (pairs of tangent-continuous circular arcs) so that it stays within tolerance of the original, subdividing where a single biarc is not enough. Cubics and arcs that are straight within the tolerance become lines. Line and arc commands are kept as they are.

Parameters

ParameterTypeDescription
pathPathThe path to convert
optionsArcifyOptionsThe options

Returns

Path<VertexL | VertexA>

The new path that only consists of lines and arcs

Example


drawToCanvas()

drawToCanvas(path, context): void

Defined in: path/canvas.ts:28

Draws the given path to the context. It calls context.beginPath at the beginning, so please note that the sub-paths already stacked on the context are also cleared. Note that you also need to call context.stroke or context.fill to actually draw the path.

Parameters

ParameterTypeDescription
pathPathThe path to draw
contextCanvasRenderingContext2D | OffscreenCanvasRenderingContext2DThe Canvas context

Returns

void


drawToP5()

drawToP5(path, p5Instance): void

Defined in: path/canvas.ts:43

Draws the given path to the context. It calls beginShape at the beginning, drawing the path with vertex and bezierVertex commands, then calls endShape at the end if the curve is closed.

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe path to draw
p5Instance__module | WindowwindowThe p5.js instance. Pass the instance only if you are using p5.js in instance mode.

Returns

void


fromD()

fromD(d): Path

Defined in: path/svg.ts:56

Alias for fromSVGString

Parameters

ParameterTypeDescription
dstringThe d attribute of an SVG path

Returns

Path

The newly created path


fromPaperPath()

fromPaperPath(arg): Path

Defined in: path/paper.ts:163

Creates a path from the given paper.Path or paper.CompoundPath.

Parameters

ParameterType
argPaperPathItemLike

Returns

Path

The newly created path


fromSVG()

fromSVG(commands): Path

Defined in: path/svg.ts:130

Converts an array of SVG commands to a Path.

Parameters

ParameterTypeDescription
commandsSVGCommand[]The array of SVG commands

Returns

Path

The newly created path


fromSVGString()

fromSVGString(d): Path

Defined in: path/svg.ts:16

Parses the given d attribute of an SVG path and creates a new path. Internally uses svgpath library.

Parameters

ParameterTypeDescription
dstringThe d attribute of an SVG path

Returns

Path

The newly created path


toD()

toD(path): string

Defined in: path/svg.ts:122

Alias for toSVGString

Parameters

ParameterTypeDescription
pathPathThe path to convert

Returns

string

The string for the d attribute of the SVG path element


toPaperPath()

toPaperPath<P>(path, paper): InstanceType<P["Path"]> | InstanceType<P["CompoundPath"]>

Defined in: path/paper.ts:89

Converts the given path to a paper.Path, or a paper.CompoundPath when it has several curves. The items are created with insert: false, so they are not added to the active project.

Type Parameters

Type Parameter
P extends PaperNamespace

Parameters

ParameterTypeDescription
pathPathThe path to convert
paperPThe paper module

Returns

InstanceType<P["Path"]> | InstanceType<P["CompoundPath"]>

The newly created Paper.js item

See

http://paperjs.org/reference/pathitem/

Example

import paper from 'paper'
const item = Path.toPaperPath(path, paper)

toPath2D()

toPath2D(arg): Path2D

Defined in: path/canvas.ts:14

Creates a Path2D instance with the given path data.

Parameters

ParameterTypeDescription
argPathThe path to convert

Returns

Path2D

The newly created Path2D


toSVGString()

toSVGString(path): string

Defined in: path/svg.ts:64

Converts the given path to a string that can be used as the d attribute of an SVG path element.

Parameters

ParameterTypeDescription
pathPathThe path to convert

Returns

string

The string for the d attribute of the SVG path element

Draw Functions

addVertex()

addVertex(path, vertex): Path

Defined in: path/drawAppend.ts:53

Appends the given command to the end of the path.

Parameters

ParameterTypeDescription
pathPathThe base path
vertexVertexThe vertex to append

Returns

Path

The newely created path


arcTo()

arcTo(path, radii, xAxisRotation, largeArcFlag, sweepFlag, point): Path

Defined in: path/drawAppend.ts:147

Returns the new path with the new A (arc) command at the end.

Parameters

ParameterTypeDescription
pathPathThe base path
radiivec2The radii of the ellipse used to draw the arc
xAxisRotationnumberThe rotation angle of the ellipse’s x-axis relative to the x-axis of the current coordinate system, expressed in degrees
largeArcFlagbooleanThe large arc flag. If true, then draw the arc spanning greather than 180 degrees. Otherwise, draw the arc spanning less than 180 degrees.
sweepFlagbooleanThe sweep flag. If true, then draw the arc in a “positive-angle” direction in the current coordinate system. Otherwise, draw it in a “negative-angle” direction.
pointvec2The end point of the arc

Returns

Path

The newely created path


cubicBezierTo()

cubicBezierTo(path, control1, control2, point): Path

Defined in: path/drawAppend.ts:94

Returns the new path with the new C (cubic Bézier curve) command at the end.

Parameters

ParameterTypeDescription
pathPathThe base path
control1vec2The first control point
control2vec2The second control point
pointvec2The end point

Returns

Path

The newely created path


lineTo()

lineTo(path, point): Path

Defined in: path/drawAppend.ts:81

Returns the new path with the new L (line-to) command at the end.

Parameters

ParameterTypeDescription
pathPathThe base path
pointvec2The point to draw a line to

Returns

Path

The newely created path


pen()

pen(): Pen

Defined in: path/drawAppend.ts:194

Creates a new Path instance to begin drawing a path.

Returns

Pen


Pen

Defined in: path/drawAppend.ts:202

A class for creating a path by calling draw functions, like Canvas API.

Constructors

new Pen()

new Pen(): Pen

Returns

Pen

Properties

PropertyType
currentundefined | { curve: Curve; lastHandle: vec2; point: vec2; }

Methods

a()

a(radii, xAxisRotation, largeArcFlag, sweepFlag, deltaPoint): Pen

Defined in: path/drawAppend.ts:522

Parameters
ParameterType
radiivec2
xAxisRotationnumber
largeArcFlagboolean
sweepFlagboolean
deltaPointvec2
Returns

Pen

A()

A(radii, xAxisRotation, largeArcFlag, sweepFlag, point): Pen

Defined in: path/drawAppend.ts:494

Parameters
ParameterType
radiivec2
xAxisRotationnumber
largeArcFlagboolean
sweepFlagboolean
pointvec2
Returns

Pen

arcBy()

arcBy(radii, xAxisRotation, largeArcFlag, sweepFlag, deltaPoint): Pen

Defined in: path/drawAppend.ts:504

Parameters
ParameterType
radiivec2
xAxisRotationnumber
largeArcFlagboolean
sweepFlagboolean
deltaPointvec2
Returns

Pen

arcTo()

arcTo(radii, xAxisRotation, largeArcFlag, sweepFlag, point): Pen

Defined in: path/drawAppend.ts:473

Parameters
ParameterType
radiivec2
xAxisRotationnumber
largeArcFlagboolean
sweepFlagboolean
pointvec2
Returns

Pen

c()

c(deltaControl1, deltaControl2, deltaPoint): Pen

Defined in: path/drawAppend.ts:437

Parameters
ParameterType
deltaControl1vec2
deltaControl2vec2
deltaPointvec2
Returns

Pen

C()

C(control1, control2, point): Pen

Defined in: path/drawAppend.ts:419

Parameters
ParameterType
control1vec2
control2vec2
pointvec2
Returns

Pen

close()

close(removeOverwrapped): Pen

Defined in: path/drawAppend.ts:532

Parameters
ParameterTypeDefault value
removeOverwrappedbooleantrue
Returns

Pen

cubicBezierBy()

cubicBezierBy(deltaControl1, deltaControl2, deltaPoint): Pen

Defined in: path/drawAppend.ts:423

Parameters
ParameterType
deltaControl1vec2
deltaControl2vec2
deltaPointvec2
Returns

Pen

cubicBezierTo()

cubicBezierTo(control1, control2, point): Pen

Defined in: path/drawAppend.ts:403

Parameters
ParameterType
control1vec2
control2vec2
pointvec2
Returns

Pen

get()

get(): Path

Defined in: path/drawAppend.ts:562

Returns the path drawn by the pen so far.

Returns

Path

h()

h(dx): Pen

Defined in: path/drawAppend.ts:298

Parameters
ParameterType
dxnumber
Returns

Pen

H()

H(x): Pen

Defined in: path/drawAppend.ts:283

Parameters
ParameterType
xnumber
Returns

Pen

horizBy()

horizBy(dx): Pen

Defined in: path/drawAppend.ts:287

Parameters
ParameterType
dxnumber
Returns

Pen

horizTo()

horizTo(x): Pen

Defined in: path/drawAppend.ts:272

Parameters
ParameterType
xnumber
Returns

Pen

l()

l(delta): Pen

Defined in: path/drawAppend.ts:268

Parameters
ParameterType
deltavec2
Returns

Pen

L()

L(point): Pen

Defined in: path/drawAppend.ts:253

Parameters
ParameterType
pointvec2
Returns

Pen

lineBy()

lineBy(delta): Pen

Defined in: path/drawAppend.ts:257

Parameters
ParameterType
deltavec2
Returns

Pen

lineTo()

lineTo(point): Pen

Defined in: path/drawAppend.ts:242

Parameters
ParameterType
pointvec2
Returns

Pen

m()

m(delta): Pen

Defined in: path/drawAppend.ts:238

Parameters
ParameterType
deltavec2
Returns

Pen

M()

M(point): Pen

Defined in: path/drawAppend.ts:223

Parameters
ParameterType
pointvec2
Returns

Pen

moveBy()

moveBy(delta): Pen

Defined in: path/drawAppend.ts:227

Parameters
ParameterType
deltavec2
Returns

Pen

moveTo()

moveTo(point): Pen

Defined in: path/drawAppend.ts:212

Parameters
ParameterType
pointvec2
Returns

Pen

q()

q(delta, delta2): Pen

Defined in: path/drawAppend.ts:369

Parameters
ParameterType
deltavec2
delta2vec2
Returns

Pen

Q()

Q(control, point): Pen

Defined in: path/drawAppend.ts:352

Parameters
ParameterType
controlvec2
pointvec2
Returns

Pen

quadraticCurveBy()

quadraticCurveBy(deltaControl, deltaPoint): Pen

Defined in: path/drawAppend.ts:356

Parameters
ParameterType
deltaControlvec2
deltaPointvec2
Returns

Pen

quadraticCurveTo()

quadraticCurveTo(control, point): Pen

Defined in: path/drawAppend.ts:332

Parameters
ParameterType
controlvec2
pointvec2
Returns

Pen

s()

s(deltaControl2, deltaPoint): Pen

Defined in: path/drawAppend.ts:469

Parameters
ParameterType
deltaControl2vec2
deltaPointvec2
Returns

Pen

S()

S(control2, point): Pen

Defined in: path/drawAppend.ts:451

Parameters
ParameterType
control2vec2
pointvec2
Returns

Pen

smoothCubicBezierBy()

smoothCubicBezierBy(deltaControl2, deltaPoint): Pen

Defined in: path/drawAppend.ts:455

Parameters
ParameterType
deltaControl2vec2
deltaPointvec2
Returns

Pen

smoothCubicBezierTo()

smoothCubicBezierTo(control2, point): Pen

Defined in: path/drawAppend.ts:441

Parameters
ParameterType
control2vec2
pointvec2
Returns

Pen

smoothQuadraticCurveBy()

smoothQuadraticCurveBy(delta): Pen

Defined in: path/drawAppend.ts:387

Parameters
ParameterType
deltavec2
Returns

Pen

smoothQuadraticCurveTo()

smoothQuadraticCurveTo(point): Pen

Defined in: path/drawAppend.ts:373

Parameters
ParameterType
pointvec2
Returns

Pen

t()

t(delta): Pen

Defined in: path/drawAppend.ts:399

Parameters
ParameterType
deltavec2
Returns

Pen

T()

T(point): Pen

Defined in: path/drawAppend.ts:383

Parameters
ParameterType
pointvec2
Returns

Pen

v()

v(dy): Pen

Defined in: path/drawAppend.ts:328

Parameters
ParameterType
dynumber
Returns

Pen

V()

V(y): Pen

Defined in: path/drawAppend.ts:313

Parameters
ParameterType
ynumber
Returns

Pen

vertBy()

vertBy(dy): Pen

Defined in: path/drawAppend.ts:317

Parameters
ParameterType
dynumber
Returns

Pen

vertTo()

vertTo(y): Pen

Defined in: path/drawAppend.ts:302

Parameters
ParameterType
ynumber
Returns

Pen

Z()

Z(removeOverwrapped): Pen

Defined in: path/drawAppend.ts:555

Parameters
ParameterTypeDefault value
removeOverwrappedbooleantrue
Returns

Pen


quadraticBezierTo()

quadraticBezierTo(path, control, point): Path

Defined in: path/drawAppend.ts:115

Returns the new path with the new Q (quadratic Bézier curve) command at the end.

Parameters

ParameterTypeDescription
pathPathThe base path
controlvec2The control point
pointvec2The end point

Returns

Path

The newely created path

Utilities

align()

align(paths, mode, options): Path[]

Defined in: path/layout.ts:157

Lines the paths up by their bounds, like the Align panel of Illustrator. Paths without curves are left as they are.

Parameters

ParameterTypeDescription
pathsPath[]The paths to align
modeAlignModeWhich edge or center of the bounds to line up
optionsAlignOptionsThe options

Returns

Path[]

The aligned paths, in the same order

Example


blend()

blend(a, b, t): Path

Defined in: path/layout.ts:345

Interpolates between two paths, like the Blend tool of Illustrator. Both are converted to cubic Béziers and given the same structure: curves are paired by index, a curve without a partner blends to a copy of itself collapsed to the center of its bounds, and the curve of a pair with fewer segments has its segments subdivided (exactly, without changing its shape) until the counts match. Every point and handle is then interpolated linearly, as are the attributes.

A pair of an open and a closed curve is closed when t is nearer to the closed one.

Parameters

ParameterTypeDescription
aPathThe path at t = 0
bPathThe path at t = 1
tnumberThe interpolation factor, which may be outside [0, 1]

Returns

Path

The interpolated path

Example


blendSeries()

blendSeries(a, b, count): Path[]

Defined in: path/layout.ts:357

The intermediate steps of Path.blend, what the Blend tool of Illustrator draws between two paths.

Parameters

ParameterTypeDescription
aPathThe path at the start
bPathThe path at the end
countnumberThe number of the steps between the two paths, excluding them

Returns

Path[]

The steps, from the one nearest to a to the one nearest to b


breakApart()

breakApart(path): Path[]

Defined in: path/structure.ts:107

Breaks the path into one path per curve. Each of them keeps the attributes and the definitions of the whole path.

Parameters

ParameterTypeDescription
pathPathThe path to break apart

Returns

Path[]

The paths, one for each curve, in order


connect()

connect(paths, options): Path

Defined in: path/structure.ts:118

Connects the open curves of the paths into a single open curve by their nearest endpoints, like the Join command of Illustrator with multiple paths selected. Starting from the first open curve, the curve whose endpoint is nearest to the current end is appended, reversed when its end is nearer than its start, with a line segment between them unless the endpoints coincide. Closed curves are kept as they are.

Parameters

ParameterTypeDescription
pathsPath[]The paths to connect
optionsConnectOptionsThe options

Returns

Path

The path with the connected chain, followed by the closed curves


distribute()

distribute(paths, axis, options): Path[]

Defined in: path/layout.ts:217

Spreads the paths evenly along an axis, like the Distribute commands of Illustrator. The paths are ordered by the centers of their bounds along the axis, and the first and the last stay where they are unless within says otherwise. Paths without curves are left as they are.

Parameters

ParameterTypeDescription
pathsPath[]The paths to distribute
axis"x" | "y"The axis along which to distribute
optionsDistributeOptionsThe options

Returns

Path[]

The distributed paths, in the same order


dubinsTypes()

dubinsTypes(start, startAngle, end, endAngle, radius): object[]

Defined in: path/dubins.ts:224

Lists the sequences of Dubins paths possible between two directed points with their lengths, the shortest first. Some sequences do not exist between close points. With this, the type chosen for one setting can be reused for another by the type option of dubins, for example to keep the shape from switching during an animation.

Parameters

ParameterTypeDescription
startvec2The start point
startAnglenumberThe direction of travel at the start, in degrees
endvec2The end point
endAnglenumberThe direction of travel at the end, in degrees
radiusnumberThe minimum turning radius

Returns

object[]

The possible types and their lengths

Example


repeatAlong()

repeatAlong(path, stamp, options): Path

Defined in: path/layout.ts:565

Places copies of the stamp along the path, like a pattern brush. The origin of the stamp lands on the path, and its x axis follows the tangent unless rotate is false.

Parameters

ParameterTypeDescription
pathPathThe path to place the copies along
stampPathThe path to copy
optionsRepeatAlongOptionsThe options

Returns

Path

The copies merged into a single path

Example


toTime()

toTime(path, location): Required<TimePathLocation> & object

Defined in: path/location.ts:23

Retrieves the segment location information from the given path and path-based signed location.

Parameters

ParameterTypeDescription
pathPathThe path to retrieve the segment location
locationPathLocationThe path-based location

Returns

Required<TimePathLocation> & object

The information of the segment location


unlinearSegmentIndex()

unlinearSegmentIndex(path, linearSegmentIndex): object

Defined in: path/location.ts:140

Converts a signed linear segment index to a pair of curve and unsgined segment index.

Parameters

ParameterType
pathPath
linearSegmentIndexnumber

Returns

object

NameType
curveIndexnumber
segmentIndexnumber

Aliases

fromD()

fromD(d): Path

Defined in: path/svg.ts:56

Alias for fromSVGString

Parameters

ParameterTypeDescription
dstringThe d attribute of an SVG path

Returns

Path

The newly created path


subdiv()

subdiv(path, division): Path

Defined in: path/modifiers.ts:457

Alias for subdivide

Parameters

ParameterTypeDescription
pathPathThe path to subdivide
divisionnumberThe number of division for each segment

Returns

Path

The newly created path


toC()

toC(path, tolerance): PathC

Defined in: path/modifiers.ts:391

Alias for toCubicBezier

Parameters

ParameterTypeDefault valueDescription
pathPathundefinedThe path to convert
tolerancenumber0.05The maximum deviation allowed when approximating arc commands by cubic Béziers

Returns

PathC

The new path with only cubic Bézier curve commands


toD()

toD(path): string

Defined in: path/svg.ts:122

Alias for toSVGString

Parameters

ParameterTypeDescription
pathPathThe path to convert

Returns

string

The string for the d attribute of the SVG path element

Attributes

attribute()

attribute(path, name, location): undefined | AttributeValue

Defined in: path/attributes.ts:57

Reads the attribute at the location. It is looked up on the vertices, the curve, the path and in the definition in this order, and is interpolated between the two ends of the segment by time.

Parameters

ParameterTypeDescription
pathPathThe path to read
namestringThe name of the attribute
locationPathLocationThe location on the path

Returns

undefined | AttributeValue

The value, or undefined if it is not set anywhere


attributeNames()

attributeNames(path): string[]

Defined in: path/attributes.ts:81

Lists the names of the attributes set on any level or defined in the path.

Parameters

ParameterType
pathPath

Returns

string[]


defineAttribute()

defineAttribute(path, name, def): Path

Defined in: path/attributes.ts:269

Defines the default value and the interpolation of an attribute. This is optional: without a definition there is no default, and numbers are interpolated linearly, booleans by and, and anything else by step.

Parameters

ParameterType
pathPath
namestring
defAttributeDef

Returns

Path


deleteAttribute()

deleteAttribute(path, name, options): Path

Defined in: path/attributes.ts:208

Removes an attribute.

Parameters

ParameterTypeDescription
pathPathThe base path
namestringThe name of the attribute
options{ level: AttributeLevel; }level limits the removal to one level, so that the values on the upper levels can be read again. Without it, the definition is removed as well.
options.level?AttributeLevel-

Returns

Path

The new path


renameAttribute()

renameAttribute(path, from, to): Path

Defined in: path/attributes.ts:243

Renames an attribute on all the levels and in the definitions.

Parameters

ParameterType
pathPath
fromstring
tostring

Returns

Path


setAttribute()

Call Signature

setAttribute(path, name, value, options?): Path

Defined in: path/attributes.ts:126

Sets an attribute. A group is just a boolean attribute, so this also makes one.

Parameters
ParameterTypeDescription
pathPathThe base path
namestringThe name of the attribute
valueAttributeLike<AttributeValue>The value, the name of another attribute to copy, or a function to compute it
options?{ group: AttributeLike<boolean>; level: "vertex"; }The options
options.group?AttributeLike<boolean>-
options.level?"vertex"-
Returns

Path

The new path

Example

Call Signature

setAttribute(path, name, value, options): Path

Defined in: path/attributes.ts:132

Sets an attribute. A group is just a boolean attribute, so this also makes one.

Parameters
ParameterTypeDescription
pathPathThe base path
namestringThe name of the attribute
valueAttributeValue | (curve, context) => AttributeValueThe value, the name of another attribute to copy, or a function to compute it
options{ level: "curve"; }The options
options.level"curve"-
Returns

Path

The new path

Example

Call Signature

setAttribute(path, name, value, options): Path

Defined in: path/attributes.ts:140

Sets an attribute. A group is just a boolean attribute, so this also makes one.

Parameters
ParameterTypeDescription
pathPathThe base path
namestringThe name of the attribute
valueAttributeValue | (path) => AttributeValueThe value, the name of another attribute to copy, or a function to compute it
options{ level: "path"; }The options
options.level"path"-
Returns

Path

The new path

Example

Options

AlignMode

AlignMode: "left" | "centerX" | "right" | "top" | "centerY" | "bottom" | "center"

Defined in: path/layout.ts:16

How Path.align lines the paths up


AlignOptions

Defined in: path/layout.ts:29

An options for Path.align

Properties

PropertyTypeDescription
to?Rect | "selection"The rect to align the paths to. 'selection' is the union of the bounds of all the paths. Default 'selection'

ArcifyOptions

Defined in: path/arcify.ts:18

An options for Path.arcify

Properties

PropertyTypeDescription
tolerance?numberThe maximum deviation allowed between the arcified path and the original, in the same unit as the coordinates. Default 0.05

ArcOptions

ArcOptions: object

Defined in: path/primitives.ts:26

An options for Path.arc

Type declaration

NameTypeDescription
align?"uniform" | "start" | "center" | "end"The alignment of the vertices Default 'uniform'
count?numberThe total count of the segments in the arc. If this is specified, the step will be ignored and the arc will be deviced into the specified number of segments uniformly.
step?numberThe maximum angle step in degrees Default 360 - 1e-4

CircleFromPointsOptions

Defined in: path/primitives.ts:14

Properties

PropertyTypeDescription
preferredSweep?booleanIf the given points are less than three and the circumcenter cannot be well-defined, the circle will be drawn in the direction of the sweep flag. (in Canvas API, it means clockwise). Default true

CleanupOptions

Defined in: path/structure.ts:38

An options for Path.cleanup

Properties

PropertyTypeDescription
removeDots?booleanIf true, curves consisting of a single vertex are removed as well Default false
tolerance?numberThe distance below which a segment counts as zero-length, a vertex as lying on the line through its neighbours, and a handle as lying on the chord Default 1e-6

ClothoidOptions

Defined in: path/spirals.ts:40

The options for clothoid

Properties

PropertyTypeDescription
tolerance?numberThe largest distance allowed from the exact curve. Default 0.05

ConnectOptions

Defined in: path/structure.ts:21

An options for Path.connect

Properties

PropertyTypeDescription
close?booleanIf true, the connected chain is also closed Default false
tolerance?numberEndpoints within this distance are fused into one vertex instead of being connected by a line segment Default 1e-6

ContainsOptions

Defined in: path/queries.ts:22

The options for Path.contains.

Properties

PropertyTypeDescription
fillRule?FillRuleDefault 'nonzero'

ConvertVertexOptions

Defined in: path/vertexEdit.ts:38

An options for Path.convertVertex

Properties

PropertyTypeDescription
handleLength?numberThe length of both handles when converting to symmetric. By default, the mean of the current lengths is used.

ConvexHullOptions

Defined in: path/hull.ts:47

The options for Path.convexHull.

Properties

PropertyTypeDescription
steps?numberThe number of directions the hull is swept with. The switches between segments are refined by bisection afterwards, so this only has to be fine enough to notice every segment on the hull. Default 720

CornerCubicOptions

Defined in: path/modifiers.ts:1130

Extends

  • CornerOptions

Properties

PropertyTypeDescriptionInherited from
group?AttributeLike<boolean>Which corners to process: a boolean attribute’s name, or a function of the vertex at the corner. All of them by default.CornerOptions.group
handle?AttributeLike<number>The length of the handles, relative to the distance from each cut to the point where the tangents meet. It is 0 for a chamfer, 2/3 for a parabola, 1 for a sharp tip and 2 for a cusp; beyond that the curve makes a loop. By default, it is the value closest to a circular arc, off by 0.03% of the radius at right angles and 0.3% at a turn of 135°.-

CornerOptions

Defined in: path/modifiers.ts:575

An options for Path.fillet and Path.chamfer

Extended by

  • CornerCubicOptions
  • CornerShapeOptions

Properties

PropertyTypeDescription
group?AttributeLike<boolean>Which corners to process: a boolean attribute’s name, or a function of the vertex at the corner. All of them by default.

CornerShapeOptions

Defined in: path/modifiers.ts:1186

Extends

  • CornerOptions

Properties

PropertyTypeDefault valueDescriptionInherited from
group?AttributeLike<boolean>undefinedWhich corners to process: a boolean attribute’s name, or a function of the vertex at the corner. All of them by default.CornerOptions.group
tolerance?number0.05The maximum deviation allowed when approximating a shape by cubic Béziers-

DashOptions

Defined in: path/dash.ts:11

An options for Path.dash

Properties

PropertyTypeDescription
offset?numberThe distance into the pattern at which each curve starts, like stroke-dashoffset of SVG. A negative value shifts the pattern the other way. Default 0

DeleteVertexOptions

Defined in: path/vertexEdit.ts:72

An options for Path.deleteVertex

Properties

PropertyTypeDefault valueDescription
preserveShape?booleantrueIf true, the two segments meeting at the vertex are replaced by a single cubic Bézier fitted to them, so the shape changes as little as possible. If false, the vertex is just dropped and the following segment keeps its command and handles.

DisplaceOptions

Defined in: path/displace.ts:37

Properties

PropertyTypeDefault valueDescription
breaks?Iterable<number, any, any>undefinedThe units on each curve where the displacement has a corner, such as the peak of a triangular wave. A corner can only appear exactly on one of them, or on a joint of the path.
tolerance?number0.05The maximum deviation allowed when approximating the result by cubic Béziers

DistortOptions

Defined in: path/modifiers.ts:69

Extended by

  • WaveOptions
  • RadialDistortOptions

Properties

PropertyTypeDescription
tolerance?numberThe maximum deviation allowed between the distorted path and the true image of the original path, in the same unit as the coordinates. Segments are subdivided until the fitted cubics stay within it. Default 0.05

DistributeOptions

Defined in: path/layout.ts:41

An options for Path.distribute

Properties

PropertyTypeDescription
mode?"centers" | "gaps"centers: the centers of the bounds are evenly spaced. gaps: the gaps between the bounds are equal. Default 'centers'
within?RectThe extent the paths are spread over, along the axis: the first path in order starts at its beginning and the last ends at its end. By default, it is what the paths already span, so the two extremes stay where they are.

DubinsOptions

Defined in: path/dubins.ts:21

Properties

PropertyTypeDescription
type?DubinsTypeUses this sequence instead of the shortest one. It throws an error if the sequence is not possible between the two points.

FitIntoOptions

Defined in: path/layout.ts:57

An options for Path.fitInto

Properties

PropertyTypeDescription
align?vec2Where the bounds sit in the rect when there is room left, as a fraction of the room on each axis: [0, 0] for the top-left corner, [1, 1] for the bottom-right. Default [0.5, 0.5]
mode?"contain" | "cover" | "stretch"contain: scaled uniformly to fit inside the rect. cover: scaled uniformly to fill the rect. stretch: scaled on each axis to match the rect exactly. Default 'contain'

FitOptions

Defined in: path/fitting.ts:19

An options for Path.fit

Properties

PropertyTypeDefault valueDescription
closed?booleanfalseIf true, the points are regarded as a loop and a closed curve is returned.
tolerance?number2.5The maximum distance allowed between the given points and the fitted curve, in the same unit as the coordinates.

FormulaOptions

Defined in: path/primitives.ts:47

The options for Path.formula

Properties

PropertyTypeDescription
delta?numberThe delta value for calculating the derivative of the formula Default 1e-6

HitTestOptions

Defined in: path/queries.ts:43

The options for Path.hitTest.

Properties

PropertyTypeDescription
fillRule?null | FillRuleThe fill rule used for hits on the inside of the path. Set to null to never report the fill. Default 'nonzero'
tolerance?numberHow far from a vertex, a handle or the stroke a point still counts as hitting it. Default 4

IntersectionsOptions

Defined in: path/queries.ts:82

The options for Path.intersections and Path.selfIntersections.

Properties

PropertyTypeDescription
tolerance?numberHow close two curves have to come to count as touching. Default 1e-9 relative to the size of the paths

MoveVertexOptions

Defined in: path/vertexEdit.ts:60

An options for Path.moveVertex

Properties

PropertyTypeDefault valueDescription
handles?booleantrueIf true, the handles of the vertex move along with it, keeping the shape around the vertex. If false, they stay where they are.

NormalizeWindingOptions

Defined in: path/structure.ts:55

An options for Path.normalizeWinding

Properties

PropertyTypeDescription
fillRule?"nonzero" | "evenodd"The fill rule deciding which regions of the input count as filled Default 'nonzero'

OffsetOptions

Defined in: path/offset.ts:56

Extended by

  • OffsetStrokeOptions

Properties

PropertyTypeDefault valueDescription
lineJoin?CanvasLineJoin'miter'The join style at the vertices where the offset curves diverge
miterLimit?number10The limit for miter style, as the ratio of the miter length to the offset distance See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/miterLimit
tolerance?number0.05The maximum deviation allowed when approximating offset cubic Béziers and elliptic arcs

OffsetStrokeOptions

Defined in: path/offset.ts:78

Extends

  • OffsetOptions

Properties

PropertyTypeDefault valueDescriptionInherited from
lineCap?CanvasLineCap'butt'The cap style at the ends of open curves-
lineJoin?CanvasLineJoin'miter'The join style at the vertices where the offset curves divergeOffsetOptions.lineJoin
miterLimit?number10The limit for miter style, as the ratio of the miter length to the offset distance See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/miterLimitOffsetOptions.miterLimit
tolerance?number0.05The maximum deviation allowed when approximating offset cubic Béziers and elliptic arcsOffsetOptions.tolerance

PathCloseOptions

PathCloseOptions: object

Defined in: path/drawAppend.ts:11

An options for Path.close

Type declaration

NameTypeDescription
fuse?booleanIf true, deletes overwrapped first and last vertices. Default true
group?CurveGroupSpecifies which curves to close. Default is the last curve. Default -1

RadialDistortOptions

Defined in: path/distortions.ts:34

Extends

  • DistortOptions

Properties

PropertyTypeDescriptionInherited from
ramp?(t: number) => numberFalloff from the center: receives 1 at the center and 0 at the radius, returns the strength multiplier. Default t => t (linear)-
tolerance?numberThe maximum deviation allowed between the distorted path and the true image of the original path, in the same unit as the coordinates. Segments are subdivided until the fitted cubics stay within it. Default 0.05DistortOptions.tolerance

RaycastOptions

Defined in: path/raycast.ts:31

The options for Path.raycast.

Properties

PropertyTypeDescription
both?booleanWhen true, the ray extends behind the origin too, becoming a line. Default false
maxDistance?numberHits farther than this are left out. Default Infinity
tolerance?numberHits closer than this to one another are merged, which happens where the ray passes through a vertex. Default 1e-9 relative to the size of the path

ReduceOptions

ReduceOptions: ReduceOptions & object

Defined in: path/drawAppend.ts:28

An options for Path.reduce

Type declaration

NameTypeDescription
removeEmptyCurves?booleanIf true, removes the curves with zero length Default true

RepeatAlongOptions

Defined in: path/layout.ts:74

An options for Path.repeatAlong

Properties

PropertyTypeDescription
align?"uniform" | "start" | "center" | "end"How the copies sit along the length. uniform: evenly spread with both ends included. start, center, end: the length is divided into count cells and the copies sit at the start, the center, or the end of each. With spacing, the run of the copies is placed at the start, the center, or the end of the length, or stretched over it for uniform. Default 'uniform'
count?numberThe number of the copies. Ignored when spacing is given. Default 10
offset?numberThe arc length added to the position of every copy. The positions wrap around a path of a single closed curve, and are clamped to the ends otherwise. Default 0
rotate?booleanIf true, the copies are rotated to the tangent of the path, with their x axis along it Default true
spacing?numberThe arc length between the copies. When given, as many copies as fit are placed.

ReverseOptions

Defined in: path/modifiers.ts:58

An options for Path.reverse

Properties

PropertyTypeDefault valueDescription
per?"curve" | "path"'path'The unit to reverse the path.

SetAttributeOptions

SetAttributeOptions: { group: AttributeLike<boolean>; level: "vertex"; } | { group: undefined; level: "curve"; } | { group: undefined; level: "path"; }

Defined in: path/attributes.ts:98

Type declaration

{ group: AttributeLike<boolean>; level: "vertex"; }

NameTypeDescription
group?AttributeLike<boolean>Only writes to the vertices this selects; the others keep their values.
level?"vertex"The level to write to. The value is passed the vertex, the curve or the path accordingly if it is a function.

{ group: undefined; level: "curve"; }

NameType
group?undefined
level"curve"

{ group: undefined; level: "path"; }

NameType
group?undefined
level"path"

SetHandleOptions

Defined in: path/vertexEdit.ts:49

An options for Path.setHandle

Properties

PropertyTypeDescription
link?VertexType | "none"How the opposite handle follows: not at all, in direction only (smooth), or in direction and length (symmetric). By default, it follows the way the vertex currently is, as reported by Path.vertexType.

SimplifyOptions

Defined in: path/fitting.ts:36

An options for Path.simplify

Properties

PropertyTypeDefault valueDescription
tolerance?number2.5The maximum distance allowed between the original path and the simplified one, in the same unit as the coordinates.

SmoothOptions

Defined in: path/fitting.ts:65

An options for Path.smooth

Properties

PropertyTypeDefault valueDescription
factor?number0.5The alpha of the Catmull-Rom spline the handles are taken from: 0 is uniform, 0.5 is centripetal, and 1 is chordal. Larger values make the handles of a vertex more unequal when its neighbours are at unequal distances, which avoids cusps and overshoots.

SpawnOptions

Defined in: path/modifiers.ts:46

Properties

PropertyTypeDefault valueDescription
join?booleantrueIf true, the continuous open path will be joined

SpiralOptions

Defined in: path/spirals.ts:18

The options for spiral

Properties

PropertyTypeDescription
startAngle?numberThe angle at the start in degrees, in which 0° is +X and the angle increases clockwise on a Y-down canvas. Default 0
tolerance?numberThe largest distance allowed from the exact curve. Default 0.05
type?"archimedean" | "logarithmic"How the radius changes along the angle. 'archimedean' grows by the same amount for each turn, like a coil of rope, so that the gaps stay even. 'logarithmic' grows by the same ratio, like a nautilus shell, so that the shape looks the same at any scale, and both radii must be positive. Default 'archimedean'

SplineOptions

Defined in: path/fitting.ts:48

An options for Path.spline

Properties

PropertyTypeDefault valueDescription
closed?booleanfalseIf true, the spline wraps around and a closed curve is returned.
tension?number0.5How far the handles reach, in the range of 0 to 1. Each handle of a vertex is tension / 3 of the vector between its neighbours, so 0 makes every segment straight, 0.5 is the uniform Catmull-Rom spline, and 1 is twice as loose as that.

SuperellipseOptions

Defined in: path/superellipse.ts:22

The options for superellipse

Properties

PropertyTypeDescription
tolerance?numberThe largest distance allowed from the exact curve. Default 0.05

TangentsOptions

Defined in: path/hull.ts:35

The options for Path.tangentsAlong and Path.tangentsFrom.

Properties

PropertyTypeDescription
extreme?booleanWhen true, only the two tangents that bound the whole path are returned: the silhouette seen from the light. Otherwise every local tangent is returned. Default false

WaveOptions

Defined in: path/distortions.ts:13

Extends

  • DistortOptions

Properties

PropertyTypeDescriptionInherited from
angle?numberRotates the wave direction in the plane, in degrees Default 0-
origin?vec2A reference point on the wave axis. With angle, it fixes the frame of the wave. Default [0, 0]-
phase?numberShifts the wave along its direction, in degrees (360 = one full cycle) Default 0-
tolerance?numberThe maximum deviation allowed between the distorted path and the true image of the original path, in the same unit as the coordinates. Segments are subdivided until the fitted cubics stay within it. Default 0.05DistortOptions.tolerance

ZigzagOptions

Defined in: path/modifiers.ts:824

Properties

PropertyTypeDefault valueDescription
phase?number0Shifts the zigzag along the path, in periods, so that animating it from 0 to 1 makes a seamless loop. A positive value moves the peaks backwards along the path. An open curve keeps its ends in place only when this is a multiple of 0.5; otherwise they follow the wave, so that no peak pops in or out at the ends.
smooth?booleanfalseDraws waves instead of straight zigzags.

Other

circleFromPoints()

circleFromPoints(p1, p2?, p3?, __namedParameters?): Path

Defined in: path/primitives.ts:234

Parameters

ParameterType
p1vec2
p2?null | vec2
p3?null | vec2
__namedParameters?CircleFromPointsOptions

Returns

Path


close()

close(path, __namedParameters): Path

Defined in: path/drawAppend.ts:161

Parameters

ParameterType
pathPath
__namedParametersPathCloseOptions

Returns

Path


empty

const empty: Path

Defined in: path/primitives.ts:55


formula()

formula(f, iter, __namedParameters): Path

Defined in: path/primitives.ts:935

Parameters

ParameterType
f(t) => vec2
iterIterable<number>
__namedParametersFormulaOptions

Returns

Path


moveTo()

moveTo(path, point): Path

Defined in: path/drawAppend.ts:36

Parameters

ParameterType
pathPath
pointvec2

Returns

Path


polyline()

polyline(…points): PathL

Defined in: path/primitives.ts:670

Parameters

ParameterType
…pointsvec2[]

Returns

PathL


spawnVertex()

spawnVertex<V1, V2>(path, fn): Path<V2>

Defined in: path/modifiers.ts:77

Type Parameters

Type ParameterDefault type
V1 extends VertexVertex
V2 extends VertexVertex

Parameters

ParameterType
pathPath<V1>
fn(segment, segmentIndex, curve) => V2 | V2[]

Returns

Path<V2>

Types

Corner

Defined in: path/modifiers.ts:1015

A corner being cut, passed to the function that fills the gap in Path.cutCorners.

Properties

PropertyTypeDescription
apexvec2Where the tangents at start and end meet. It is the original point between straight segments, and falls back on it when the tangents do not meet ahead.
contextVertexContextWhere the vertex is
endvec2Where the outgoing segment now starts
endTangentvec2The unit direction of the outgoing segment at end
jointvec2The original point of the corner
startvec2Where the incoming segment now ends
startTangentvec2The unit direction of the incoming segment at start
turnnumberHow much the path turns from startTangent to endTangent, in degrees
vertexVertexThe vertex at the corner

DisplaceContext

Defined in: path/displace.ts:18

Where a point being displaced is, passed to the function of Path.displace.

Properties

PropertyTypeDescription
attrsundefined | Readonly<Record<string, AttributeValue>>The attributes of the vertices, interpolated here
curveCurveThe curve being displaced
curveIndexnumber-
lengthnumberThe arc length of the curve
normalvec2The unit normal of the path
pointvec2The point on the path
tangentvec2The unit direction of the path

DubinsType

DubinsType: "LSL" | "RSR" | "LSR" | "RSL" | "RLR" | "LRL"

Defined in: path/dubins.ts:16

The sequence of a Dubins path. R turns clockwise as seen on a Y-down canvas, which is towards increasing angles, L turns the other way, and S goes straight.


FillRule

FillRule: "nonzero" | "evenodd"

Defined in: path/queries.ts:16

The fill rule deciding which regions a self-overlapping path fills, as in SVG.


HitTestResult

HitTestResult: { curveIndex: number; point: vec2; type: "vertex"; vertexIndex: number; } | { curveIndex: number; point: vec2; side: "in" | "out"; type: "handle"; vertexIndex: number; } | { distance: number; location: Required<TimePathLocation>; point: vec2; type: "stroke"; } | { type: "fill"; }

Defined in: path/queries.ts:60

What Path.hitTest found under the point, in the order they are looked for.

Type declaration

{ curveIndex: number; point: vec2; type: "vertex"; vertexIndex: number; }

NameType
curveIndexnumber
pointvec2
type"vertex"
vertexIndexnumber

{ curveIndex: number; point: vec2; side: "in" | "out"; type: "handle"; vertexIndex: number; }

NameTypeDescription
curveIndexnumber-
pointvec2-
side"in" | "out"in for the handle arriving at the vertex, out for the one leaving it
type"handle"-
vertexIndexnumber-

{ distance: number; location: Required<TimePathLocation>; point: vec2; type: "stroke"; }

NameType
distancenumber
locationRequired<TimePathLocation>
pointvec2
type"stroke"

{ type: "fill"; }

NameType
type"fill"

MirrorAxis

MirrorAxis: AxisLine | readonly [vec2, vec2]

Defined in: path/mirror.ts:24

The axis of a reflection. Either a directed line of geome, or two distinct points on the line. Two points [p1, p2] give the line whose normal is the direction from p1 to p2 rotated by +90° (x+ towards y+).


NearestPoint

Defined in: path/queries.ts:33

The nearest point of a path to a point.

Properties

PropertyType
distancenumber
locationRequired<TimePathLocation>
pointvec2

OrientedRect

Defined in: path/hull.ts:59

A rectangle of any rotation.

Properties

PropertyTypeDescription
centervec2-
corners[vec2, vec2, vec2, vec2]The four corners, in order around the rectangle
rotationnumberThe rotation of the rectangle in degrees
sizevec2-

PathIntersection

Defined in: path/queries.ts:94

A point where two paths cross.

Properties

PropertyTypeDescription
aRequired<TimePathLocation>Where on the first path
bRequired<TimePathLocation>Where on the second path
pointvec2-

PathPoint

Defined in: path/hull.ts:13

A point on a path, with where it lies.

Extended by

  • TangentHit

Properties

PropertyType
locationRequired<TimePathLocation>
pointvec2

RayHit

Defined in: path/raycast.ts:14

Where a ray hits the path.

Properties

PropertyTypeDescription
distancenumberThe distance from the origin of the ray. Negative when behind the origin, which only happens with both.
frontbooleanTrue when the ray hits the path from its normal side
locationRequired<TimePathLocation>-
normalvec2The unit normal of the path at the hit, see Path.normal
pointvec2-
tangentvec2The unit tangent of the path at the hit

TangentHit

Defined in: path/hull.ts:22

A point where a line touches the path.

Extends

  • PathPoint

Properties

PropertyTypeDescriptionInherited from
locationRequired<TimePathLocation>-PathPoint.location
pointvec2-PathPoint.point
side"left" | "right" | "cross"On which side of the directed tangent line the path lies near the point: left is the side of Path.normal of tangent. cross when the line crosses the path there, as at an inflection.-
tangentvec2The direction of the touching line.-

VertexAddress

Defined in: path/vertexEdit.ts:19

Which vertex of a path to edit. Negative indices count from the end, like Array.at.

Properties

PropertyType
curveIndexnumber
vertexIndexnumber

VertexType

VertexType: "corner" | "smooth" | "symmetric"

Defined in: path/vertexEdit.ts:32

How the two handles of a vertex relate to each other.

  • corner: The handles are independent, so the path can bend there.
  • smooth: The handles are opposite to each other, so the tangent is continuous.
  • symmetric: The handles are opposite and of equal length.
Edit this page