title: Quadtree for 2D collision detection
body: <p>I'm trying to use a quadtree for 2D collision detection, but I'm a little stumped on how to implement it. First of all, I'd have a quadtree which contains four subtrees (one representing each quadrant), as well as a collection of objects which don't fit into a single subtree.</p>
  
  <p>When checking an object for collisions in the tree, I would do something like this (thanks to <a href="https://stackoverflow.com/questions/4434335/quadtree-for-2d-collision-detection">QuadTree for 2D collision detection</a>):</p>
  
  <ol>
  <li>Check the object for collisions with any objects in the current node.</li>
  <li>For any subtree whose space overlaps the object, recurse.</li>
  </ol>
  
  <p>To find all collisions within a quadtree tree:</p>
  
  <ol>
  <li>Check each object in the current node against each other object in the current node.</li>
  <li>Check each object in the current node against each subtree.</li>
  </ol>
  
  <p>To insert into a quadtree:</p>
  
  <ol>
  <li>If the object fits into multiple subtrees, then add it to the current node, and return.</li>
  <li>Otherwise, recurse into whichever subtree contains it.</li>
  </ol>
  
  <p>To update a quadtree:</p>
  
  <ol>
  <li>Recurse into each subtree.</li>
  <li>If any element in the current node no longer fits completely in the current tree, move it to the parent.</li>
  <li>If any element in the current node fits into a subtree, insert it into the subtree.</li>
  </ol>
  
  <p>Is this alright? Can it be improved?</p>