# new QuadTree(An, pointQuad, maxDepth, maxChildren)
A QuadTree implementation in JavaScript, a 2d spatial subdivision algorithm.
Parameters:
Name | Type | Description |
---|---|---|
An |
Object | object representing the bounds of the top level of the QuadTree. The object should contain the following properties : x, y, width, height |
pointQuad |
Boolean | Whether the QuadTree will contain points (true), or items with bounds (width / height)(false). Default value is false. |
maxDepth |
Number | The maximum number of levels that the quadtree will create. Default is 4. |
maxChildren |
Number | The maximum number of children that a node can contain before it is split into sub-nodes. |
Members
# root
The root node of the QuadTree which covers the entire area being segmented.
Properties:
Name | Type | Description |
---|---|---|
root |
Methods
# insert(item)
Inserts an item into the QuadTree.
Parameters:
Name | Type | Description |
---|---|---|
item |
Object | Array | The 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:
Name | Type | Description |
---|---|---|
item |
Object | An object representing a 2D coordinate point (with x, y properties), or a shape with dimensions (x, y, width, height) properties. |