UNPKG

toosoon-utils

Version:
97 lines (96 loc) 2.93 kB
import { type Vector, Vector2, Vector3 } from '../geometry'; /** * Utility abstract class for manipulating curves * * @exports * @class Curve * @abstract * @template {Vector} [V=Vector2|Vector3] */ export default abstract class Curve<V extends Vector = Vector2 | Vector3> { readonly isCurve = true; readonly type: string; /** * Amount of divisions when calculating the cumulative segment lengths of a curve */ arcLengthDivisions: number; /** * Must be set to `true` if the curve parameters have changed */ needsUpdate: boolean; protected _cacheArcLengths: number[]; /** * Interpolate a point on this curve * * @abstract * @param {number} t Normalized time value to interpolate * @returns {Vector} Interpolated coordinates on this curve */ abstract getPoint(t: number): V; /** * Interpolate a point on this curve * * @param {number} u Normalized position value to interpolate * @returns {Vector} Interpolated coordinates on this curve */ getPointAt(u: number): V; /** * Compute this curve shape into an array of points * * @param {number} [divisions=5] Number of divisions * @returns {Vector[]} */ getPoints(divisions?: number): V[]; /** * Compute this curve shape into an array of equi-spaced points across the entire curve * * @param {number} [divisions=5] Number of divisions * @returns {Vector[]} */ getSpacedPoints(divisions?: number): V[]; /** * Compute the total arc length of this curve * * @returns {number} */ getLength(): number; /** * Compute the cumulative segment lengths of this curve * * @param {number} [divisions=this.arcLengthDivisions] Number of divisions * @returns {number[]} */ getLengths(divisions?: number): number[]; /** * Update the cached cumulative segment lengths */ updateArcLengths(): void; /** * Re-map a normalized position value into normalized time * * @param {number} u Normalized position value to interpolate * @param {number} [targetArcLength] Distance on this curve * @returns {number} Updated interpolation value */ getUtoTmapping(u: number, targetArcLength?: number): number; /** * Compute an unit vector tangent for a given normalized time value * * @param {number} t Normalized time value * @returns {Vector} Tangent vector */ getTangent(t: number): V; /** * Compute an unit vector tangent for a given normalized position value * * @param {number} u Normalized position value * @returns {Vector} Tangent vector */ getTangentAt(u: number): V; /** * Check if this curve is closed * * @returns {boolean} `true` if the curve is closed, `false` otherwise */ isClosed(): boolean; }