 ((window) ->
-
   QuadTree = (I) ->
     I ||= {}
     

            
      index = TOP_LEFT
      
      if left
        if !top
          index = BOTTOM_LEFT
      else
        if top
          index = TOP_RIGHT

        return I.children    
          
      subdivide: ->
        increased_depth = I.depth + 1
    
        x_bounds = I.bounds.x
        y_bounds = I.bounds.y
        width = I.bounds.width
        height = I.bounds.height
        
        half_width = (width / 2).floor() 
        half_height = (height / 2).floor()
        x_midpoint = x_bounds + half_width
        y_midpoint = y_bounds + half_height  
        
        I.nodes[TOP_LEFT] = Node
          bounds:
            x: x_bounds
            y: y_bounds
            width: half_width
            height: half_height
          depth: increased_depth
          
        I.nodes[TOP_RIGHT] = Node
          bounds:
            x: x_midpoint
            y: y_bounds
            width: half_width
            height: half_height
          depth: increased_depth
          
        I.nodes[BOTTOM_LEFT] = Node
          bounds:
            x: x_bounds
            y: y_midpoint
            width: half_width
            height: half_height
          depth: increased_depth
          
        I.nodes[BOTTOM_RIGHT] = Node
          bounds:
            x: x_midpoint
            y: y_midpoint
            width: half_width
            height: half_height
          depth: increased_depth
    
    self
      
