Quadtree
:A quadtree structure
bounds
: RectmaxObjects
: numbermaxLevels
: numberlevel
: numbernodes
: Quadtree[]objects
: GameObj<AreaComp>[]isLeaf
(): booleanTrue if this node is a leaf node.
subdivide
() => voidSplits the node, but doesn't redistribute objects
merge
() => voidTries to merge and collapse nodes which are no longer overpopulated.
getQuadrant
(rect: Rect) =>Returns the quadrant this rect fits in or -1 if it doesn't fit any quadrant
param rect- The rect to test with.
returns The index of the quadrant fitting the rect completely, or -1 if none.
getQuadrants
(rect: Rect) => number[]Returns the quadrants this rect intersects
param rect- The rect to test with. Note that this rect is assumed to be within the node.
returns the list of quadrant indices
insert
(obj: GameObj<AreaComp>, bbox: Rect) => voidInserts the object with the given rectangle
param obj- The object to add
param bbox- The bounding box of the object
add
(obj: GameObj<AreaComp>) => voidAdd the object
param obj- The object to add
retrieve
(rect: Rect, objects: GameObj<AreaComp>[]) => voidRetrieves all objects potentially intersecting the rectangle
param rect- The rect to test with
returns A set of objects potentially intersecting the rectangle
remove
(obj: GameObj<AreaComp>, fast?: boolean) => booleanRemoves the object
param obj- The object to remove
param fast- No node collapse if true
updateObject
(root: Quadtree, obj: GameObj<AreaComp>, bbox: Rect) => voidUpdates a single object Note that no testing is done here. Make sure the object needs to be actually updated.
param root- The tree root, since insertion happens from the root
param obj- The object to update
param bbox- The new bounding box
isOutside
(bbox: Rect) => booleanTrue if the rectangle is completely outside this node's bounds
param bbox- The bounding box to test
isInside
(bbox: Rect) => booleanTrue if the rectangle is completely outside this node's bounds
param bbox- The bounding box to test
updateNode
(orphans: [GameObj<AreaComp>, Rect][]) => voidUpdates all objects in this node and the objects of its children
param orphans- The tree root, since insertion happens from the root
update
() => voidUpdate this tree
clear
() => voidClears this node and collapses it
gatherPairs
(ancestorObjects: Array<GameObj<AreaComp>>, pairCb: (obj1: GameObj<AreaComp>, obj2: GameObj<AreaComp>) => void) => voidGathers all collision pairs in this node and child nodes
param ancestorObjects- Objects in one of the node's ancestors
param pairCb- The pairs being gathered