All files / src/core/grid grid-scan.ts

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

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 211x 101x 101x 101x 101x 101x 101x 101x 101x 101x 101x 101x 101x   101x 404x 2020x 2020x 404x 101x  
export function scanCellWindow(
  gridWidth: number,
  gridHeight: number,
  approxCol: number,
  approxRow: number,
  colRadius: number,
  rowRadius: number,
  visit: (col: number, row: number) => void
): void {
  const minRow = Math.max(0, approxRow - rowRadius);
  const maxRow = Math.min(gridHeight - 1, approxRow + rowRadius);
  const minCol = Math.max(0, approxCol - colRadius);
  const maxCol = Math.min(gridWidth - 1, approxCol + colRadius);
 
  for (let r = minRow; r <= maxRow; r++) {
    for (let c = minCol; c <= maxCol; c++) {
      visit(c, r);
    }
  }
}