trassel
Version:
Graph computing in JavaScript
69 lines (68 loc) • 3.13 kB
TypeScript
/**
* This is a point region quadtree (i.e. all nodes must have their own quadrant, the only exception being identically positioned nodes).
* This can be used for collision detection as well as n-body approximations such as Barnes and Hut
* To read more about quad trees:
* https://en.wikipedia.org/wiki/
*/
export default class Quadtree {
/**
* @param {import("../model/igraphnode").IGraphNode[]=} entities - Graph nodes to base the quadtree on
*/
constructor(entities?: import("../model/igraphnode").IGraphNode[] | undefined);
isMassComputed: boolean;
isLargestRadiusComputed: boolean;
entities: any[];
quadrants: any[];
bounds: {
xStart: number;
yStart: number;
xEnd: number;
yEnd: number;
};
/**
* (Re)Computes the quadtree with new graph nodes
* @param {import("../model/igraphnode").IGraphNode[]} entities
*/
initialize(entities?: import("../model/igraphnode").IGraphNode[]): void;
/**
* Recomputes the quadtree with the currently assigned nodes
*/
update(): void;
/**
* Computes the bounds of the quad tree based on the contained entities
* @returns {import("../model/ibounds").IBounds}
*/
getBounds(): import("../model/ibounds").IBounds;
/**
* The quadtree is recomputed by calling this function sequentially for each graph entity
* @param {import("../model/igraphnode").IGraphNode} entity
* @returns
*/
addEntity(entity: import("../model/igraphnode").IGraphNode): void;
/**
* Traverses the tree from top to bottom. Will execute a callback for each quadrant and leaf.
* If the callback returns a truthy value then the quadrant in question will not be drilled further down into
* @param {(quadNode?: import("../model/quadmember").QuadMember, xStart: number, yStart: number, xEnd: number, yEnd: number) => boolean} callback
* @returns
*/
traverseTopBottom(callback: (quadNode?: import("../model/quadmember").QuadMember, xStart: number, yStart: number, xEnd: number, yEnd: number) => boolean): void;
/**
* Executes a callback for each quadrant in the graph from bottom to top.
* @param {(quadNode?: import("../model/quadmember").QuadMember, xStart: number, yStart: number, xEnd: number, yEnd: number) => boolean} callback
* @returns
*/
traverseBottomTop(callback: (quadNode?: import("../model/quadmember").QuadMember, xStart: number, yStart: number, xEnd: number, yEnd: number) => boolean): void;
/**
* Computes the mass of each quadNode and aggregates entity coordinates into an average center.
* Used for example when computing Barnes and Huts n-body approximation
*/
computeMass(): void;
/**
* Records the largest radius on each quad node.
* This is useful for example in collision detection.
* We need this information because a point can stretch across multiple quadrants.
* This is a downside of an adaptive tree.
* @param {number} padding - Adds a padding to all radiuses
*/
computeLargestRadius(padding?: number): void;
}