supergrid: An extremely optimized (safe) spatial hash grid.
This project was bootstrapped by create-neon.
Installing supergrid requires a supported version of Node and Rust.
You can install the project with npm. In the project directory, run:
$ npm install
This fully installs the project, including installing any dependencies and running the build.
If you have already installed the project and only want to run the build, run:
$ npm run build -- --release
This command uses the cargo-cp-artifact utility to run the Rust build and copy the built library into ./index.node
.
const Grid = require('supergrid-bindings');
let grid = new Grid(1024, 7); // Hash table size of 1,024,000, with a cell size of 128x128
grid.insert({
// IDs MUST BE UNIQUE
id: 0,
x: 50,
y: 50,
width: 100,
height: 100,
});
grid.insert({
id: 1,
x: 300,
y: 300,
width: 20,
height: 20,
});
let intersectingIDs = grid.query({
x: 0,
y: 0,
width: 500,
height: 500,
});
console.log(intersectingIDs); // [0, 1]