Classdesc

A refactored cubic bezier curve class.

Requires

Bounds

Requires

Vertex

Requires

Vector

Requires

XYCoords

Requires

UID

Requires

UIDGenerator

Implements

Constructors

  • The constructor.

    Parameters

    • startPoint: Vertex

      The Bézier curve's start point.

    • endPoint: Vertex

      The Bézier curve's end point.

    • startControlPoint: Vertex

      The Bézier curve's start control point.

    • endControlPoint: Vertex

      The Bézier curve's end control point.

    Returns CubicBezierCurve

    Name

    CubicBezierCurve

Properties

END_CONTROL_POINT: number = CubicBezierCurve.END_CONTROL_POINT

Constant

END_POINT: number = CubicBezierCurve.END_POINT

Constant

START_CONTROL_POINT: number = CubicBezierCurve.START_CONTROL_POINT

Constant

START_POINT: number = CubicBezierCurve.START_POINT

Constant

arcLength: number

Member

Memberof

CubicBezierCurve

Instance

curveIntervals: number

Member

Memberof

CubicBezierCurve

Instance

endControlPoint: Vertex

Member

Memberof

CubicBezierCurve

Instance

endPoint: Vertex

Member

Memberof

CubicBezierCurve

Instance

isDestroyed: boolean

Member

isDestroyed

Memberof

CubicBezierCurve

Instance

segmentCache: Vertex[]

Member

Memberof

CubicBezierCurve

Instance

segmentLengths: number[]

Member

Memberof

CubicBezierCurve

Instance

startControlPoint: Vertex

Member

Memberof

CubicBezierCurve

Instance

startPoint: Vertex

Member

Memberof

CubicBezierCurve

Instance

uid: string

The UID of this drawable object.

Member

Memberof

CubicBezierCurve

Instance

END_CONTROL_POINT: number = 2

Constant

END_POINT: number = 3

Constant

START_CONTROL_POINT: number = 1

Constant

START_POINT: number = 0

Constant

utils: {
    getSubCurvePointsAt: ((curve, tStart, tEnd) => [Vertex, Vertex, Vertex, Vertex]);
} = ...

Helper utils.

Type declaration

  • getSubCurvePointsAt: ((curve, tStart, tEnd) => [Vertex, Vertex, Vertex, Vertex])

    Get the points of 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

    getSubCurvePointsAt

    Instance

    Memberof

    CubicBezierCurve

    Returns

    The sub curve as a new curve.

      • (curve, tStart, tEnd): [Vertex, Vertex, Vertex, Vertex]
      • Parameters

        • curve: CubicBezierCurve

          – The curve to get the sub curve points from.

        • 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 [Vertex, Vertex, Vertex, Vertex]

