Socket
Book a DemoInstallSign in
Socket

@rgsoft/quadtree

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rgsoft/quadtree

Quadtreae library

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

QuadTree

Quadtree Lib for Typescript/Javascript

Installation

npm install @rgsoft/quadtree

Usage

The constructor of the QuadTree class expects to parameters:

  • k: number: The capacity of each layer
  • boundary: Rect: An instance of the Rect class that sets the initial boundary
const { QuadTree, Rect } = require('@rgsoft/quadtree');
const k = 1;

const q = new QuadTree(k, new Rect(0, 0, 160, 160));

Adding Points

The addPoint method will insert a point into the structure, subdividing in four quadrants if necesary.

q.addPoint({ x: 50, y: 50 })

It expects any parameter that implements the Point interface.

export interface Point {
    x: number;
    y: number;
}

Querying Points

The query method searches for point in a given area. This area can be a Rect or a Circle.

let area = new Rect(30, 30, 25, 25);
let points = q.query(area);

area = new Circle(30, 30, 20);
points = q.query(area);

Keywords

typescript

FAQs

Package last updated on 11 Nov 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