                 node.x = xMin + node.width / 2
                 node.y = yMin + node.height / 2
 
-        q = d3.geom.quadtree(nodes)
-
-        for i in [0 .. nodes.length - 1]
-            q.visit(collide(nodes[i]))
+        for node in nodes
+            doCollisions(node.children)
+
+        doCollisions(topNodes)
 
         svg.selectAll('.cell')
             .attr('transform', (node) -> "translate(#{node.x},#{node.y})")

                parentNode = nodeMap[parent.name]
                node.parent = parentNode
                parentNode.children.push(node)

    r = 40


            .attr('y', (node) -> - node.height / 2)
            .attr('width', (node) -> node.width)
            .attr('height', (node) -> node.height)


doCollisions = (children) ->
    if children.length
        q = d3.geom.quadtree(children)
        for child in children
            q.visit(collide(child))


collide = (node) ->
