Returns the index for a given cell in a UniformGrid. This is useful if a grid is stored in an array.
const data = [ 1, 2, 3, 4, 5, 6];// Get index for cell {x: 1, y: 1} (ie. second column, second row)const index = indexFromCell({ rows: 2, cols: 2}, {x: 1, y: 1}); // Yields 3console.log(data[index]); // Yields 4 Copy
const data = [ 1, 2, 3, 4, 5, 6];// Get index for cell {x: 1, y: 1} (ie. second column, second row)const index = indexFromCell({ rows: 2, cols: 2}, {x: 1, y: 1}); // Yields 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 in a UniformGrid. 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
Param: grid
Grid
Param: cell
Cell to get index for
Param: wrap
Logic for if we hit bounds of grid