All files / core/src/utilities indexWithinDimensions.ts

100% Statements 3/3
100% Branches 8/8
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 16 17 18 19 20 21 22 23 24 25 26 27 28                            178x               53x     125x    
import type { Point3 } from '../types';
 
/**
 * Returns true if the specified index is within the given dimensions.
 *
 * @param index - The index to check.
 * @param dimensions - The dimensions to check against.
 *
 * @returns True if the index is in-bounds.
 */
export default function indexWithinDimensions(
  index: Point3,
  dimensions: Point3
): boolean {
  if (
    index[0] < 0 ||
    index[0] >= dimensions[0] ||
    index[1] < 0 ||
    index[1] >= dimensions[1] ||
    index[2] < 0 ||
    index[2] >= dimensions[2]
  ) {
    return false;
  }
 
  return true;
}