Options
All
  • Public
  • Public/Protected
  • All
Menu
classdesc

A refactored cubic bezier curve class.

requires

Bounds

requires

Vertex

requires

Vector

requires

XYCoords

requires

SVGSerializable

Hierarchy

  • CubicBezierCurve

Index

Constructors

constructor

Properties

Readonly END_CONTROL_POINT

END_CONTROL_POINT: number = CubicBezierCurve.END_CONTROL_POINT
constant

{number}

Readonly END_POINT

END_POINT: number = CubicBezierCurve.END_POINT
constant

{number}

Readonly START_CONTROL_POINT

START_CONTROL_POINT: number = CubicBezierCurve.START_CONTROL_POINT
constant

{number}

Readonly START_POINT

START_POINT: number = CubicBezierCurve.START_POINT
constant

{number}

arcLength

arcLength: number
member

{CubicBezierCurve}

memberof

CubicBezierCurve

instance

curveIntervals

curveIntervals: number
member

{CubicBezierCurve}

memberof

CubicBezierCurve

instance

endControlPoint

endControlPoint: Vertex
member

{CubicBezierCurve}

memberof

CubicBezierCurve

instance

endPoint

endPoint: Vertex
member

{CubicBezierCurve}

memberof

CubicBezierCurve

instance

segmentCache

segmentCache: Array<Vertex>
member

{CubicBezierCurve}

memberof

CubicBezierCurve

instance

segmentLengths

segmentLengths: Array<number>
member

{CubicBezierCurve}

memberof

CubicBezierCurve

instance

startControlPoint

startControlPoint: Vertex
member

{CubicBezierCurve}

memberof

CubicBezierCurve

instance

startPoint

startPoint: Vertex
member

{CubicBezierCurve}

memberof

CubicBezierCurve

instance

Static Readonly END_CONTROL_POINT

END_CONTROL_POINT: number = 2
constant

{number}

Static Readonly END_POINT

END_POINT: number = 3
constant

{number}

Static Readonly START_CONTROL_POINT

START_CONTROL_POINT: number = 1
constant

{number}

Static Readonly START_POINT

START_POINT: number = 0
constant

{number}

Methods

clone

convertU2T

  • convertU2T(u: number): number
  • Convert a relative curve position u to the absolute curve position t.

    method

    convertU2t

    instance
    memberof

    CubicBezierCurve

    Parameters

    • u: number

      The relative position on the curve in [0,arcLength].

    Returns number

equals

  • Check if this and the specified curve are equal.

    All four points need to be equal for this, the Vertex.equals function is used.

    Please note that this function is not type safe (comparison with any object will fail).

    method

    clone

    instance
    memberof

    CubicBezierCurve

    Parameters

    Returns boolean

getBounds

  • Get the bounds of this bezier curve.

    The bounds are approximated by the underlying segment buffer; the more segment there are, the more accurate will be the returned bounds.

    Returns Bounds

    The bounds of this curve.

getClosestT

  • getClosestT(p: Vertex): number
  • Get a 't' (relative position on curve) with the closest distance to point 'p'.

    The returned number is 0.0 <= t <= 1.0. Use the getPointAt(t) function to retrieve the actual curve point.

    This function uses a recursive approach by cutting the curve into several linear segments.

    Parameters

    • p: Vertex

      The point to find the closest position ('t' on the curve).

    Returns number

getEndControlPoint

  • getEndControlPoint(): Vertex
  • Get the end control point of the curve.

    This function just returns this.endControlPoint.

    method

    getEndControlPoint

    instance
    memberof

    CubicBezierCurve

    Returns Vertex

    this.endControlPoint

getEndPoint

  • Get the end point of the curve.

    This function just returns this.endPoint.

    method

    getEndPoint

    instance
    memberof

    CubicBezierCurve

    Returns Vertex

    this.endPoint

getLength

  • getLength(): number
  • Get the total curve length.

    As not all Bézier curved have a closed formula to calculate their lengths, this implementation uses a segment buffer (with a length of 30 segments). So the returned length is taken from the arc segment buffer.

    Note that if the curve points were changed and the segment buffer was not updated this function might return wrong (old) values.

    method

    getLength

    instance
    memberof

    CubicBezierCurve

    Returns number

    = 0

