@fimbul-works/vec
Version:
A comprehensive TypeScript vector math library providing 2D, 3D, and 4D vector operations with a focus on performance and type safety.
29 lines (28 loc) • 1.05 kB
JavaScript
;
/**
* Documentation for spherical linear interpolation functions.
* @module Slerp
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.slerpDegrees = exports.slerp = void 0;
const PI2 = 2 * Math.PI;
const PI3 = 3 * Math.PI;
/**
* Spherical linear interpolation for angles (in radians).
* Handles wrapping around 2π correctly.
* @param {number} from - Start angle in radians
* @param {number} to - End angle in radians
* @param {number} t - Interpolation factor (0-1)
* @returns {number} Interpolated angle
*/
const slerp = (from, to, t) => from + (((((to - from) % PI2) + PI3) % PI2) - Math.PI) * t;
exports.slerp = slerp;
/**
* Spherical linear interpolation for angles (in degrees).
* @param {number} from - Start angle in degrees
* @param {number} to - End angle in degrees
* @param {number} t - Interpolation factor (0-1)
* @returns {number} Interpolated angle
*/
const slerpDegrees = (from, to, t) => from + (((((to - from) % 360) + 540) % 360) - 180) * t;
exports.slerpDegrees = slerpDegrees;