Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grid-index

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grid-index - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

27

grid-index.js

@@ -70,6 +70,6 @@ 'use strict';

GridIndex.prototype.query = function(x1, y1, x2, y2) {
GridIndex.prototype.query = function(x1, y1, x2, y2, intersectionTest) {
var min = this.min;
var max = this.max;
if (x1 <= min && y1 <= min && max <= x2 && max <= y2) {
if (x1 <= min && y1 <= min && max <= x2 && max <= y2 && !intersectionTest) {
// We use `Array#slice` because `this.keys` may be a `Int32Array` and

@@ -83,3 +83,3 @@ // some browsers (Safari and IE) do not support `TypedArray#slice`

var seenUids = {};
this._forEachCell(x1, y1, x2, y2, this._queryCell, result, seenUids);
this._forEachCell(x1, y1, x2, y2, this._queryCell, result, seenUids, intersectionTest);
return result;

@@ -89,3 +89,3 @@ }

GridIndex.prototype._queryCell = function(x1, y1, x2, y2, cellIndex, result, seenUids) {
GridIndex.prototype._queryCell = function(x1, y1, x2, y2, cellIndex, result, seenUids, intersectionTest) {
var cell = this.cells[cellIndex];

@@ -99,6 +99,8 @@ if (cell !== null) {

var offset = uid * 4;
if ((x1 <= bboxes[offset + 2]) &&
if (intersectionTest ?
intersectionTest(bboxes[offset + 0], bboxes[offset + 1], bboxes[offset + 2], bboxes[offset + 3]) :
((x1 <= bboxes[offset + 2]) &&
(y1 <= bboxes[offset + 3]) &&
(x2 >= bboxes[offset + 0]) &&
(y2 >= bboxes[offset + 1])) {
(y2 >= bboxes[offset + 1]))) {
seenUids[uid] = true;

@@ -114,3 +116,3 @@ result.push(keys[uid]);

GridIndex.prototype._forEachCell = function(x1, y1, x2, y2, fn, arg1, arg2) {
GridIndex.prototype._forEachCell = function(x1, y1, x2, y2, fn, arg1, arg2, intersectionTest) {
var cx1 = this._convertToCellCoord(x1);

@@ -123,3 +125,8 @@ var cy1 = this._convertToCellCoord(y1);

var cellIndex = this.d * y + x;
if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2)) return;
if (intersectionTest && !intersectionTest(
this._convertFromCellCoord(x),
this._convertFromCellCoord(y),
this._convertFromCellCoord(x + 1),
this._convertFromCellCoord(y + 1))) continue;
if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, intersectionTest)) return;
}

@@ -129,2 +136,6 @@ }

GridIndex.prototype._convertFromCellCoord = function(x) {
return (x - this.padding) / this.scale;
};
GridIndex.prototype._convertToCellCoord = function(x) {

@@ -131,0 +142,0 @@ return Math.max(0, Math.min(this.d - 1, Math.floor(x * this.scale) + this.padding));

{
"name": "grid-index",
"version": "1.0.0",
"version": "1.1.0",
"description": "A 2D spatial index for axis-aligned boxes",

@@ -5,0 +5,0 @@ "main": "grid-index.js",

@@ -34,3 +34,3 @@ # grid-index

var arrayBuffer = grid.toArrayBuffer();
// transfer the ArrayBuffer to a different worker
// transfer the ArrayBuffer to a different worker

@@ -58,3 +58,3 @@ var grid2 = new GridIndex(arrayBuffer);

### `gridIndex.insert(key, x1, x2, y1, y2)`
### `gridIndex.insert(key, x1, y1, x2, y2)`

@@ -65,8 +65,8 @@ Insert a new key, box pair into the grid.

- **x1**: The x coordinate of the left edge of the box.
- **y1**: The y coordinate of the bottom edge of the box.
- **x2**: The x coordinate of the right edge of the box.
- **y1**: The y coordinate of the top edge of the box.
- **y2**: The y coordinate of the bottom edge of the box.
- **y2**: The y coordinate of the top edge of the box.
### `gridIndex.query(key, x1, x2, y1, y2)`
### `gridIndex.query(key, x1, y1, x2, y2, intersectionTest?)`

@@ -76,5 +76,6 @@ Find the keys that intersect with the given box.

- **x1**: The x coordinate of the left edge of the box.
- **y1**: The y coordinate of the bottom edge of the box.
- **x2**: The x coordinate of the right edge of the box.
- **y1**: The y coordinate of the top edge of the box.
- **y2**: The y coordinate of the bottom edge of the box.
- **y2**: The y coordinate of the top edge of the box.
- **intersectionTest**: An optional function that can be used to filter results by bbox. If provided, this function is called for each possible result with four arguments: x1, y1, x2, y2. Return true to include the result in the returned value.

@@ -81,0 +82,0 @@ **returns** an array of keys.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc