All files / packages/core/src/utilities isEqual.ts

85.71% Statements 6/7
87.5% Branches 7/8
100% Functions 1/1
85.71% Lines 6/7

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                            324x 324x       324x 610x 218x       106x    
/**
 * 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 isEqual(
  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++) {
    if (Math.abs(v1[i] - v2[i]) > tolerance) {
      return false;
    }
  }
 
  return true;
}