New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@4bitlabs/quadtree

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@4bitlabs/quadtree

A simple 2D quadtree (2×2 spatial division) for fast, efficient spatial queries

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-16.67%
Maintainers
0
Weekly downloads
 
Created
Source

@4bitlabs/quadtree License NPM Version NPM Downloads

A simple 2D quadtree (2×2 spatial division) for fast, efficient spatial queries.

Quadtree split illustration

Installing

$ npm install --save @4bitlabs/quadtree
$ yarn add @4bitlabs/quadtree
$ pnpm add @4bitlabs/quadtree

Documentation

Full documentation for the library can be found here

Usage

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]);

Options

quadtree() accept a third argument of options:

optionDescriptionDefaults
maxDepthThe maximum depth/subdivisions that the graph will divide.7
maxChildrenThe maximum number of objects in a node before it will split10
const space = quadtree<DOMRect>([0, 0, 1000, 1000], rectBounds, {
  maxDepth: 5,
  maxChildren: 50,
});

License

ISC

Keywords

FAQs

Package last updated on 26 Jul 2024

Did you know?

Socket

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.

Install

Related posts

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