# @jgtools/gridmap

> Spatial Hash Grid that extends Map

Latest version **1.0.0** (published 2022-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jgtools/gridmap
pnpm add @jgtools/gridmap
yarn add @jgtools/gridmap
bun add @jgtools/gridmap
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-12-21 |
| First published | 2022-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Erik1001 |
| Maintainers | jgtools |
| Keywords | javascript, typescript, spatial-hash, spatial-hash-grid, shg |

## Links

- npm: https://www.npmjs.com/package/@jgtools/gridmap
- Repository: https://github.com/JGTools/GridMap
- Homepage: https://github.com/JGTools/GridMap#readme
- Issues: https://github.com/JGTools/GridMap/issues
- npm.io page: https://npm.io/package/@jgtools/gridmap

## Dependencies (1)

- [@jgtools/shg](https://npm.io/package/@jgtools/shg.md) ^1.0.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-12-21

## README

# GridMap

[![npm](https://img.shields.io/npm/v/@jgtools/gridmap)](https://www.npmjs.com/package/@jgtools/gridmap)
[![npm](https://img.shields.io/npm/dm/@jgtools/gridmap)](https://www.npmjs.com/package/@jgtools/gridmap)
[![GitHub](https://img.shields.io/github/license/jgtools/gridmap)](https://github.com/git/git-scm.com/blob/main/MIT-LICENSE.txt)

2D 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

```bash
npm i @jgtools/gridmap
```

```javascript
import GridMap from "@jgtools/gridmap";
// ...
```

## Usage

```javascript
import GridMap from "@jgtools/gridmap";

const entities = new GridMap(100, 60, 10);

const entity = { id: "1", x: 0, y: 0, name: "Bob" };
entities.set(entity.id, entity, entity.x, entity.y);

const entity2 = { id: "2", x: 15, y: 15, name: "Joe" };
entities.set(entity2.id, entity2, entity2.x, entity2.y);

console.log("nearby entities: ", gm.query(20, 20, 10));

entities.update("1", 15, 20);
console.log("nearby entities: ", gm.query(20, 20, 10));

entities.delete("2");
console.log("nearby entities: ", gm.query(20, 20, 10));

console.log("amount of entities:", gm.size);
console.log("entity with id 1: ", gm.get("1"));

entities.clear();
console.log("nearby entities: ", gm.query(20, 20, 10));
console.log("amount of entities after clear:", gm.size);
```

## License

MIT

---
_Source: https://npm.io/package/@jgtools/gridmap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
