Class: BezierPath

BezierPath(pathPoints)

new BezierPath(pathPoints)

The constructor.

This constructor expects a sequence of path points and will approximate the location of control points by picking some between the points.
You should consider just constructing empty paths and then add more curves later using the addCurve() function.
Parameters:
Name Type Description
pathPoints Array:.<Vertex:> An array of path vertices (no control points).
Source:

Methods

(static) fromArray(arr) → {BezierPath}

Create a BezierPath instance from the given array.
Parameters:
Name Type Description
arr Array:.<Array:.<Vertex:>> A two-dimensional array containing the bezier path vertices.
Source:
Returns:
The bezier path instance retrieved from the array data.
Type
BezierPath

(static) fromJSON(jsonString) → {BezierPath}

Parse a BezierPath from the given JSON string.
Parameters:
Name Type Description
jsonString string The string with the JSON data.
Source:
Returns:
The parsed bezier path instance.
Type
BezierPath

addCurve(curve) → {void}

Add a cubic bezier curve to the end of this path.
Parameters:
Name Type Description
curve CubicBezierCurve The curve to be added to the end of the path.
Source:
Returns:
Type
void

clone() → {BezierPath}

Clone this BezierPath (deep clone).
Source:
Returns:
Type
BezierPath

equals(path) → {boolean}

Compare this and the passed Bézier path.
Parameters:
Name Type Description
path BezierPath The pass to compare with.
Source:
Returns:
Type
boolean

fromReducedListRepresentation(listJSON) → {BezierPath}

Parse a BezierPath instance from the reduced list representation.

The passed string must represent a JSON array containing numbers only.
Parameters:
Name Type Description
listJSON string The number of digits to be used after the floating point.
Source:
Returns:
The bezier path instance retrieved from the string.
Type
BezierPath

getCurveAt(index) → {CubicBezierCurve}

Get the cubic bezier curve at the given index.
Parameters:
Name Type Description
index number The curve index from 0 to getCurveCount()-1.
Source:
Returns:
The curve at the specified index.
Type
CubicBezierCurve

getCurveCount() → {number}

Get the number of curves in this path.
Source:
Returns:
The number of curves in this path.
Type
number

getLength() → {number}

Get the total length of this path.

Note that the returned value comes from the curve buffer. Unregistered changes to the curve points will result in invalid path length values.
Source:
Returns:
The (buffered) length of the path.
Type
number

getPerpendicular(u) → {Vertex}

Get the perpendicular of the bézier path at the given relative path location.

Note that the returned vector is not normalized.
Parameters:
Name Type Description
u number The relative path position:
0 <= u <= getLength()
Source:
Returns:
The perpendicluar vector at the relative path position.
Type
Vertex

getPerpendicularAt(t) → {Vertex}

Get the perpendicular of the bézier path at the given absolute path location (fraction).

Note that the returned vector is not normalized.
Parameters:
Name Type Description
t number The absolute path position:
0.0 <= t <= 1.0
Source:
Returns:
The perpendicluar vector at the absolute path position.
Type
Vertex

getPoint(u) → {Vertex}

Get the point on the bézier path at the given relative path location.
Parameters:
Name Type Description
u number The relative path position:
0 <= u <= this.getLength()
Source:
Returns:
The point at the relative path position.
Type
Vertex

getPointAt(t) → {Vertex}

Get the point on the bézier path at the given path fraction.
Parameters:
Name Type Description
t number The absolute path position:
0.0 <= t <= 1.0
Source:
Returns:
The point at the absolute path position.
Type
Vertex

getSubPathAt(startT, endT) → {BezierPath}

Get a specific sub path from this path. The start and end position are specified by ratio number in [0..1]. 0.0 is at the beginning of the path. 1.0 is at the end of the path. Values below 0 or beyond 1 are cropped down to the [0..1] interval. startT > endT is allowed, the returned sub path will have inverse direction then.
Parameters:
Name Type Description
startT number The start position of the sub path.
endT number The end position of the sub path.
Source:
Returns:
The desired sub path in the bounds [startT..endT].
Type
BezierPath

getTangent(u) → {Vertex}

Get the tangent of the bézier path at the given path location.

Note that the returned vector is not normalized.
Parameters:
Name Type Description
u number The relative path position:
0 <= u <= getLength()
Source:
Returns:
The tangent vector at the relative path position.
Type
Vertex

getTangentAt(t) → {Vertex}

Get the tangent of the bézier path at the given path fraction.

Note that the returned vector is not normalized.
Parameters:
Name Type Description
t number The absolute path position:
0.0 <= t <= 1.0
Source:
Returns:
The tangent vector at the absolute path position.
Type
Vertex

