Class: QuadTree

QuadTree

new QuadTree()

Effectively store positional and sized objects. Each tree has a position and size, as well as up to 4 child nodes (other trees) and an array of entries.
Source:

Classes

Entry

Members

<static, constant> MAX_ENTRIES

Max number of entries in a node before it splits
Source:

<static, constant> MAX_LEVELS

Max depth the tree will split
Source:

entries :Array.<Entry>

Type:
  • Array.<Entry>
Source:

nodes :Array.<QuadTree>

Type:
Source:

Methods

_combine()

Unwinds this node. Move all child nodes into this node and remove child nodes.
Source:

_getIndex(position, hwidth) → {Number}

Return which of the 4 quandrants of this tree an object would go into.
Parameters:
Name Type Description
position Vec2
hwidth Vec2
Source:
Returns:
Which quandrant, or -1 if won't fit.
Type
Number

_redistribute()

Distrubute all entrys into child nodes if we can.
Source:

_split()

Create 4 sub nodes for the tree (does not populate tho)
Source:

_splitAndRedistributeIfNeeded()

If we've overpacked this tree, then split into 4 smaller trees (if we haven't already) and redistribute.
Source:

clear()

Empty the tree recursively.
Source:

insert(object, position, hwidth)

Pack an object into an entry and add it to the tree.
Parameters:
Name Type Description
object Object
position Vec2
hwidth Vec2
Source:

popEntry(entry)

Removes an entry from the tree (but does NOT release it back to the pool!!)
Parameters:
Name Type Description
entry Entry
Source:

pushEntry(entry)

Add item to tree that is already packed into an entry.
Parameters:
Name Type Description
entry Entry
Source:

querySpace(position, hwidth, out__objects) → {Array.<Entry>}

Get all tree entries that are interesected by a rectangle defined with position and hwidth.
Parameters:
Name Type Argument Description
position Vec2
hwidth Vec2
out__objects Array.<Entry>= <optional>
Return objects.
Source:
Returns:
The out__objects parameter (filled up now)
Type
Array.<Entry>