QuadTree Class
QuadTree data structure. See https://github.com/mikechambers/ExamplesByMesh/tree/master/JavaScript/QuadTree
Constructor
QuadTree
-
An
-
pointQuad
-
maxDepth
-
maxChildren
Parameters:
-
An
Objectobject representing the bounds of the top level of the QuadTree. The object should contain the following properties : x, y, width, height
-
pointQuad
BooleanWhether the QuadTree will contain points (true), or items with bounds (width / height)(false). Default value is false.
-
maxDepth
NumberThe maximum number of levels that the quadtree will create. Default is 4.
-
maxChildren
NumberThe maximum number of children that a node can contain before it is split into sub-nodes.
Methods
clear
()
Clears all nodes and children from the QuadTree
insert
-
item
Inserts an item into the QuadTree.
Parameters:
-
item
Object | ArrayThe item or Array of items to be inserted into the QuadTree. The item should expose x, y properties that represents its position in 2D space.
retrieve
-
item
Retrieves all items / points in the same node as the specified item / point. If the specified item overlaps the bounds of a node, then all children in both nodes will be returned.
Parameters:
-
item
ObjectAn object representing a 2D coordinate point (with x, y properties), or a shape with dimensions (x, y, width, height) properties.
Properties
root
Node
The root node of the QuadTree which covers the entire area being segmented.