# 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:
    - QuadTree.js, line 11

### Classes

Entry

### Members

#### <static, constant> MAX_ENTRIES

  Max number of entries in a node before it splits
  Source:
    - QuadTree.js, line 32

#### <static, constant> MAX_LEVELS

  Max depth the tree will split
  Source:
    - QuadTree.js, line 38

#### entries :Array.<Entry>

  ##### Type:

  - Array.<Entry>
  Source:
    - QuadTree.js, line 25

#### nodes :Array.<QuadTree>

  ##### Type:

  - Array.<QuadTree>
  Source:
    - QuadTree.js, line 20

### Methods

#### _combine()

  Unwinds this node. Move all child nodes into this node and remove child nodes.
  Source:
    - QuadTree.js, line 282

#### _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:
    - QuadTree.js, line 115

  ##### Returns:

  Which quandrant, or -1 if won't fit.
  Type
    Number

#### _redistribute()

  Distrubute all entrys into child nodes if we can.
  Source:
    - QuadTree.js, line 188

#### _split()

  Create 4 sub nodes for the tree (does not populate tho)
  Source:
    - QuadTree.js, line 150

#### _splitAndRedistributeIfNeeded()

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

#### clear()

  Empty the tree recursively.
  Source:
    - QuadTree.js, line 260

#### 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:
    - QuadTree.js, line 81

#### popEntry(entry)

  Removes an entry from the tree (but does NOT release it back to the pool!!)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `entry` | Entry |

  Source:
    - QuadTree.js, line 246

#### pushEntry(entry)

  Add item to tree that is already packed into an entry.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `entry` | Entry |

  Source:
    - QuadTree.js, line 94

#### 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:
    - QuadTree.js, line 215

  ##### Returns:

  The out__objects parameter (filled up now)
  Type
    Array.<Entry>