All files / core/src/utilities reflectVector.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

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                    276x 276x 276x    
import { vec3 } from 'gl-matrix';
 
/**
 * Reflects a vector `v` over a given normal vector.
 *
 * @param v - The vector to reflect.
 * @param normal - The normal vector to reflect over.
 * @returns The reflected vector.
 */
export function reflectVector(v: vec3, normal: vec3): vec3 {
  const dotProduct = vec3.dot(v, normal);
  const scaledNormal = vec3.scale(vec3.create(), normal, 2 * dotProduct);
  return vec3.sub(vec3.create(), v, scaledNormal);
}