getPerpendicular

  • getPerpendicular(u: number): Vertex
  • Get the curve perpendicular at a given relative position u in [0,arcLength] as a vector.

    Note that the returned vector (end point) is not normalized.

    method

    getPerpendicular

    instance
    memberof

    CubicBezierCurve

    Parameters

    • u: number

      The relative position on the curve in [0,arcLength].

    Returns Vertex

getPerpendicularAt

  • getPerpendicularAt(t: number): Vertex
  • Get the curve perpendicular at a given absolute position t in [0,1] as a vector.

    Note that the returned vector (end point) is not normalized.

    method

    getPerpendicularAt

    instance
    memberof

    CubicBezierCurve

    Parameters

    • t: number

    Returns Vertex

getPoint

  • Get the curve point at a given position u, where u is in [0,arcLength].

    see

    CubicBezierCurve.getPointAt

    method

    getPoint

    instance
    memberof

    CubicBezierCurve

    Parameters

    • u: number

      The position on the curve in [0,arcLength] (0 means at start point, arcLength means at end point, other values address points in bertween).

    Returns Vertex

getPointAt

  • getPointAt(t: number): Vertex
  • Get the curve point at a given position t, where t is in [0,1].

    see

    Line.pointAt

    method

    getPointAt

    instance
    memberof

    CubicBezierCurve

    Parameters

    • t: number

      The position on the curve in [0,1] (0 means at start point, 1 means at end point, other values address points in bertween).

    Returns Vertex

getPointByID

  • getPointByID(id: number): Vertex
  • Get one of the four curve points specified by the passt point ID.

    method

    getEndControlPoint

    instance
    memberof

    CubicBezierCurve

    Parameters

    • id: number

      One of START_POINT, START_CONTROL_POINT, END_CONTROL_POINT or END_POINT.

    Returns Vertex

getStartControlPoint

  • getStartControlPoint(): Vertex
  • Get the start control point of the curve.

    This function just returns this.startControlPoint.

    method

    getStartControlPoint

    instance
    memberof

    CubicBezierCurve

    Returns Vertex

    this.startControlPoint

getStartPoint

  • Get the start point of the curve.

    This function just returns this.startPoint.

    method

    getStartPoint

    instance
    memberof

    CubicBezierCurve

    Returns Vertex

    this.startPoint

getSubCurveAt

  • Get a sub curve at the given start end end offsets (values between 0.0 and 1.0).

    tStart >= tEnd is allowed, you will get a reversed sub curve then.

    method

    getSubCurveAt

    instance
    memberof

    CubicBezierCurve

    Parameters

    • tStart: number

      – The start offset of the desired sub curve (must be in [0..1]).

    • tEnd: number

      – The end offset if the desired cub curve (must be in [0..1]).

    Returns CubicBezierCurve

    The sub curve as a new curve.

getTangent

  • getTangent(u: number): Vertex
  • Get the curve tangent vector at a given relative position u in [0,arcLength].

    Note that the returned tangent vector (end point) is not normalized.

    method

    getTangent

    instance
    memberof

    CubicBezierCurve

    Parameters

    • u: number

      The position on the curve in [0,arcLength].

    Returns Vertex

getTangentAt

  • getTangentAt(t: number): Vertex
  • Get the curve tangent vector at a given absolute curve position t in [0,1].

    Note that the returned tangent vector (end point) is not normalized and relative to (0,0).

    method

    getTangent

    instance
    memberof

    CubicBezierCurve

    Parameters

    • t: number

      The position on the curve in [0,1].

    Returns Vertex

