![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@4bitlabs/quadtree
Advanced tools
A simple 2D quadtree (2×2 spatial division) for fast, efficient spatial queries
@4bitlabs/quadtree
A simple 2D quadtree (2×2 spatial division) for fast, efficient spatial queries.
$ npm install --save @4bitlabs/quadtree
$ yarn add @4bitlabs/quadtree
$ pnpm add @4bitlabs/quadtree
Full documentation for the library can be found here
An easy way to use this within a browser is to use the built-in DOMRect
class, consider:
import { quadtree, type Bounds } from '@4bitlabs/quadtree';
const rectBounds = (r: DOMRect) => [r.left, r.top, r.right, r.bottom];
const space = quadtree<DOMRect>([0, 0, 1000, 1000], rectBounds);
space.insert(new DOMRect(25, 25, 50, 50));
const matches = space.search([20, 20, 80, 80]);
Or with custom objects:
import { quadtree, type Bounds } from '@4bitlabs/quadtree';
class Shape {
bounds(): Bounds {
/* TODO implement return bounds */
return [0, 0, 0, 0];
}
}
const space = quadtree<Shape>([0, 0, 1000, 1000], Shape.prototype.bounds);
space.insert(new Shape());
const matches = space.search([20, 20, 80, 80]);
quadtree()
accept a third argument of options
:
option | Description | Defaults |
---|---|---|
maxDepth | The maximum depth/subdivisions that the graph will divide. | 7 |
maxChildren | The maximum number of objects in a node before it will split | 10 |
const space = quadtree<DOMRect>([0, 0, 1000, 1000], rectBounds, {
maxDepth: 5,
maxChildren: 50,
});
FAQs
A simple 2D quadtree (2×2 spatial division) for fast, efficient spatial queries
The npm package @4bitlabs/quadtree receives a total of 10 weekly downloads. As such, @4bitlabs/quadtree popularity was classified as not popular.
We found that @4bitlabs/quadtree demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.