js-quadtree
Version:
A simple quadtree implementation for javascript (nodejs or browser with module bundler).
108 lines • 3.97 kB
TypeScript
import { Box } from './Box';
import { Point } from './Point';
import { QuadTreeConfig, Tree, Shape } from "./types";
/**
* QuadTree class.
* @class QuadTree
*/
export declare class QuadTree {
private readonly container;
private isDivided;
private points;
private readonly config;
private ne;
private nw;
private se;
private sw;
/**
* Create a new QuadTree
* @constructor
* @param {Box} container - The box on which the QuadTree will operate.
* @param {Object} [config] - The configuration of the quadtree.
* @param {number} [config.capacity] - The maximum amount of points per node.
* @param {boolean} [config.removeEmptyNodes] - Specify if the quadtree has to remove subnodes if they are empty.
* @param {number} [config.maximumDepth] - Specify the maximum depth of the tree.
* @param {function} [config.arePointsEqual] - Specify a custom method to compare point for removal.
* @param {(Object[]|Point[])} [points] - An array of initial points to insert in the QuadTree.
* @param {number} points[].x - X coordinate of the point.
* @param {number} points[].y - Y coordinate of the point.
*/
constructor(container: Box, config?: QuadTreeConfig, points?: Point[]);
/**
* Return a tree representation of the QuadTree
* @returns {{se: *, sw: *, ne: *, nw: *}|Number} - A tree representation of the QuadTree
*/
getTree(): Tree;
/**
* Get all the points in the QuadTree
* @returns {(Object[]|Point[])} - An array containing all the points.
*/
getAllPoints(): Point[];
/**
* Get all the points in the QuadTree
* @param {(Object[]|Point[])} pointsList
* @private
*/
private getAllPointsRecursive;
/**
* Return the amount of points in this node.
* @returns {number} - The amount of points in this node.
* @private
*/
private getNodePointAmount;
/**
* Divide this node into 4 sub-nodes
* @private
*/
private divide;
/**
* Remove a point in the QuadTree
* @param {(Point|Object|Point[]|Object[])} pointOrArray - A point or an array of points to remove
* @param {number} pointOrArray.x - X coordinate of the point
* @param {number} pointOrArray.y - Y coordinate of the point
*/
remove(pointOrArray: Point | Point[]): void;
/**
* Remove a point in the QuadTree
* @param {(Point|Object)} point - A point to remove
* @param {number} point.x - X coordinate of the point
* @param {number} point.y - Y coordinate of the point
* @private
*/
private removeRecursive;
/**
* Insert a point in the QuadTree
* @param {(Point|Object|Point[]|Object[])} pointOrArray - A point or an array of points to insert
* @param {number} pointOrArray.x - X coordinate of the point
* @param {number} pointOrArray.y - Y coordinate of the point
* @returns {boolean} true if the point or all the point has been inserted, false otherwise
*/
insert(pointOrArray: Point | Point[]): boolean;
/**
* Insert a point in the QuadTree
* @param {(Point|Object)} point - A point to insert
* @param {number} point.x - X coordinate of the point
* @param {number} point.y - Y coordinate of the point
* @returns {boolean}
* @private
*/
private insertRecursive;
/**
* Query all the point within a range
* @param {Shape} range - The range to test
* @returns {(Point[]|Object[])} - The points within the range
*/
query(range: Shape): Point[];
/**
* @param {Shape} range
* @param {(Point[]|Object[])} pointsFound
* @returns {(Point[]|Object[])}
* @private
*/
private queryRecursive;
/**
* Clear the QuadTree
*/
clear(): void;
}
//# sourceMappingURL=QuadTree.d.ts.map