Classdesc

A BezierPath class.

This was refactored from an older project.

Requires

Bounds

Requires

Vertex

Requires

CubicBezierCurve

Requires

XYCoords

Requires

SVGSerializable

Requires

UID

Requires

UIDGenerator

Implements

Constructors

  • 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.

    Returns BezierPath

    Name

    BezierPath

Properties

END_CONTROL_POINT: number = 2

Constant

END_POINT: number = 3

Constant

START_CONTROL_POINT: number = 1

Constant

START_POINT: number = 0

Constant

adjustCircular: boolean

Set this flag to true if you want the first point and last point of the path to be auto adjusted, too.

Member

Memberof

BezierPath

Instance

bezierCurves: CubicBezierCurve[]

Member

Memberof

BezierPath

Instance

className: string = "BezierPath"

Required to generate proper CSS classes and other class related IDs.

isDestroyed: boolean

Member

Memberof

BezierPath

Instance

pathPoints: Vertex[]

Member

Memberof

BezierPath

Instance

totalArcLength: number

Member

Memberof

BezierPath

Instance

uid: string

The UID of this drawable object.

Member

Memberof

BezierCurve

Instance

END_CONTROL_POINT: number = 2

Constant

END_POINT: number = 3

Constant

START_CONTROL_POINT: number = 1

Constant

START_POINT: number = 0

Constant

