JSPM

@berkozturkdev/grid-neighbors-1d

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q44122F
  • License ISC

Find neighbors of a grid cell

Package Exports

  • @berkozturkdev/grid-neighbors-1d

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@berkozturkdev/grid-neighbors-1d) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

grid-neighbors-1d

Get the 8 closest neighbours of a grid with edge wrapping from a 1d array

Why?

grid-neighbors

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:

  • neighbors[0] = north west neighbor
  • neighbors[1] = north neighbor
  • neighbors[2] = north east neighbor
  • neighbors[3] = west neighbor
  • neighbors[4] = east neighbor
  • neighbors[5] = south west neighbor
  • neighbors[6] = south neighbor
  • neighbors[7] = south east neighbor

License

(C) 2019 P. Hughes. All rights reserved.

Shared under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license.