Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Network: Cleanup and refactoring PhysicsEngine #3507

Merged
merged 5 commits into from
Oct 5, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Small refactoring BarnesHutSolver
  • Loading branch information
wimrijnders committed Sep 30, 2017
commit deba1621ac687b5ae75dbcb2df67113f76347da3
32 changes: 19 additions & 13 deletions lib/network/modules/components/physics/BarnesHutSolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BarnesHutSolver {
this.randomSeed = 5;

// debug: show grid
//this.body.emitter.on("afterDrawing", (ctx) => {this._debug(ctx,'#ff0000')})
this.body.emitter.on("afterDrawing", (ctx) => {this._debug(ctx,'#ff0000')})
}

/**
Expand All @@ -25,7 +25,9 @@ class BarnesHutSolver {
setOptions(options) {
this.options = options;
this.thetaInversed = 1 / this.options.theta;
this.overlapAvoidanceFactor = 1 - Math.max(0, Math.min(1,this.options.avoidOverlap)); // if 1 then min distance = 0.5, if 0.5 then min distance = 0.5 + 0.5*node.shape.radius

// if 1 then min distance = 0.5, if 0.5 then min distance = 0.5 + 0.5*node.shape.radius
this.overlapAvoidanceFactor = 1 - Math.max(0, Math.min(1, this.options.avoidOverlap));
}

/**
Expand Down Expand Up @@ -277,22 +279,26 @@ class BarnesHutSolver {
this._updateBranchMass(parentBranch, node);
}

if (parentBranch.children.NW.range.maxX > node.x) { // in NW or SW
if (parentBranch.children.NW.range.maxY > node.y) { // in NW
this._placeInRegion(parentBranch, node, "NW");
let range = parentBranch.children.NW.range;
let region;
if (range.maxX > node.x) { // in NW or SW
if (range.maxY > node.y) {
region = "NW";
}
else { // in SW
this._placeInRegion(parentBranch, node, "SW");
else {
region = "SW";
}
}
else { // in NE or SE
if (parentBranch.children.NW.range.maxY > node.y) { // in NE
this._placeInRegion(parentBranch, node, "NE");
if (range.maxY > node.y) {
region = "NE";
}
else { // in SE
this._placeInRegion(parentBranch, node, "SE");
else {
region = "SE";
}
}

this._placeInRegion(parentBranch, node, region);
}


Expand Down Expand Up @@ -475,12 +481,12 @@ class BarnesHutSolver {
ctx.lineTo(branch.range.minX, branch.range.minY);
ctx.stroke();

/*
//*
if (branch.mass > 0) {
ctx.circle(branch.centerOfMass.x, branch.centerOfMass.y, 3*branch.mass);
ctx.stroke();
}
*/
// */
}
}

Expand Down