UNPKG

toosoon-utils

Version:
72 lines (71 loc) 1.87 kB
import { Curve } from '../curves'; import { type Vector, Vector2, Vector3 } from '../geometry'; /** * Utility class for manipulating connected curves * * @exports * @class Path * @extends Curve */ export default class Path<V extends Vector = Vector2 | Vector3, C extends Curve<V> = Curve<V>> extends Curve<V> { readonly isPath = true; readonly type: string; /** * Array of curves composing this path */ curves: C[]; /** * Array of points composing this path */ points: V[]; /** * Define if a last point should be automatically added to close this path */ autoClose: boolean; constructor({ autoClose }?: { autoClose?: boolean; }); /** * Add a curve to this path * * @param {Curve} curve Curve to add */ add(curve: C): void; /** * Interpolate a point on this path * * @param {number} t Normalized time value to interpolate * @returns {Vector} Interpolated coordinates on the curve */ getPoint(t: number): V; /** * Compute the curve shape into an array of points * * @param {number} [divisions=40] Number of divisions * @returns {Vector[]} */ getPoints(divisions?: number): V[]; /** * Compute the curve shape into an array of equi-spaced points across the entire curve path * * @param {number} [divisions=40] Number of divisions * @returns {Vector[]} */ getSpacedPoints(divisions?: number): V[]; /** * Compute the total arc length of this path * * @returns {number} */ getLength(): number; /** * Compute the cumulative curve lengths of this path * * @returns {number[]} */ getCurveLengths(): number[]; /** * Update the cached cumulative segment lengths */ updateArcLengths(): void; }