0.0.1-2 • Published 5 months ago

@pomle/grid v0.0.1-2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Grid

A JavaScript and TypeScript lib for working with grids of any size and any dimension.

Usage

Write a number to each cell in a 2x2 grid

import { Grid } from '@pomle/grid';

const grid = new Grid<number, 'x' | 'y'>({ x: 2, y: 2 });

let count = 0;
for (const coord of grid) {
  count += 1;
  grid.set(coord, count);
}

Dimensions can use any name

import { Grid } from '@pomle/grid';

const grid = new Grid({ width: 320, height: 240 });

Dimensions can use number of dimensions

import { Grid } from '@pomle/grid';

const grid = new Grid({ a: 10, b: 10, c: 10, d: 10 });
grid.set({ a: 1, b: 1, c: 1, d: 1 }, 'one');
grid.set({ a: 2, b: 2, c: 2, d: 2 }, 'two');

Neighbours can be explored

import { Grid } from '@pomle/grid';

const grid = new Grid({ x: 3, y: 3 });
for (const coord of grid.neighbours({ x: 1, y: 1 })) {
  console.log(coord); // Prints cartesian product of {x: 0, y: 0} to {x: 2, y: 2}
}
0.0.1-2

5 months ago

0.0.1-1

5 months ago

0.0.1-0

5 months ago