Private locateIntervalByDistance

  • locateIntervalByDistance(p: Vertex, tStart: number, tEnd: number, stepCount: number): { t: number; tNext: number; tPrev: number }
  • This helper function locates the 't' on a fixed step interval with the minimal distance between the curve (at 't') and the given point.

    Furthermore you must specify a sub curve (start 't' and end 't') you want to search on. Using tStart=0.0 and tEnd=1.0 will search on the full curve.

    Parameters

    • p: Vertex

      The point to find the closest curve point for.

    • tStart: number

      The start position (start 't' of the sub curve). Should be >= 0.0.

    • tEnd: number

      The end position (end 't' of the sub curve). Should be <= 1.0.

    • stepCount: number

      The number of steps to check within the interval.

    Returns { t: number; tNext: number; tPrev: number }

    • An object with t, tPrev and tNext (numbers).
    • t: number
    • tNext: number
    • tPrev: number

moveCurvePoint

  • moveCurvePoint(pointID: number, moveAmount: XYCoords, moveControlPoint: boolean, updateArcLengths: boolean): void
  • Move the given curve point (the start point, end point or one of the two control points).

    method

    moveCurvePoint

    instance
    memberof

    CubicBezierCurve

    Parameters

    • pointID: number

      The numeric identicator of the point to move. Use one of the four eBezierPoint constants.

    • moveAmount: XYCoords

      The amount to move the specified point by.

    • moveControlPoint: boolean

      Move the control points along with their path point (if specified point is a path point).

    • updateArcLengths: boolean

      Specifiy if the internal arc segment buffer should be updated.

    Returns void

reverse

  • Reverse this curve, means swapping start- and end-point and swapping start-control- and end-control-point.

    method

    reverse

    instance
    memberof

    CubicBezierCurve

    Returns CubicBezierCurve

    this (for chaining).

toJSON

  • toJSON(prettyFormat: boolean): string
  • Convert this curve to a JSON string.

    method

    toJSON

    instance
    memberof

    CubicBezierCurve

    Parameters

    • prettyFormat: boolean

    Returns string

    The JSON data.

toSVGPathData

  • toSVGPathData(): string
  • Create an SVG path data representation of this bézier curve.

    Path data string format is:

    'M x0 y1 C dx0 dy1 dx1 dy1 x1 x2'

    or in other words
    'M startoint.x startPoint.y C startControlPoint.x startControlPoint.y endControlPoint.x endControlPoint.y endPoint.x endPoint.y'

    method

    toSVGPathData

    instance
    memberof

    CubicBezierCurve

    Returns string

    The SVG path data string.

translate

  • Translate the whole curve by the given {x,y} amount: moves all four points.

    method

    translate

    instance
    memberof

    CubicBezierCurve

    Parameters

    • amount: Vertex

      The amount to translate this curve by.

    Returns CubicBezierCurve

    this (for chaining).

updateArcLengths

  • updateArcLengths(): void
  • Uptate the internal arc segment buffer and their lengths.

    All class functions update the buffer automatically; if any curve point is changed by other reasons you should call this function to keep actual values in the buffer.

    method

    updateArcLengths

    instance
    memberof

    CubicBezierCurve

    Returns void

Static fromArray

  • Convert a 4-element array of vertices to a cubic bézier curve.

    method

    fromArray

    memberof

    CubicBezierCurve

    throws

    An exception if the passed array is malformed.

    Parameters

    • arr: Array<Vertex>

      [ startVertex, endVertex, startControlVertex, endControlVertex ]

    Returns CubicBezierCurve

Static fromJSON

  • Parse a Bézier curve from the given JSON string.

    method

    fromJSON

    memberof

    CubicBezierCurve

    static
    throws

    An exception if the JSON string is malformed.

    Parameters

    • jsonString: string

      The JSON data to parse.

    Returns CubicBezierCurve

Static fromObject

  • Try to convert the passed object to a CubicBezierCurve.

    method

    fromObject

    memberof

    CubicBezierCurve

    static
    throws

    An exception if the passed object is malformed.

    Parameters

    • obj: any

      The object to convert.

    Returns CubicBezierCurve

Static isInstance

  • isInstance(obj: any): boolean
  • Quick check for class instance. Is there a better way?

    method

    isInstance

    instance
    memberof

    CubicBezierCurve

    Parameters

    • obj: any

      Check if the passed object/value is an instance of CubicBezierCurve.

    Returns boolean

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Private property
  • Private method
  • Static property
  • Static method

Generated using TypeDoc