Function indexFromCell

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 wide
const index = indexFromCell(cols, {x: 1, y: 1});
// Yields an index of 3
console.log(data[index]); // Yields 4

Bounds logic is applied to cell.x/y separately. Wrapping only ever happens in same col/row.

cellFromIndex

  • Parameters

    • grid: Grid

      Grid

    • cell: Cell

      Cell to get index for

    • wrap: BoundsLogic

      Logic for if we hit bounds of grid

    Returns undefined | number