1.0.2 • Published 4 years ago
@berkozturkdev/grid-neighbors-1d v1.0.2
grid-neighbors-1d
Get the 8 closest neighbours of a grid with edge wrapping from a 1d array
Why?
Usage
Get the neighbours of cell 12 in a 5x6 grid:
const gn = require('grid-neighbors-1d');
const neighbors = gn(12, 5, 6);
console.log(neighbours); // [6, 7, 8, 11, 13, 16, 17, 18]
grid-neighbors returns an array of indexes where:
- neighbors0 = north west neighbor
- neighbors1 = north neighbor
- neighbors2 = north east neighbor
- neighbors3 = west neighbor
- neighbors4 = east neighbor
- neighbors5 = south west neighbor
- neighbors6 = south neighbor
- neighbors7 = south east neighbor
License
(C) 2019 P. Hughes. All rights reserved.
Shared under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license.