Commit d8aaffb6 authored by S Anand's avatar S Anand

REF: G.unpack() re-uses G.network.collide

parent 82994ba7
......@@ -21,40 +21,17 @@ G.unpack = function() {
}
}
function collide(k) {
var q = d3.geom.quadtree(nodes)
return function(node) {
var nr = node.r,
nx1 = node.x - nr,
nx2 = node.x + nr,
ny1 = node.y - nr,
ny2 = node.y + nr
q.visit(function(quad, x1, y1, x2, y2) {
if (quad.point && (quad.point !== node)) {
var x = node.x - quad.point.x,
y = node.y - quad.point.y,
l = x * x + y * y,
r = nr + quad.point.r
if (l < r * r) {
l = ((l = Math.sqrt(l)) - r) / l * k
node.x -= x *= l
node.y -= y *= l
quad.point.x += x
quad.point.y += y
}
}
return x1 > nx2 || x2 < nx1 || y1 > ny2 || y2 < ny1
})
}
}
var collide = G.network.collide.circle(function(node) { return node.r })
force
.size([width, height])
.nodes(nodes)
.on('tick', function tick(e) {
update.each(gravity(e.alpha * 0.1))
.each(collide(0.5))
.attr('transform', function(d) { return 'translate(' + d.x + ',' + d.y + ')' })
var q = d3.geom.quadtree(nodes),
i = 0
while (++i < l)
q.visit(collide(nodes[i]))
update.attr('transform', function(d) { return 'translate(' + d.x + ',' + d.y + ')' })
})
.start()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment