A quadtree structure
nodes: Quadtree[]
versionsForObject: Map<GameObj,
[
number, number, number
]
>
True if this node is a leaf node.
Splits the node, but doesn't redistribute objects
Tries to merge and collapse nodes which are no longer overpopulated.
getQuadrant(rect: Rect ): FirstLiteralToken | FirstLiteralToken | FirstLiteralToken | PrefixUnaryExpression | FirstLiteralToken
Returns the quadrant this rect fits in or -1 if it doesn't fit any quadrant
paramrect- The rect to test with.
returnsThe index of the quadrant fitting the rect completely, or -1 if none.
Returns the quadrants this rect intersects
paramrect- The rect to test with. Note that this rect is assumed to be within the node.
returnsthe list of quadrant indices
insert(obj: GameObj , bbox: Rect ): void
Inserts the object with the given rectangle
paramobj- The object to add
parambbox- The bounding box of the object
add(obj: GameObj ): void
Add the object
paramobj- The object to add
retrieve(rect: Rect , retrieveCb: (obj: GameObj )=>void ): void
Retrieves all objects potentially intersecting the rectangle
paramrect- The rect to test with
returnsA set of objects potentially intersecting the rectangle
remove(obj: GameObj , fast?: boolean ): boolean
Removes the object
paramobj- The object to remove
paramfast- No node collapse if true
updateObject(root: Quadtree , obj: GameObj , bbox: Rect ): void
Updates a single object
Note that no testing is done here. Make sure the object needs to be actually updated.
paramroot- The tree root, since insertion happens from the root
paramobj- The object to update
parambbox- The new bounding box
isOutside(bbox: Rect ): boolean
True if the rectangle is completely outside this node's bounds
parambbox- The bounding box to test
isInside(bbox: Rect ): boolean
True if the rectangle is completely outside this node's bounds
parambbox- The bounding box to test
updateNode(orphans:
[
GameObj, Rect
]
[] ): void
Updates all objects in this node and the objects of its children
paramorphans- The tree root, since insertion happens from the root
Update this tree
Clears this node and collapses it
gatherPairs(ancestorObjects: Array , pairCb: (obj1: GameObj , obj2: GameObj )=>void ): void
Gathers all collision pairs in this node and child nodes
paramancestorObjects- Objects in one of the node's ancestors
parampairCb- The pairs being gathered
iterPairs(pairCb: (obj1: GameObj , obj2: GameObj )=>void ): void