Methods

  • Private

    This helper function adjusts the given point's predecessor's control point.

    Parameters

    • curveIndex: number

      The curve index to move a point from.

    • obtainHandleLength: boolean

      Moves the point with keeping the original handle length.

    • updateArcLengths: boolean

    Returns void

    Method

    adjustPredecessorControlPoint

    Instance

    Memberof

    BezierPath

  • Private

    This helper function adjusts the given point's successor's control point.

    Parameters

    • curveIndex: number

      The curve index to move a point from.

    • obtainHandleLength: boolean

      Moves the point with keeping the original handle length.

    • updateArcLengths: boolean

    Returns void

    Method

    adjustSuccessorControlPoint

    Instance

    Memberof

    BezierPath

  • This function should invalidate any installed listeners and invalidate this object. After calling this function the object might not hold valid data any more and should not be used.

    Returns void

    Method

    destroy

    Instance

    Memberof

    BezierPath

  • Get the bounds of this Bézier path.

    Note the the curves' underlyung segment buffers are used to determine the bounds. The more elements the segment buffers have, the more precise the returned bounds will be.

    Returns Bounds

    The bounds of this Bézier path.

  • Get the 't' position on this curve with the minimal distance to point p.

    Parameters

    • p: Vertex

      The point to find the closest curve point for.

    Returns number

    A value t with 0.0 <= t <= 1.0.

  • Get the number of curves in this path.

    Returns number

    The number of curves in this path.

    Method

    getCurveCount

    Instance

    Memberof

    BezierPath

  • Get n 'equally' distributed vertices along this Bézier path.

    As the changing curvature of the B slines makes prediction of distances difficult, the returned vertices' distances are only relatively equal:

    • the distance grows where curvature is large.
    • the distance shrinks where curvature is small.

    Only the distance mean of all consecutive is 1/n-th of the total arc length.

    Usually this approximation is good enough for most use cases.

    Parameters

    • pointCount: number

      (must be at least 2) The number of desired points (start and end point included).

    Returns Vertex[]

  • 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.

    Returns number

    The (buffered) length of the path.

    Method

    getLength

    Instance

    Memberof

    BezierPath

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

    Note that the returned vector is not normalized.

    Parameters

    • u: number

      The relative path position:

      0 <= u <= getLength()

    Returns Vertex

    The perpendicluar vector at the relative path position.

    Method

    getPerpendicular

    Instance

    Memberof

    BezierPath

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

    Note that the returned vector is not normalized.

    Parameters

    • t: number

      The absolute path position:

      0.0 <= t <= 1.0

    Returns Vertex

    The perpendicluar vector at the absolute path position.

    Method

    getPerpendicularAt

    Instance

    Memberof

    BezierPath

  • Get the point on the bézier path at the given relative path location.

    Parameters

    • u: number

      The relative path position:

      0 <= u <= this.getLength()

    Returns Vertex

    The point at the relative path position.

    Method

    getPoint

    Instance

    Memberof

    BezierPath

  • Get the point on the bézier path at the given path fraction.

    Parameters

    • t: number

      The absolute path position:

      0.0 <= t <= 1.0

    Returns Vertex

    The point at the absolute path position.

    Method

    getPointAt

    Instance

    Memberof

    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

    • startT: number

      The start position of the sub path.

    • endT: number

      The end position of the sub path.

    Returns BezierPath

    The desired sub path in the bounds [startT..endT].

    Method

    getSubPathAt

    Instance

    Memberof

    BezierPath

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

    Note that the returned vector is not normalized.

    Parameters

    • u: number

      The relative path position:

      0 <= u <= getLength()

    Returns Vertex

    The tangent vector at the relative path position.

    Method

    getTangent

    Instance

    Memberof

    BezierPath

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

    Note that the returned vector is not normalized.

    Parameters

    • t: number

      The absolute path position:

      0.0 <= t <= 1.0

    Returns Vertex

    The tangent vector at the absolute path position.

    Method

    getTangentAt

    Instance

    Memberof

    BezierPath

  • Locate the curve with the given end point (function returns the index).

    Parameters

    • point: Vertex

      The (curve end-) point to look for.

    Returns number

    The curve index or -1 if curve (end-) point not found

    Method

    locateCurveByEndPoint

    Instance

    Memberof

    BezierPath

  • Locate the curve with the given start point (function returns the index).

    Parameters

    • point: Vertex

      The (curve endt-) point to look for.

    Returns number

    The curve index or -1 if curve (end-) point not found

    Method

    locateCurveByStartControlPoint

    Instance

    Memberof

    BezierPath

  • Locate the curve with the given start point (function returns the index).

    Parameters

    • point: Vertex

      The (curve start-) point to look for.

    Returns number

    The curve index or -1 if curve (start-) point not found

    Method

    locateCurveByStartPoint

    Instance

    Memberof

    BezierPath

  • 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

    • 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.

    Returns void

    Method

    moveCurvePoint

    Instance

    Memberof

    BezierPath

  • Rotate the whole bezier path around a point..

    Parameters

    • angle: number

      The angle to rotate this path by.

    • center: Vertex

      The rotation center.

    Returns void

    Method

    rotate

    Instance

    Memberof

    BezierPath

  • Scale the whole bezier path by the given uniform factor.

    Parameters

    • anchor: Vertex

      The scale origin to scale from.

    • scaleFactor: number

      The scalar to be multiplied with.

    Returns BezierPath

    this for chaining.

    Method

    scale

    Instance

    Memberof

    BezierPath

  • Create a JSON string representation of this bézier curve.

    Parameters

    • prettyFormat: boolean

      If true then the function will add line breaks.

    Returns string

    The JSON string.

    Method

    toJSON

    Instance

    Memberof

    BezierPath

  • 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

    • digits: number

      The number of digits to be used after the comma '.'.

    Returns string

    The reduced list representation of this path.

    Method

    toReducedListRepresentation

    Instance

    Memberof

    BezierPath

  • 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.

    Returns void

    Method

    updateArcLengths

    Instance

    Memberof

    BezierPath

  • This is a helper function to locate the curve index for a given absolute path position u.

    I decided to put this into privat scope as it is really specific. Maybe put this into a utils wrapper.

    Returns:

    • {number} i - the index of the containing curve.
    • {number} uPart - the absolute curve length sum (length from the beginning to u, should equal u itself).
    • {number} uBefore - the absolute curve length for all segments before the matched curve (usually uBefore <= uPart).

    Parameters

    Returns {
        i: number;
        uBefore: number;
        uPart: number;
    }

    • i: number
    • uBefore: number
    • uPart: number
  • Private

    This helper function adjusts the given point's successor's control point.

    Parameters

    Returns void

    Method

    adjustNeighbourControlPoint

    Instance

    Memberof

    BezierPath

  • Create a BezierPath instance from the given array.

    Parameters

    • obj: any

    Returns BezierPath

    The bezier path instance retrieved from the array data.

    Method

    fromArray

    Throw

    An error if the array does not contain proper bezier path data.

    Static

    Memberof

    BezierPath

  • Parse a BezierPath from the given JSON string.

    Parameters

    • jsonString: string

      The string with the JSON data.

    Returns BezierPath

    The parsed bezier path instance.

    Method

    fromJSON

    Throw

    An error if the string is not JSON or does not contain a bezier path object.

    Static

    Memberof

    BezierPath

  • Convert a reduced list representation (array of numeric coordinates) to a BezierPath instance.

    The array's length must be 6*n + 2:

    • [sx, sy, scx, scy, ecx, ecy, ... , ex, ey ] | | | | +--- sequence of curves --------+ +-end-+

    Parameters

    • pointArray: number[]
    • Optional adjustCircular: boolean

    Returns BezierPath

    BezierPath

  • Parse a BezierPath instance from the reduced list representation.

    The passed string must represent a JSON array containing numbers only.

    Parameters

    • listJSON: string

      The number of digits to be used after the floating point.

    • Optional adjustCircular: boolean

    Returns BezierPath

    The bezier path instance retrieved from the string.

    Method

    fromReducedListRepresentation

    Throw

    An error if the string is malformed.

    Instance

    Memberof

    BezierPath