Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/physics/physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@

applyBarnesHutRepulsion:function(){
if (!_bounds.topleft || !_bounds.bottomright) return
var nParticles = 0;
for (var particle in active.particles)
nParticles++;
if (nParticles < 2) return

var bottomright = new Point(_bounds.bottomright)
var topleft = new Point(_bounds.topleft)

Expand Down Expand Up @@ -248,7 +253,7 @@
numParticles++
});

if (numParticles==0) return
if (numParticles < 2) return

var correction = centroid.divide(-numParticles)
$.each(active.particles, function(id, point) {
Expand Down Expand Up @@ -314,7 +319,8 @@
});

_energy = {sum:sum, max:max, mean:sum/n, n:n}
_bounds = {topleft:topleft||new Point(-1,-1), bottomright:bottomright||new Point(1,1)}
if (n > 1)
_bounds = {topleft:topleft||new Point(-1,-1), bottomright:bottomright||new Point(1,1)}
},

systemEnergy:function(timestep){
Expand Down