Add projects and tutorials
This commit is contained in:
14
tutorials/summed_area/snippets/countSquares.js
Normal file
14
tutorials/summed_area/snippets/countSquares.js
Normal file
@@ -0,0 +1,14 @@
|
||||
// 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;
|
||||
}
|
||||
16
tutorials/summed_area/snippets/defineCount.js
Normal file
16
tutorials/summed_area/snippets/defineCount.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// where br is the cell we're calculating
|
||||
function defineCount(br) {
|
||||
let c = 0;
|
||||
|
||||
// br.x is the column number
|
||||
// br.y is the row number
|
||||
for (y = 0; y <= br.y; y++) { // loop through all rows above br (and the row br is on)
|
||||
for (x = 0; x <= br.x; x++) { // loop through all columns to the left of br (and br column)
|
||||
var i = x + n * y; // convert 2d array format to 1d index
|
||||
if (t[i].s) { // if cell[i].status==true then increase count
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
Reference in New Issue
Block a user