joinAt(curveIndex) → {boolean}

Removes a path point inside the path. This function joins the bezier curve at the given index with its predecessor, which means that the start point at the given curve index will be removed.
Parameters:
Name Type Description
curveIndex number The index of the curve to be joined with its predecessor.
Source:
Returns:
True if the passed index indicated an inner vertex and the two curves were joined.
Type
boolean

locateCurveByEndPoint(point) → {number}

Locate the curve with the given end point (function returns the index).
Parameters:
Name Type Description
point Vertex The (curve end-) point to look for.
Source:
Returns:
The curve index or -1 if curve (end-) point not found
Type
number

locateCurveByStartControlPoint(point) → {number}

Locate the curve with the given start point (function returns the index).
Parameters:
Name Type Description
point Vertex The (curve endt-) point to look for.
Source:
Returns:
The curve index or -1 if curve (end-) point not found
Type
number

locateCurveByStartPoint(point) → {number}

Locate the curve with the given start point (function returns the index).
Parameters:
Name Type Description
point Vertex The (curve start-) point to look for.
Source:
Returns:
The curve index or -1 if curve (start-) point not found
Type
number

moveCurvePoint(curveIndex, pointID, moveAmount) → {void}

This function moves the addressed curve point (or control point) with keeping up the path's curve integrity.

Thus is done by moving neighbour- and control- points as needed.
Parameters:
Name Type Description
curveIndex number The curve index to move a point from.
pointID number One of the curve's four point IDs (START_POINT, START_CONTROL_POINT, END_CONTRO_POINT or END_POINT).
moveAmount XYCoords The amount to move the addressed vertex by.
Source:
Returns:
Type
void

removeEndPoint() → {boolean}

Remove the end point of this path (which removes the last curve from this path).

Please note that this function does never remove the first curve, thus the path cannot be empty after this call.
Source:
Returns:
Indicating if the last curve was removed.
Type
boolean

removeStartPoint() → {boolean}

Remove the start point of this path (which removes the first curve from this path).

Please note that this function does never remove the last curve, thus the path cannot be empty after this call.
Source:
Returns:
Indicating if the first curve was removed.
Type
boolean

rotate(angle, center) → {void}

Rotate the whole bezier path around a point..
Parameters:
Name Type Description
angle Vertex The angle to rotate this path by.
center Vertex The rotation center.
Source:
Returns:
Type
void

scale(anchor, amount) → {BezierPath}

Scale the whole bezier path by the given (x,y)-factors.
Parameters:
Name Type Description
anchor Vertex The scale origin to scale from.
amount number The scalar to be multiplied with.
Source:
Returns:
this for chaining.
Type
BezierPath

splitAt(curveIndex, segmentIndex) → {boolean}

Add a new inner curve point to the path.

This function splits the bezier curve at the given index and given curve segment index.
Parameters:
Name Type Description
curveIndex number The index of the curve to split.
segmentIndex nunber The index of the curve segment where the split should be performed.
Source:
Returns:
True if the passed indices were valid and the path was split.
Type
boolean

toJSON(prettyFormat) → {string}

Create a JSON string representation of this bézier curve.
Parameters:
Name Type Description
prettyFormat boolean If true then the function will add line breaks.
Source:
Returns:
The JSON string.
Type
string

toReducedListRepresentation(digits) → {string}

This function converts the bezier path into a string containing integer values only. The points' float values are rounded to 1 digit after the comma. The returned string represents a JSON array (with leading '[' and trailing ']', the separator is ',').
Parameters:
Name Type Description
digits number The number of digits to be used after the comma '.'.
Source:
Returns:
The reduced list representation of this path.
Type
string

toSVGString(optionsopt) → {string}

Create a
<path>
SVG representation of this bézier curve.
Parameters:
Name Type Attributes Default Description
options object <optional>
{} Like options.className
Properties
Name Type Attributes Description
className string <optional>
The classname to use for the SVG item.
Source:
Returns:
The SVG string.
Type
string

translate(amount) → {BezierPath}

Move the whole bezier path by the given (x,y)-amount.
Parameters:
Name Type Description
amount Vertex The amount to be added (amount.x and amount.y) to each vertex of the curve.
Source:
Returns:
this for chaining
Type
BezierPath

updateArcLengths() → {void}

This function is internally called whenever the curve or path configuration changed. It updates the attribute that stores the path length information.

If you perform any unregistered changes to the curve points you should call this function afterwards to update the curve buffer. Not updating may result in unexpected behavior.
Source:
Returns:
Type
void