Files
havox/tutorials/summed_area/snippets/countSquares.js
2026-03-16 18:03:17 +00:00

15 lines
437 B
JavaScript

// where tl and br are the top left and bottom right cell respectively
function countSquares(tl, br) {
// these are the four cells to interrogate
let topLeft, left, top, whole;
// 1d index = x + #rows * y
topLeft = t[(tl.x - 1) + n * (tl.y - 1)].count;
left = t[(tl.x - 1) + n * bry].count;
top = t[br.x + n * (tl.y - 1)].count;
whole = t[br.x + n * br.y].count;
return whole + topLeft - top - left;
}