UNPKG

frame.akima

Version:

A package for Akima interpolation

98 lines 4.93 kB
import { AkimaPoint } from './AkimaPoint'; export declare class CatmullRom { private points; private splineFunc; private polarSplineFunc; constructor(points: AkimaPoint[]); /** * Core Catmull-Rom interpolation between four control points */ private catmullRomInterpolate; /** * Calculate centroid of points */ private getCentroid; /** * Creates a Catmull-Rom spline interpolation function for a given set of points. * * The returned function takes a parameter `t` in the range [0, 1) and returns * the interpolated `Point` on the closed spline curve. The spline wraps around, * forming a closed loop through all provided points. * * @param points - An array of `Point` objects representing the control points of the spline. * Must contain at least 3 points. * @returns A function that takes a parameter `t` (number in [0, 1)) and returns the interpolated `Point`. * @throws Error if fewer than 3 points are provided. */ createSplineFunction(points: AkimaPoint[]): (t: number) => AkimaPoint; /** * Creates a polar Catmull-Rom spline interpolation function based on the current set of points. * * The function sorts the points by their angle around the centroid, finds the point closest to the positive x-axis, * and reorders the points so that this point is first. It then constructs a Catmull-Rom spline in polar coordinates. * * @throws {Error} If fewer than 3 points are available to construct the spline. * @returns A function that takes an angle (in radians) and returns the interpolated {@link AkimaPoint} on the spline at that angle. */ createPolarCatmullRom(): (angle: number) => AkimaPoint; at(t: number, decimalPlaces?: number): AkimaPoint; /** * Evaluates the polar spline function at the given parameter `t` and returns the corresponding point. * * @param t - The parameter value at which to evaluate the polar spline function. * @returns The point on the polar spline corresponding to the parameter `t`. t should be in the range [0, 2 * Math.PI) */ atPolar(t: number): AkimaPoint; /** * Finds the corresponding point on the curve for a given angle in radians. * * This method converts the provided angle to a normalized unit value using `findRadian`, * then retrieves the corresponding point on the curve using `angleSpline`. * * @param angle - The angle in radians for which to find the corresponding point. * @returns The point on the curve corresponding to the given angle [0, Math.PI * 2]. */ findPointforUnit(angle: number): AkimaPoint; angleSpline(polar: number): { point: AkimaPoint; radian: number; }; /** * Recursively finds the angle (in radians) for which the provided polar spline function * produces a point whose `radian` property is closest to the specified target `radian`. * Uses a binary search approach within the interval [`from`, `to`] (defaulting to [0, 2π]). * * @param polSpline - A function that takes an angle (in radians) and returns a `Point` object * with an additional `radius` property. * @param angle - The target radian value to search for. * @param from - The lower bound of the search interval (inclusive). Defaults to 0. * @param to - The upper bound of the search interval (inclusive). Defaults to 2 * Math.PI. * @returns The angle (in radians) within [`from`, `to`] for which the spline's `radian` property * is closest to the target `radian`, within a tolerance of 0.001. */ findRadian(angle: number, from?: number, to?: number): number; findPolar(angle: number, from?: number, to?: number): number; /** * Finds the point on the spline where x > 0 and y = 0 (intersection with positive x-axis) * Uses binary search to find the point where y is closest to 0 and x is positive * @param tolerance The tolerance for y-value (default: 0.0001) * @returns The point where the spline intersects the positive x-axis, or null if no such point exists */ findPositiveXAxisIntersection(tolerance?: number): number | null; } /** * Create evenly spaced points along the spline * @param splineFunc The spline function * @param numPoints Number of points to generate * @returns Array of interpolated points */ export declare function sampleSpline(catmull: CatmullRom, numPoints: number): AkimaPoint[]; /** * Calculates the angle in radians between the positive x-axis and the given point (x, y). * The result is always in the range [0, 2π). * * @param point - The point for which to calculate the angle, with `x` and `y` coordinates. * @returns The angle in radians in the range [0, 2π). */ export declare function getRadian(point: AkimaPoint): number; //# sourceMappingURL=CR.d.ts.map