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

Conversation

wimrijnders
Copy link
Contributor

Some work done in preparation for #3468, while examining the code for better understanding. The logic remains unchanged.

Note that this does not solve #3468, it's just a preliminary cleanup.

this.body.emitter.on("_dataChanged", () => {
// update shortcut lists
// Nodes an/or edges have been added or removed, update shortcut lists.
Copy link
Contributor

@yotamberk yotamberk Oct 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an/or => and/or

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Can you hold off merging until @mbroad has reviewed, please?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, that's exactly why I waited

Copy link

@mbroad mbroad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing looks wrong to me, but I'd have a lot more confidence in the refactoring if unit tests came first, and then refactoring was done, with unit tests still passing.

this.updatePhysicsData();
});

// debug: show forces
// this.body.emitter.on("afterDrawing", (ctx) => {this._drawForces(ctx);});
//this.body.emitter.on("afterDrawing", (ctx) => {this._drawForces(ctx);});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove space after comment indicator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason whatsoever. My fingers were probably thinking for me. I actually prefer the space.
Ah yes, I enabled that to test the call, then I added the //'s back again.

* @param {Node} node
* @private
*/
_getForceContributions(parentBranch, node) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A function beginning with _get that has no return value...
Now I know this isn't your fault, as you're being consistent with _getForceContribution, but this seems wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Well, there is a force contribution to be gotten, only it's not returned but added to param parentBranch. I can't think of any better names right now.

@wimrijnders
Copy link
Contributor Author

Yeah, tough one to unit test on, because everything should remain as is. I consider the examples in the unit tests running to be a good indication of fitness - actually all tests that run physics.

I did a visual check by running worldldCupPerformance.html with develop and this PR side by side.

OK, sooooo....think about a possible unit test here. The premise is physics unchanged: so how about setting a given seed and checking after a fixed number of iterations if the output is identical to previous?

The drawback I see to that idea is that it's most likely a single-shot test. If anything changes in physics, you can throw the test away.

@mbroad
Copy link

mbroad commented Oct 1, 2017

I just meant testing the inputs, outputs, and side effects of individual functions in isolation.

@wimrijnders
Copy link
Contributor Author

Actually, I think a full test is easier to do at this point. This would be an indication that the whole physics thing works as before.

@wimrijnders
Copy link
Contributor Author

It's actually quite instructive to enable the debug routine for BarnesHutSolver. It gives a visual indication of what is actually happening:

download

download 1

Apparently, the optimization here is to subdivide the area and deal with the forces in each area separately. I can sort of intuit that this works.

@yotamberk yotamberk merged commit ecdb59e into almende:develop Oct 5, 2017
@wimrijnders wimrijnders deleted the refactorPhysics branch October 5, 2017 08:39
primozs pushed a commit to primozs/vis that referenced this pull request Jan 3, 2019
* Initial refactoring

* Small refactoring BarnesHutSolver

* Disabled debug routine, empty lines removed

* Put back space in comment

* Typo
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants