Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
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, x2, y1, y2)
Insert a new key, box pair into the grid.
gridIndex.query(key, x1, x2, y1, y2)
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
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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.