Add some code review comments.

This commit is contained in:
Andrew Cameron 2011-08-13 13:48:41 -04:00
parent 14aea1afe6
commit d549ac1d98

View File

@ -349,6 +349,9 @@ Layout.ForceDirected.prototype.applyCoulombsLaw = function()
if (point1 !== point2)
{
var d = point1.p.subtract(point2.p);
// Why is distance = mag + 1.0? If there's a good reason for
// it, leave a comment. Is it to keep the repulsion from being
// way too strong at small distances?
var distance = d.magnitude() + 1.0;
var direction = d.normalise();
@ -385,6 +388,8 @@ Layout.ForceDirected.prototype.attractToCentre = function()
Layout.ForceDirected.prototype.updateVelocity = function(timestep)
{
this.eachNode(function(node, point) {
// Is this, along with updatePosition below, the only places that your
// integration code exist?
point.v = point.v.add(point.f.multiply(timestep)).multiply(this.damping);
point.f = new Vector(0,0);
});
@ -393,6 +398,8 @@ Layout.ForceDirected.prototype.updateVelocity = function(timestep)
Layout.ForceDirected.prototype.updatePosition = function(timestep)
{
this.eachNode(function(node, point) {
// Same question as above; along with updateVelocity, is this all of
// your integration code?
point.p = point.p.add(point.v.multiply(timestep));
});
};
@ -402,6 +409,8 @@ Layout.ForceDirected.prototype.totalEnergy = function(timestep)
var energy = 0.0;
this.eachNode(function(node, point) {
var speed = point.v.magnitude();
// A comment might be warranted explaining why the factor of 1/2 is
// unnecessary.
energy += speed * speed;
});
@ -547,11 +556,14 @@ Layout.ForceDirected.Point = function(position, mass)
this.p = position; // position
this.m = mass; // mass
this.v = new Vector(0, 0); // velocity
// Based on the usage, the "force" member looks more like an
// "acceleration".
this.f = new Vector(0, 0); // force
};
Layout.ForceDirected.Point.prototype.applyForce = function(force)
{
// Ditto on acceleration, here: a = F/m
this.f = this.f.add(force.divide(this.m));
};