Returns the index for a given cell. This is useful if a grid is stored in an array.
const data = [ 1, 2, 3, 4, 5, 6 ];const cols = 2; // Grid of 2 columns wideconst index = indexFromCell(cols, {x: 1, y: 1});// Yields an index of 3console.log(data[index]); // Yields 4 Copy
const data = [ 1, 2, 3, 4, 5, 6 ];const cols = 2; // Grid of 2 columns wideconst index = indexFromCell(cols, {x: 1, y: 1});// Yields an index of 3console.log(data[index]); // Yields 4
Bounds logic is applied to cell.x/y separately. Wrapping only ever happens in same col/row.
cellFromIndex
Grid
Cell to get index for
Logic for if we hit bounds of grid
Returns the index for a given cell. This is useful if a grid is stored in an array.
Bounds logic is applied to cell.x/y separately. Wrapping only ever happens in same col/row.
See
cellFromIndex