1.0.1 • Published 1 year ago
@rgsoft/quadtree v1.0.1
QuadTree
Quadtree Lib for Typescript/Javascript
Installation
npm install @rgsoft/quadtreeUsage
The constructor of the QuadTree class expects to parameters:
k: number: The capacity of each layerboundary: Rect: An instance of theRectclass 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);