Create a CanvasQuadtree which references canvas.dimensions.rect. We pass an empty object to the parent, then override _bounds.
Optional
options: object = {}Additional options passed to the parent Quadtree.
The depth of this node within the root Quadtree
The maximum number of levels that the base quadtree is allowed
The maximum number of objects allowed within this node before it must split
Children of this node
The objects contained at this level of the tree
The root Quadtree
Protected
_boundsBounding rectangle of the quadtree.
Static
INDICESA constant that enumerates the index order of the quadtree nodes from top-left to bottom-right.
Return an array of all the objects in the Quadtree (recursive)
The bounding rectangle of the region
The height of the bounding rectangle
The width of the bounding rectangle
The x-coordinate of the bounding rectangle
The y-coordinate of the bounding rectangle
Identify all nodes which are adjacent to this one within the parent Quadtree.
Obtain the child nodes within the current node which a rectangle belongs to. Note that this function is not recursive, it only returns nodes at the current or child level.
The target rectangle.
The Quadtree nodes to which the target rectangle belongs
Obtain the leaf nodes to which a target rectangle belongs. This traverses the quadtree recursively obtaining the final nodes which have no children.
The target rectangle.
The Quadtree nodes to which the target rectangle belongs
Get all the objects which could collide with the provided rectangle
The normalized target rectangle
Optional
options: { _s?: Set<any>; collisionTest?: Function } = {}Options affecting the collision test.
Optional
_s?: Set<any>The existing result set, for internal use.
Optional
collisionTest?: FunctionFunction to further refine objects to return after a potential collision is found. Parameters are the object and rect, and the function should return true if the object should be added to the result set.
The objects in the Quadtree which represent potential collisions
Add a rectangle object to the tree
The object being inserted
The Quadtree nodes the object was added to.
Remove an object from the quadtree
The quadtree target being removed
The Quadtree for method chaining
Re-dimension the bounding rectangle of this Quadtree, clear existing data, and re-insert all objects. Useful if the underlying canvas or region is resized.
The new width of the bounding rectangle
The new height of the bounding rectangle
This Quadtree for method chaining
Re-position the bounding rectangle of this Quadtree, clear existing data, and re-insert all objects. Useful if the Quadtree needs to move.
The new x-coordinate of the bounding rectangle
The new y-coordinate of the bounding rectangle
This Quadtree for method chaining
Remove an existing object from the quadtree and re-insert it with a new position
The object being inserted
The Quadtree nodes the object was added to
Visualize the nodes and objects in the quadtree
Optional
objects: boolean = {}Visualize the rectangular bounds of objects in the Quadtree. Default is false.
A subclass of Quadtree specifically intended for classifying the location of objects on the game canvas.