
Security News
Meet the Socket Team at RSAC and BSidesSF 2025
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.
GridIndex is a 2D spatial index that is transferable.
Pairs of keys and boxes can be inserted into GridIndex. The grid can then be queried to find all the keys that intersect a given box. The grid can be serialized to an ArrayBuffer so that it can be transferred between WebWorkers.
You should probably use rbush instead of GridIndex! It's easier to use and it's as fast or faster in many cases.
GridIndex can be faster in a specific set of cases:
GridIndex is used by mapbox-gl-js for label collision detection and feature picking.
var GridIndex = require('grid-index');
var grid = new GridIndex(100, 5, 0);
var key1 = 1;
var key2 = 2;
var key3 = 3;
grid.insert(key1, 30, 10, 35, 15);
grid.insert(key2, 60, 20, 65, 25);
grid.insert(key3, 40, 10, 45, 15);
var keys = grid.query(0, 0, 100, 13);
// `keys` is now [key1, key3]
var arrayBuffer = grid.toArrayBuffer();
// transfer the ArrayBuffer to a different worker
var grid2 = new GridIndex(arrayBuffer);
var keys2 = grid2.query(0, 0, 100, 13);
// `keys2` is now [key1, key3]
GridIndex(extent, n, padding)
Create a new GridIndex.
4096
.4
would divide the grid into 16 cells.GridIndex(arrayBuffer)
Unserialize a GridIndex.
gridIndex.toArrayBuffer()
.gridIndex.insert(key, x1, y1, x2, y2)
Insert a new key, box pair into the grid.
gridIndex.query(key, x1, y1, x2, y2, intersectionTest?)
Find the keys that intersect with the given box.
returns an array of keys.
gridIndex.toArrayBuffer()
Serialize a GridIndex to an ArrayBuffer so that it can be transferred between WebWorkers efficiently.
returns an ArrayBuffer that can later be deserialized with new GridIndex(arrayBuffer)
.
FAQs
A 2D spatial index for axis-aligned boxes
The npm package grid-index receives a total of 1,156,291 weekly downloads. As such, grid-index popularity was classified as popular.
We found that grid-index demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.
Security News
Biome's v2.0 beta introduces custom plugins, domain-specific linting, and type-aware rules while laying groundwork for HTML support and embedded language features in 2025.
Security News
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.