From 686abaa3677216eef40681ca476da14d85bcb6c1 Mon Sep 17 00:00:00 2001 From: Dennis Hotson Date: Sat, 26 Nov 2011 13:56:10 +1100 Subject: [PATCH] Avoid divide by zero and massive forces at small distances --- springy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/springy.js b/springy.js index 314a833..6923ab6 100644 --- a/springy.js +++ b/springy.js @@ -305,7 +305,7 @@ Layout.ForceDirected.prototype.applyCoulombsLaw = function() { if (point1 !== point2) { var d = point1.p.subtract(point2.p); - var distance = d.magnitude(); + var distance = d.magnitude() + 0.1; // avoid massive forces at small distances (and divide by zero) var direction = d.normalise(); // apply force to each end point