Socket
Socket
Sign inDemoInstall

d3-quadtree

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-quadtree

Two-dimensional recursive spatial subdivision.


Version published
Weekly downloads
3.3M
increased by5.73%
Maintainers
2
Weekly downloads
 
Created

What is d3-quadtree?

The d3-quadtree package is a part of the D3.js library and provides a data structure known as a quadtree. A quadtree is a tree data structure in which each internal node has exactly four children. Quadtrees are often used to partition a two-dimensional space by recursively subdividing it into four quadrants or regions. This package is particularly useful for spatial indexing, collision detection, and efficient neighbor searching.

What are d3-quadtree's main functionalities?

Creating a Quadtree

This feature allows you to create a quadtree from a set of points. The quadtree can then be used for efficient spatial queries.

const d3 = require('d3-quadtree');
const points = [[0, 0], [1, 1], [2, 2], [3, 3]];
const quadtree = d3.quadtree().addAll(points);

Adding Points

This feature allows you to add individual points to an existing quadtree. This is useful for dynamically updating the quadtree as new data points are introduced.

const d3 = require('d3-quadtree');
const quadtree = d3.quadtree();
quadtree.add([0, 0]);
quadtree.add([1, 1]);

Finding Nearest Neighbor

This feature allows you to find the nearest neighbor to a given point. This is useful for applications like collision detection or finding the closest data point.

const d3 = require('d3-quadtree');
const points = [[0, 0], [1, 1], [2, 2], [3, 3]];
const quadtree = d3.quadtree().addAll(points);
const nearest = quadtree.find(1.5, 1.5);

Bounding Box Search

This feature allows you to search for points within a specific bounding box. This is useful for spatial queries where you need to find all points within a certain area.

const d3 = require('d3-quadtree');
const points = [[0, 0], [1, 1], [2, 2], [3, 3]];
const quadtree = d3.quadtree().addAll(points);
const found = [];
quadtree.visit((node, x0, y0, x1, y1) => {
  if (!node.length) {
    do {
      const d = node.data;
      if (d[0] >= 1 && d[0] <= 2 && d[1] >= 1 && d[1] <= 2) {
        found.push(d);
      }
    } while (node = node.next);
  }
  return x0 >= 2 || y0 >= 2 || x1 < 1 || y1 < 1;
});

Other packages similar to d3-quadtree

Keywords

FAQs

Package last updated on 23 Aug 2020

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