1.0.0 • Published 1 year ago

@rgsoft/quadtree v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

1 year ago

1.0.0

1 year ago