# @jgtools/shg

> Spatial Hash Grid

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

## Install

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

## 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.4 |
| Published | 2022-12-21 |
| First published | 2022-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Erik1001 |
| Maintainers | jgtools |
| Keywords | javascript, typescript, spatial-hash, spatial-hash-grid, shg |

## Links

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

## 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.4 (latest) — 2022-12-21
- 1.0.3 — 2022-12-21
- 1.0.2 — 2022-12-21
- 1.0.1 — 2022-12-21
- 1.0.0 — 2022-12-21

## README

# SHG

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

2D Spatial Hash Grid

## Features

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

## Installation

### Using npm

```bash
npm i @jgtools/shg
```

```javascript
import SHG from "@jgtools/shg";
// ...
```

### Using cdn

```html
<script type="module">
    import SHG from "https://cdn.jsdelivr.net/npm/@jgtools/shg@1.0.4/dist/index.min.js";
    // ...
</script>
```

## Usage

```javascript
import SHG from "@jgtools/shg";

const width = 100;
const height = 60;
const cellSize = 10;
const shg = new SHG(width, height, cellSize);

for (let i = 0; i < 10; i++) {
  const [x, y] = [Math.random() * width, Math.random() * height];
  shg.set(i.toString(), x, y);
}

console.log(shg.query(40, 30, 10));
shg.update("1", 40, 30); // update item '1' position
console.log(shg.query(40, 30, 10));
shg.delete("1"); // delete item '1'
console.log(shg.query(40, 30, 10));
shg.clear(); // delete all items from grid
console.log(shg.query(40, 30, 10));
```

## License

MIT

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