QuadTree
class QuadTree
a QuadTree implementation in JavaScript, a 2d spatial subdivision algorithm.
Constructor
new QuadTree(world: World, bounds: Bounds, max_objects: number, max_levels: number, level: number) → {}
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
world | World |
the physic world this QuadTree belongs to |
||
bounds | Bounds |
bounds of the node |
||
max_objects | number |
<optional> |
4 |
max objects a node can hold before splitting into 4 subnodes |
max_levels | number |
<optional> |
4 |
total max levels inside root Quadtree |
level | number |
<optional> |
0 |
deepth level, required for subnodes |
Summary
Methods from QuadTree
|
|
boolean |
|
|
|
|
|
boolean |
|
boolean |
|
Array<object> |
|
Public Methods
clear(bounds: Bounds) → {}
clear the quadtree
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
bounds | Bounds |
<optional> |
this.bounds |
the bounds to be cleared |
hasChildren() → {boolean}
return true if the node has any children
Type | Description |
---|---|
boolean |
true if the node has any children |
insert(item: object) → {}
Insert the given object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes.
Name | Type | Description |
---|---|---|
item | object |
object to be added |
insertContainer(container: Container) → {}
Insert the given object container into the node.
Name | Type | Description |
---|---|---|
container | Container |
group of objects to be added |
isPrunable() → {boolean}
return true if the node is prunable
Type | Description |
---|---|
boolean |
true if the node is prunable |
remove(item: object) → {boolean}
Remove the given item from the quadtree. (this function won't recalculate the impacted node)
Name | Type | Description |
---|---|---|
item | object |
object to be removed |
Type | Description |
---|---|
boolean |
true if the item was found and removed. |
retrieve(item: object, fn: object) → {Array<object>}
Return all objects that could collide with the given object
Name | Type | Attributes | Description |
---|---|---|---|
item | object |
object to be checked against |
|
fn | object |
<optional> |
a sorting function for the returned array |
Type | Description |
---|---|
Array<object> |
array with all detected objects |