animare
Version:
Advanced animation library for modern JavaScript.
14 lines • 1.04 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:true});exports.lerp=lerp;var _utils=require("./utils.js");/**
* Linearly interpolates between two values.
*
* ⚠️ **WARNING** ⚠️ This function throws an error if the values are invalid.
*
* @param start - The start value or vector.
* @param end - The end value or vector.
* @param t - The interpolation factor (0.0 to 1.0).
* @returns The interpolated value or vector.
*/function lerp(start,end,t){// Single number interpolation
if(typeof start==='number'&&typeof end==='number'){return start+t*(end-start);}// Array-based vector interpolation
if(Array.isArray(start)&&Array.isArray(end)){return start.map((s,i)=>s+t*(end[i]-s));}// Object-based vector interpolation
if((0,_utils.isObjectVector)(start)&&(0,_utils.isObjectVector)(end)){const result=Object.assign({});for(const key in start){if(key in start&&key in end){const k=key;// x | y | z | w
result[k]=start[k]+t*(end[k]-start[k]);}}return result;}throw new Error('Invalid input types for lerp function');}