summaryrefslogtreecommitdiff
path: root/collision.js
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-05-21 15:13:16 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-05-21 15:13:16 +0200
commit0334aa5e0051b59ce4050fd306b26119466e2991 (patch)
tree656de6f8ab686b3340abdd4dd86d196048d47ff3 /collision.js
parent0d2a9c9fd6c16ced9c684354690cc62dfd3d58f0 (diff)
downloadd3viz-0334aa5e0051b59ce4050fd306b26119466e2991.tar.gz
Move scripts to subdir
Our scripts end up in js/, third-party libraries end up in lib/.
Diffstat (limited to 'collision.js')
-rw-r--r--collision.js36
1 files changed, 0 insertions, 36 deletions
diff --git a/collision.js b/collision.js
deleted file mode 100644
index acaf728..0000000
--- a/collision.js
+++ /dev/null
@@ -1,36 +0,0 @@
-/* globals d3 */
-'use strict';
-// source: http://mbostock.github.io/d3/talk/20111018/collision.html
-function collisionTick(nodes) {
- var q = d3.geom.quadtree(nodes),
- i = 0,
- n = nodes.length;
-
- while (++i < n) {
- q.visit(collide(nodes[i]));
- }
-}
-
-function collide(node) {
- var r = node.radius + 16,
- nx1 = node.x - r,
- nx2 = node.x + r,
- ny1 = node.y - r,
- ny2 = node.y + r;
- return 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 = Math.sqrt(x * x + y * y),
- r = node.radius + quad.point.radius;
- if (l < r) {
- l = (l - r) / l * 0.5;
- 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;
- };
-}