All files / platform/core/src/utils isEqualWithin.ts

0% Statements 0/7
0% Branches 0/3
0% Functions 0/1
0% Lines 0/6

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 22 23 24 25 26 27 28                                                       
/**
 * returns equal if the two arrays are identical within the
 * given tolerance.
 *
 * @param v1 - The first array of values
 * @param v2 - The second array of values.
 * @param tolerance - The acceptable tolerance, the default is 0.00001
 *
 * @returns True if the two values are within the tolerance levels.
 */
export default function isEqualWithin(
  v1: number[] | Float32Array,
  v2: number[] | Float32Array,
  tolerance = 1e-5
): boolean {
  Iif (v1.length !== v2.length) {
    return false;
  }
 
  for (let i = 0; i < v1.length; i++) {
    Iif (Math.abs(v1[i] - v2[i]) > tolerance) {
      return false;
    }
  }
 
  return true;
}