Returns neighbours for a cell. If no directions are provided, it defaults to allDirections.
directions
const grid = { rows: 5, cols: 5 };const cell = { x:2, y:2 };// Get n,ne,nw,e,s,se,sw and w neighboursconst n = Grids.neighbours(grid, cell, `wrap`);Yields:{ n: {x: 2, y: 1} s: {x: 2, y: 3} ....} Copy
const grid = { rows: 5, cols: 5 };const cell = { x:2, y:2 };// Get n,ne,nw,e,s,se,sw and w neighboursconst n = Grids.neighbours(grid, cell, `wrap`);Yields:{ n: {x: 2, y: 1} s: {x: 2, y: 3} ....}
Returns neighbours without diagonals (ie: n, e, s, w):
const n = Grids.neighbours(grid, cell, `stop`, Grids.crossDirections); Copy
const n = Grids.neighbours(grid, cell, `stop`, Grids.crossDirections);
Grid
Cell
How to handle edges of grid
Optional
Directions to return
Returns a map of cells, keyed by cardinal direction
Returns neighbours for a cell. If no
directions
are provided, it defaults to allDirections.Returns neighbours without diagonals (ie: n, e, s, w):