Methods

  • Convert a relative curve position u to the absolute curve position t.

    Parameters

    • u: number

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

    Returns number

    Method

    convertU2t

    Instance

    Memberof

    CubicBezierCurve

  • 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

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

    Parameters

    Returns boolean

    Method

    clone

    Instance

    Memberof

    CubicBezierCurve

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

  • 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

  • Get the end control point of the curve.

    This function just returns this.endControlPoint.

    Returns Vertex

    this.endControlPoint

    Method

    getEndControlPoint

    Instance

    Memberof

    CubicBezierCurve

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

    Returns number

    = 0

    Method

    getLength

    Instance

    Memberof

    CubicBezierCurve

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

    Parameters

    • u: number

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

    Returns Vertex

    Method

    getPerpendicular

    Instance

    Memberof

    CubicBezierCurve

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

    Parameters

    • t: number

    Returns Vertex

    Method

    getPerpendicularAt

    Instance

    Memberof

    CubicBezierCurve

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

    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

    See

    CubicBezierCurve.getPointAt

    Method

    getPoint

    Instance

    Memberof

    CubicBezierCurve

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

    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

    See

    Line.pointAt

    Method

    getPointAt

    Instance

    Memberof

    CubicBezierCurve

  • Get one of the four curve points specified by the passt point ID.

    Parameters

    • id: number

      One of START_POINT, START_CONTROL_POINT, END_CONTROL_POINT or END_POINT.

    Returns Vertex

    Method

    getEndControlPoint

    Instance

    Memberof

    CubicBezierCurve

  • Get the start control point of the curve.

    This function just returns this.startControlPoint.

    Returns Vertex

    this.startControlPoint

    Method

    getStartControlPoint

    Instance

    Memberof

    CubicBezierCurve

  • Get a sub curve at the given start end end positions (values on the curve's length, between 0 and curve.arcLength).

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

    Parameters

    • uStart: number
    • uEnd: number

    Returns CubicBezierCurve

    The sub curve as a new curve.

    Method

    getSubCurve

    Instance

    Memberof

    CubicBezierCurve

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

    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.

    Method

    getSubCurveAt

    Instance

    Memberof

    CubicBezierCurve

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

    Parameters

    • u: number

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

    Returns Vertex

    Method

    getTangent

    Instance

    Memberof

    CubicBezierCurve

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

    Parameters

    • t: number

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

    Returns Vertex

    Method

    getTangent

    Instance

    Memberof

    CubicBezierCurve

  • 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
  • Move the given curve point (the start point, end point or one of the two control points).

    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

    Method

    moveCurvePoint

    Instance

    Memberof

    CubicBezierCurve

  • Convert this curve to a JSON string.

    Parameters

    • Optional prettyFormat: boolean

      If set to true the function will add line breaks.

    Returns string

    The JSON data.

    Method

    toJSON

    Instance

    Memberof

    CubicBezierCurve

  • Trim off the end of this curve. The position parameter uValue is the absolute position on the curve in [0...arcLength]. The remaining curve will be the one in the bounds [0,uValue] (so [1.0-uValue,1.0] is cut off).

    Note this function just converts the absolute parameter to a relative one and call trimEndAt.

    Parameters

    • uValue: number

      The absolute position parameter where to cut off the tail curve.

    Returns CubicBezierCurve

    this for chanining.

    Method

    trimEnd

    Instance

    Memberof

    CubicBezierCurve

  • Trim off the end of this curve. The position parameter t is the relative position in [0..1]. The remaining curve will be the one in the bounds [0,t] (so [1.0-t,1.0] is cut off).

    Parameters

    • t: number

      The relative position parameter where to cut off the tail curve.

    Returns CubicBezierCurve

    this for chanining.

    Method

    trimEndAt

    Instance

    Memberof

    CubicBezierCurve

  • Trim off a start section of this curve. The position parameter uValue is the absolute position on the curve in [0...arcLength]. The remaining curve will be the one in the bounds [uValue,1] (so [0.0,uValue] is cut off).

    Note this function just converts the absolute parameter to a relative one and call trimStartAt.

    Parameters

    • uValue: number

      The absolute position parameter where to cut off the head curve.

    Returns CubicBezierCurve

    this for chanining.

    Method

    trimStart

    Instance

    Memberof

    CubicBezierCurve

  • Trim off a start section of this curve. The position parameter t is the relative position in [0..1]. The remaining curve will be the one in the bounds [uValue,1] (so [0.0,uValue] is cut off).

    Parameters

    • t: number

      The relative position parameter where to cut off the head curve.

    Returns CubicBezierCurve

    this for chanining.

    Method

    trimStartAt

    Instance

    Memberof

    CubicBezierCurve

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

    Returns void

    Method

    updateArcLengths

    Instance

    Memberof

    CubicBezierCurve

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

    Parameters

    • arr: Vertex[]

      [ startVertex, endVertex, startControlVertex, endControlVertex ]

    Returns CubicBezierCurve

    Method

    fromArray

    Memberof

    CubicBezierCurve

    Throws

    An exception if the passed array is malformed.

  • Quick check for class instance. Is there a better way?

    Parameters

    • obj: any

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

    Returns boolean

    Method

    isInstance

    Instance

    Memberof

    CubicBezierCurve

Generated using TypeDoc