1.0.3 • Published 1 month ago

@wingit/cellmap v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

CellMap

npm npm GitHub

Spatial Hash Grid that extends Map

Features

  • :heavy_check_mark: Elements are stored on a 2D grid
  • :heavy_check_mark: Filter nearby elements
  • :heavy_check_mark: Extends Map
  • :blue_square: Written in TypeScript

Installation

Using npm

npm i @wingit/cellmap

Using bun

bun i @wingit/cellmap

Usage

import CellMap from "@wingit/cellmap";

// create a CellMap(width, height, cell size)
const units = new CellMap(100, 100, 10);

// add a unit
// set hash to -1, it is used internally and gets reassigned when added
const unit = { id: "1", hash: -1, pos: {x: 0, y: 0}, name: "Bob" };
units.set(units.id, unit);

// delete a unit
units.delete("1");

// update a unit
unit.pos.x = 35;
units.update(unit);

// get cells in range
const cellsInRange = g.ig.units.query(pos, radius);
for (const cell of cellsInRange) {
    for (const u of cell){
        console.log(u);
    }
}

License

MIT

1.0.3

1 month ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago