Path2D

A 2D path.

Constructor

new Path2D(points)

Creates a new Path2D with the given points.

Parameters:
NameTypeDescription
pointsArray.<Point2D>

The points of the path.

Classes

Path2D

Members

cubic_bezier_tuples

Returns a CubicBezierTuple at a given index.

first

Gets the first point of the Path2D.

is_empty

Returns whether the Path2D is empty.

last

Gets the last point of the Path2D.

len

Returns the length of the Path2D.

points

Returns the Point2Ds of the Path2D.

points

Sets the Point2Ds of the Path2D.

Methods

clear()

Removes all Point2Ds from the Path2D.

clone() → {Path2D}

Clones the Path2D.

Returns:
Type: 
Path2D

closest_point(point) → {Point2D}

Returns the closest Point2D in the Path2D to a given Point2D.

Parameters:
NameTypeDescription
pointPoint2D

The point to find the closest point to.

Returns:

The closest point in the path.

Type: 
Point2D

get(index) → {Point2D}

Returns the Point2D at a given index.

Parameters:
NameTypeDescription
indexnumber

The index of the point.

Returns:

The first point of the path.

Type: 
Point2D

insert(index, point)

Inserts a Point2D at a given index.

Parameters:
NameTypeDescription
indexnumber

The index to insert the point at.

pointPoint2D

The point to insert.

length(samples_per_cubicopt, extra_length_per_cubicopt) → {number}

Returns an approximation of the length of the path, based on sampling points along each cubic bezier curve in the path and an optional extra length to add to each approximation.

Parameters:
NameTypeAttributesDescription
samples_per_cubicnumber | null<optional>

The number of samples to take along each cubic bezier curve.

extra_length_per_cubicnumber | null<optional>

An optional extra length to add to each cubic bezier length approximation.

Returns:

An approximation of the length of the path.

Type: 
number

partial_bezier_path(a, b) → {Path2D}

Returns a new Path2D representing a bezier curve portion of the Path2D.

Parameters:
NameTypeDescription
anumber

The start proportion of the input path. A number between 0 and 1.

bnumber

The end proportion of the input path. A number between 0 and 1.

Returns:

A Path2D object representing the portion of the input path.

Type: 
Path2D

pop() → {Point2D|undefined}

Removes the last Point2D from the Path2D.

Returns:

The last point of the path.

Type: 
Point2D | undefined

push(point)

Appends a Point2D to the Path2D.

Parameters:
NameTypeDescription
pointPoint2D

The point to append.

push_bezier(cubic_bezier)

Appends a CubicBezierTuple to the Path2D.

Parameters:
NameTypeDescription
cubic_bezierCubicBezierTuple

The cubic bezier tuple to add.

remove(index) → {Point2D}

Removes a Point2D at a given index.

Parameters:
NameTypeDescription
indexnumber

The index of the point to remove.

Returns:

The removed point.

Type: 
Point2D

repeat(count) → {Path2D}

Repeats the Path2D a given number of times.

Parameters:
NameTypeDescription
countnumber

The number of times to repeat the path.

Returns:

The repeated path.

Type: 
Path2D

reverse()

Reverse the Path2D.

set(index, point)

Sets the Point2D at the given index.

Parameters:
NameTypeDescription
indexnumber

The index of the point.

pointPoint2D

The new point.

set_slice(start, end, path)

Sets a slice of the Path2D.

Parameters:
NameTypeDescription
startnumber

The start index of the slice.

endnumber

The end index of the slice.

pathPath2D

The new path.

slice(start, end) → {Path2D}

Returns a slice of the Path2D

Parameters:
NameTypeDescription
startnumber

The start index of the slice.

endnumber

The end index of the slice.

Returns:

A slice of the path.

Type: 
Path2D

(static) fill(point, count) → {Path2D}

Creates a new Path2D by filling the Path2D with a given Point2D a given number of times.

Parameters:
NameTypeDescription
pointPoint2D

The point to fill the path with.

countnumber

The number of times to fill the path with the point.

Returns:

A path that is a portion of the input path.

Type: 
Path2D

(static) from_anchors_and_handles(anchors_and_handles) → {Path2D}

Creates a new Path2D given a AnchorsAndHandles object.

Parameters:
NameTypeDescription
anchors_and_handlesAnchorsAndHandles

The AnchorsAndHandles object.

Returns:

A 2D path.

Type: 
Path2D