All files / packages/tools/src/utilities/math/vec3 interpolateVec3.ts

50% Statements 1/2
100% Branches 0/0
0% Functions 0/1
50% Lines 1/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                      1x                  
/**
 * Linear interpolation between two vec3.
 * Can be used, for example, to interpolate between two RGB colors.
 * @param a - First vec3
 * @param b - Second vec3
 * @param t - Time "t".
 *   - Vector A is returned for values smaller than or equel to 0.
 *   - Vector B is returned for values greater than or equal to 1.
 *   - An interpolation between vectors A and B is returned otherwise.
 * @returns
 */
const interpolateVec3 = (a, b, t) => {
  return [
    a[0] * (1 - t) + b[0] * t,
    a[1] * (1 - t) + b[1] * t,
    a[2] * (1 - t) + b[2] * t,
  ];
};
 
export { interpolateVec3 as default, interpolateVec3 };