Browse Source

Merge remote-tracking branch 'origin/v4' into v4

flowchartTest
jos 9 years ago
parent
commit
41cdb2f389
1 changed files with 27 additions and 22 deletions
  1. +27
    -22
      lib/network/modules/components/physics/BarnesHutSolver.js

+ 27
- 22
lib/network/modules/components/physics/BarnesHutSolver.js View File

@ -68,17 +68,7 @@ class BarnesHutSolver {
// original condition : s/d < theta = passed === d/s > 1/theta = passed // original condition : s/d < theta = passed === d/s > 1/theta = passed
// calcSize = 1/s --> d * 1/s > 1/theta = passed // calcSize = 1/s --> d * 1/s > 1/theta = passed
if (distance * parentBranch.calcSize > this.thetaInversed) { if (distance * parentBranch.calcSize > this.thetaInversed) {
// duplicate code to reduce function calls to speed up program
if (distance === 0) {
distance = 0.1 * Math.random();
dx = distance;
}
var gravityForce = this.options.gravitationalConstant * parentBranch.mass * node.options.mass / (distance * distance * distance);
var fx = dx * gravityForce;
var fy = dy * gravityForce;
this.physicsBody.forces[node.id].x += fx;
this.physicsBody.forces[node.id].y += fy;
this._calculateForces(distance, dx, dy, node, parentBranch);
} }
else { else {
// Did not pass the condition, go into children if available // Did not pass the condition, go into children if available
@ -90,17 +80,7 @@ class BarnesHutSolver {
} }
else { // parentBranch must have only one node, if it was empty we wouldnt be here else { // parentBranch must have only one node, if it was empty we wouldnt be here
if (parentBranch.children.data.id != node.id) { // if it is not self if (parentBranch.children.data.id != node.id) { // if it is not self
// duplicate code to reduce function calls to speed up program
if (distance === 0) {
distance = 0.5 * Math.random();
dx = distance;
}
var gravityForce = this.options.gravitationalConstant * parentBranch.mass * node.options.mass / (distance * distance * distance);
var fx = dx * gravityForce;
var fy = dy * gravityForce;
this.physicsBody.forces[node.id].x += fx;
this.physicsBody.forces[node.id].y += fy;
this._calculateForces(distance, dx, dy, node, parentBranch);
} }
} }
} }
@ -108,6 +88,31 @@ class BarnesHutSolver {
} }
/**
* Calculate the forces based on the distance.
*
* @param distance
* @param dx
* @param dy
* @param node
* @param parentBranch
* @private
*/
_calculateForces(distance, dx, dy, node, parentBranch) {
// duplicate code to reduce function calls to speed up program
if (distance === 0) {
distance = 0.1 * Math.random();
dx = distance;
}
var gravityForce = this.options.gravitationalConstant * parentBranch.mass * node.options.mass / (distance * distance * distance);
var fx = dx * gravityForce;
var fy = dy * gravityForce;
this.physicsBody.forces[node.id].x += fx;
this.physicsBody.forces[node.id].y += fy;
}
/** /**
* This function constructs the barnesHut tree recursively. It creates the root, splits it and starts placing the nodes. * This function constructs the barnesHut tree recursively. It creates the root, splits it and starts placing the nodes.
* *

Loading…
Cancel
Save