UNPKG

fqtree

Version:

a flexible quadtree for JavaScript/TypeScript

114 lines 3.9 kB
import { Option } from 'onsreo'; import { PointLike } from 'evjkit'; import { IRange, RectangleRange } from './range'; import { DataCache } from './caches'; export declare interface QtSpatial extends PointLike { id: number; } export declare type QtDataTuple<T> = [data: T, qt_id: number]; export declare class QuadTree<Spatial extends QtSpatial> { id: number; boundary: RectangleRange; capacity: number; data: Array<number>; divided: boolean; maxDepth: number; root: Option<number>; ne: Option<number>; nw: Option<number>; se: Option<number>; sw: Option<number>; /** * A Quadtree for spatial partitioning and searching. * @param boundary - this QuadTree<Spatial>'s bounds * @param capacity - how many points this quadtree can hold * @param root - QuadTree<Spatial>'s root Instance (only used for subdivisions) */ constructor(boundary: RectangleRange, capacity?: number, maxDepth?: number, root?: Option<number>); /** * clears this quadtree and its children (if any). */ _clear(): void; destroy(): void; get qt_cache(): DataCache<QuadTree<Spatial>>; get data_cache(): DataCache<QtDataTuple<Spatial>>; /** * resets the quadtree and optionally sets new bounds. * @param boundary - this QuadTree<Spatial>'s bounds */ reset(bounds?: RectangleRange): void; /** * subdivide this tree into 4 new quadrants. */ subdivide(): void; _insert(spatial: Spatial): void; /** * insert a spatial into this tree. * @param spatial - spatial to insert. */ insert(spatial: Spatial): void; /** * insert all the provided spatials. * @param spatials - spatials to insert. */ insertMany(spatials: Set<Spatial> | Array<Spatial>): void; /** * tests if this quadtree's boundary completely contains the spatial. * @param spatial - spatial to test. * @returns true if contained within the bounds, else false. */ contains(spatial: Spatial): boolean; /** * tests if this quadtree's boundary intersects with the boundary. * @param spatial - spatial to test. * @returns true if intersects, else false. */ intersects(range: IRange): boolean; getData(): Spatial[]; /** * query insertain spatial using provided range. * @param range - range for query * @param found - set to fill [default: empty Set]. * @returns query results as a set */ query(range: IRange, found?: Set<Spatial>): Set<Spatial>; _remove(id: number): void; /** * remove the given spatial from the quadtree. * @param spatial - spatial to remove. */ remove(spatial: Spatial): void; /** * remove a spatial by id. * @param id - id of spatial to remove. */ removeById(id: number): void; /** * remove all spatials with the provided IDs. * @param removedIds - array of uuids to remove. */ removeByIds(removedIds: Array<number>): void; /** * remove many spatials from the quadtree. * @param spatials - spatials to remove. */ removeMany(spatials: Set<Spatial> | Array<Spatial>): void; /** * update a spatial point. * @param spatial - spatial point to update. */ update(spatial: Spatial): void; /** * returns all spatials within the tree. * @param spatials - optional starting set [default: empty Set]. * @returns All contained spatials within the tree. */ getAllSpatials(spatials?: Set<Spatial>): Set<Spatial>; /** * update the bounds of the current quadtree * @param newBounds - the bounds for the quadtree. * @param spatials - optional spatials to insert [default: all previously inserted spatials] */ updateBounds(newBounds: RectangleRange, spatials?: Set<Spatial>): void; } //# sourceMappingURL=quadtree.d.ts.map