Skip to content

Commit

Permalink
jshint fixes and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Sep 15, 2014
1 parent 3e57dc8 commit 07fcb3d
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 102 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
// environments
"node" : true,
"es5" : true,
"browser" : true,

// options
Expand Down
2 changes: 1 addition & 1 deletion src/collision/ArrayCollisionMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function ArrayCollisionMatrix() {
* @type {Array}
*/
this.matrix = [];
};
}

/**
* Get an element
Expand Down
20 changes: 10 additions & 10 deletions src/collision/GridBroadphase.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = GridBroadphase;

var Broadphase = require('./Broadphase')
, Vec3 = require('../math/Vec3')
, Shape = require('../shapes/Shape')
var Broadphase = require('./Broadphase');
var Vec3 = require('../math/Vec3');
var Shape = require('../shapes/Shape');

/**
* Axis aligned uniform grid broadphase.
Expand Down Expand Up @@ -35,7 +35,7 @@ function GridBroadphase(aabbMin,aabbMax,nx,ny,nz){
this.bins[i]=[];
this.binLengths[i]=0;
}
};
}
GridBroadphase.prototype = new Broadphase();
GridBroadphase.prototype.constructor = GridBroadphase;

Expand Down Expand Up @@ -107,12 +107,12 @@ GridBroadphase.prototype.collisionPairs = function(world,pairs1,pairs2){
yoff1 = ceil((y1 - ymin) * ymult),
zoff1 = ceil((z1 - zmin) * zmult);

if (xoff0 < 0) xoff0 = 0; else if (xoff0 >= nx) xoff0 = nx - 1;
if (yoff0 < 0) yoff0 = 0; else if (yoff0 >= ny) yoff0 = ny - 1;
if (zoff0 < 0) zoff0 = 0; else if (zoff0 >= nz) zoff0 = nz - 1;
if (xoff1 < 0) xoff1 = 0; else if (xoff1 >= nx) xoff1 = nx - 1;
if (yoff1 < 0) yoff1 = 0; else if (yoff1 >= ny) yoff1 = ny - 1;
if (zoff1 < 0) zoff1 = 0; else if (zoff1 >= nz) zoff1 = nz - 1;
if (xoff0 < 0) { xoff0 = 0; } else if (xoff0 >= nx) { xoff0 = nx - 1; }
if (yoff0 < 0) { yoff0 = 0; } else if (yoff0 >= ny) { yoff0 = ny - 1; }
if (zoff0 < 0) { zoff0 = 0; } else if (zoff0 >= nz) { zoff0 = nz - 1; }
if (xoff1 < 0) { xoff1 = 0; } else if (xoff1 >= nx) { xoff1 = nx - 1; }
if (yoff1 < 0) { yoff1 = 0; } else if (yoff1 >= ny) { yoff1 = ny - 1; }
if (zoff1 < 0) { zoff1 = 0; } else if (zoff1 >= nz) { zoff1 = nz - 1; }

xoff0 *= xstep;
yoff0 *= ystep;
Expand Down
2 changes: 1 addition & 1 deletion src/collision/ObjectCollisionMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function ObjectCollisionMatrix() {
* @type {Object}
*/
this.matrix = {};
};
}

/**
* @method get
Expand Down
4 changes: 2 additions & 2 deletions src/collision/SAPBroadphase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Shape = require('../shapes/Shape')
, Broadphase = require('../collision/Broadphase')
var Shape = require('../shapes/Shape');
var Broadphase = require('../collision/Broadphase');

module.exports = SAPBroadphase;

Expand Down
20 changes: 13 additions & 7 deletions src/equations/ContactEquation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = ContactEquation;

var Equation = require('./Equation')
, Vec3 = require('../math/Vec3')
, Mat3 = require('../math/Mat3')
var Equation = require('./Equation');
var Vec3 = require('../math/Vec3');
var Mat3 = require('../math/Mat3');

/**
* Contact/non-penetration constraint equation
Expand Down Expand Up @@ -116,10 +116,16 @@ ContactEquation.prototype.computeB = function(h){

var invIi_vmult_taui = ContactEquation_computeB_temp1;
var invIj_vmult_tauj = ContactEquation_computeB_temp2;
if(bi.invInertiaWorld) bi.invInertiaWorld.vmult(taui,invIi_vmult_taui);
else invIi_vmult_taui.set(0,0,0);
if(bj.invInertiaWorld) bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj);
else invIj_vmult_tauj.set(0,0,0);
if(bi.invInertiaWorld){
bi.invInertiaWorld.vmult(taui,invIi_vmult_taui);
} else {
invIi_vmult_taui.set(0,0,0);
}
if(bj.invInertiaWorld){
bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj);
} else {
invIj_vmult_tauj.set(0,0,0);
}

// Compute iteration
var ePlusOne = this.restitution+1;
Expand Down
20 changes: 10 additions & 10 deletions src/equations/FrictionEquation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = FrictionEquation;

var Equation = require('./Equation')
, Vec3 = require('../math/Vec3')
, Mat3 = require('../math/Mat3')
var Equation = require('./Equation');
var Vec3 = require('../math/Vec3');
var Mat3 = require('../math/Mat3');

/**
* Constrains the slipping in a contact along a tangent
Expand Down Expand Up @@ -35,7 +35,7 @@ function FrictionEquation(bi,bj,slipForce){

this.biInvInertiaTimesRixt = new Vec3();
this.bjInvInertiaTimesRjxt = new Vec3();
};
}

FrictionEquation.prototype = new Equation();
FrictionEquation.prototype.constructor = FrictionEquation;
Expand Down Expand Up @@ -90,18 +90,18 @@ FrictionEquation.prototype.computeB = function(h){
// And remember, this is a pure velocity constraint, g is always zero!
var GA = this.jacobianElementA,
GB = this.jacobianElementB;
t.negate(GA.spatial)
t.negate(GA.spatial);
rixt.negate(GA.rotational);
GB.spatial.copy(t);
GB.rotational.copy(rjxt);

if(bi.invInertiaWorld) bi.invInertiaWorld.vmult(taui,invIi_vmult_taui);
else invIi_vmult_taui.set(0,0,0);
if(bj.invInertiaWorld) bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj);
else invIj_vmult_tauj.set(0,0,0);
if(bi.invInertiaWorld){ bi.invInertiaWorld.vmult(taui,invIi_vmult_taui); }
else { invIi_vmult_taui.set(0,0,0); }
if(bj.invInertiaWorld){ bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj); }
else { invIj_vmult_tauj.set(0,0,0); }

var GW = this.computeGW();//vj.dot(t) - vi.dot(t) + wjxrj.dot(t) - wixri.dot(t), // eq. 40
GiMf = this.computeGiMf();//fj.dot(t)*invMassj - fi.dot(t)*invMassi + rjxt.dot(invIj_vmult_tauj) - rixt.dot(invIi_vmult_taui);
var GiMf = this.computeGiMf();//fj.dot(t)*invMassj - fi.dot(t)*invMassi + rjxt.dot(invIj_vmult_tauj) - rixt.dot(invIi_vmult_taui);

// we do only want to constrain velocity, so g=0
var B = - GW * b - h*GiMf;
Expand Down
8 changes: 4 additions & 4 deletions src/equations/RotationalEquation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = RotationalEquation;

var Vec3 = require('../math/Vec3')
, Mat3 = require('../math/Mat3')
, Equation = require('./Equation')
var Vec3 = require('../math/Vec3');
var Mat3 = require('../math/Mat3');
var Equation = require('./Equation');

/**
* Rotational constraint. Works to keep the local vectors orthogonal to each other.
Expand All @@ -28,7 +28,7 @@ function RotationalEquation(bodyA, bodyB){

this.relVel = new Vec3();
this.relForce = new Vec3();
};
}

RotationalEquation.prototype = new Equation();
RotationalEquation.prototype.constructor = RotationalEquation;
Expand Down
2 changes: 1 addition & 1 deletion src/material/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ function Material(name){
*/
this.name = name;
this.id = Material.idCounter++;
};
}

Material.idCounter = 0;
2 changes: 1 addition & 1 deletion src/math/JacobianElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function JacobianElement(){
* @property {Vec3} rotational
*/
this.rotational = new Vec3();
};
}

/**
* Multiply with other JacobianElement
Expand Down
4 changes: 2 additions & 2 deletions src/math/Mat3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = Mat3;

var Vec3 = require('./Vec3')
var Vec3 = require('./Vec3');

/**
* A 3x3 matrix.
Expand All @@ -19,7 +19,7 @@ function Mat3(elements){
} else {
this.elements = [0,0,0,0,0,0,0,0,0];
}
};
}

/**
* Sets the matrix to identity
Expand Down
4 changes: 2 additions & 2 deletions src/math/Quaternion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = Quaternion;

var Vec3 = require('./Vec3')
var Vec3 = require('./Vec3');

/**
* A Quaternion describes a rotation in 3D space. The Quaternion is mathematically defined as Q = x*i + y*j + z*k + w, where (i,j,k) are imaginary basis vectors. (x,y,z) can be seen as a vector related to the axis of rotation, while the real multiplier, w, is related to the amount of rotation.
Expand Down Expand Up @@ -33,7 +33,7 @@ function Quaternion(x,y,z,w){
* @property {Number} w
*/
this.w = w!==undefined ? w : 1;
};
}

/**
* Set the value of the quaternion.
Expand Down
14 changes: 13 additions & 1 deletion src/objects/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ var Box = require('../shapes/Box');
* @class Body
* @constructor
* @extends EventTarget
* @param {object} [options]
* @param {Vec3} [options.position]
* @param {number} [options.mass]
* @param {number} [options.type]
* @param {number} [options.linearDamping]
* @example
* var body = new Body({
* mass: 1
* });
* var shape = new Sphere(1);
* body.addShape(shape);
* world.add(body);
*/
function Body(options){
options = options || {};
Expand Down Expand Up @@ -543,7 +555,7 @@ var uiw_m1 = new Mat3(),
*/
Body.prototype.updateInertiaWorld = function(force){
var I = this.invInertia;
if (I.x == I.y && I.y == I.z && !force) {
if (I.x === I.y && I.y === I.z && !force) {
// If inertia M = s*I, where I is identity and s a scalar, then
// R*M*R' = R*(s*I)*R' = s*R*I*R' = s*R*R' = s*I = M
// where R is the rotation matrix.
Expand Down
2 changes: 1 addition & 1 deletion src/objects/SPHSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ SPHSystem.prototype.update = function(){
Pij = -neighbor.mass * (this.pressures[i] / (this.densities[i]*this.densities[i] + eps) + this.pressures[j] / (this.densities[j]*this.densities[j] + eps));
this.gradw(r_vec, gradW);
// Add to pressure acceleration
gradW.mult(Pij , gradW)
gradW.mult(Pij , gradW);
a_pressure.vadd(gradW, a_pressure);

// Viscosity contribution
Expand Down
36 changes: 20 additions & 16 deletions src/objects/Spring.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module.exports = Spring;
* @param {Body} bodyA
* @param {Body} bodyB
* @param {Object} [options]
* @param {number} options.restLength A number > 0. Default: 1
* @param {number} options.stiffness A number >= 0. Default: 100
* @param {number} options.damping A number >= 0. Default: 1
* @param {Array} options.worldAnchorA Where to hook the spring to body A, in world coordinates.
* @param {Array} options.worldAnchorB
* @param {Array} options.localAnchorA Where to hook the spring to body A, in local body coordinates.
* @param {Array} options.localAnchorB
* @param {number} [options.restLength] A number > 0. Default: 1
* @param {number} [options.stiffness] A number >= 0. Default: 100
* @param {number} [options.damping] A number >= 0. Default: 1
* @param {Vec3} [options.worldAnchorA] Where to hook the spring to body A, in world coordinates.
* @param {Vec3} [options.worldAnchorB]
* @param {Vec3} [options.localAnchorA] Where to hook the spring to body A, in local body coordinates.
* @param {Vec3} [options.localAnchorB]
*/
function Spring(bodyA,bodyB,options){
options = options || {};
Expand Down Expand Up @@ -70,15 +70,19 @@ function Spring(bodyA,bodyB,options){
*/
this.localAnchorB = new Vec3();

if(options.localAnchorA) this.localAnchorA.set( options.localAnchorA.x,
options.localAnchorA.y,
options.localAnchorA.z);
if(options.localAnchorB) this.localAnchorB.set( options.localAnchorB.x,
options.localAnchorB.y,
options.localAnchorB.z);
if(options.worldAnchorA) this.setWorldAnchorA(options.worldAnchorA);
if(options.worldAnchorB) this.setWorldAnchorB(options.worldAnchorB);
};
if(options.localAnchorA){
this.localAnchorA.copy(options.localAnchorA);
}
if(options.localAnchorB){
this.localAnchorB.copy(options.localAnchorB.x);
}
if(options.worldAnchorA){
this.setWorldAnchorA(options.worldAnchorA);
}
if(options.worldAnchorB){
this.setWorldAnchorB(options.worldAnchorB);
}
}

/**
* Set the anchor point on body A, using world coordinates.
Expand Down
8 changes: 4 additions & 4 deletions src/shapes/Box.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = Box;

var Shape = require('./Shape')
, Vec3 = require('../math/Vec3')
, ConvexPolyhedron = require('./ConvexPolyhedron')
var Shape = require('./Shape');
var Vec3 = require('../math/Vec3');
var ConvexPolyhedron = require('./ConvexPolyhedron');

/**
* A 3d box shape.
Expand Down Expand Up @@ -32,7 +32,7 @@ function Box(halfExtents){

this.updateConvexPolyhedronRepresentation();
this.updateBoundingSphereRadius();
};
}
Box.prototype = new Shape();
Box.prototype.constructor = Box;

Expand Down
13 changes: 7 additions & 6 deletions src/shapes/ConvexPolyhedron.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = ConvexPolyhedron;

var Shape = require('./Shape')
, Vec3 = require('../math/Vec3')
, Quaternion = require('../math/Quaternion')
, Transform = require('../math/Transform')
var Shape = require('./Shape');
var Vec3 = require('../math/Vec3');
var Quaternion = require('../math/Quaternion');
var Transform = require('../math/Transform');

/**
* A set of polygons describing a convex shape.
Expand Down Expand Up @@ -147,7 +147,7 @@ ConvexPolyhedron.prototype.computeNormals = function(){
this.faceNormals[i] = n;
var vertex = this.vertices[this.faces[i][0]];
if(n.dot(vertex) < 0){
throw new Error(".faceNormals[" + i + "] = Vec3("+n.toString()+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");
console.error(".faceNormals[" + i + "] = Vec3("+n.toString()+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");
for(var j=0; j<this.faces[i].length; j++){
console.warn(".vertices["+this.faces[i][j]+"] = Vec3("+this.vertices[this.faces[i][j]].toString()+")");
}
Expand Down Expand Up @@ -592,8 +592,9 @@ ConvexPolyhedron.prototype.clipFaceAgainstPlane = function(inVertices,outVertice
var n_dot_first, n_dot_last;
var numVerts = inVertices.length;

if(numVerts < 2)
if(numVerts < 2){
return outVertices;
}

var firstVertex = inVertices[inVertices.length-1],
lastVertex = inVertices[0];
Expand Down
8 changes: 4 additions & 4 deletions src/shapes/Shape.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = Shape;

var Shape = require('./Shape')
, Vec3 = require('../math/Vec3')
, Quaternion = require('../math/Quaternion')
, Material = require('../material/Material')
var Shape = require('./Shape');
var Vec3 = require('../math/Vec3');
var Quaternion = require('../math/Quaternion');
var Material = require('../material/Material');

/**
* Base class for shapes
Expand Down
6 changes: 3 additions & 3 deletions src/shapes/Sphere.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = Sphere;

var Shape = require('./Shape')
, Vec3 = require('../math/Vec3')
var Shape = require('./Shape');
var Vec3 = require('../math/Vec3');

/**
* Spherical shape
Expand All @@ -21,7 +21,7 @@ function Sphere(radius){
this.type = Shape.types.SPHERE;

this.updateBoundingSphereRadius();
};
}
Sphere.prototype = new Shape();
Sphere.prototype.constructor = Sphere;

Expand Down

0 comments on commit 07fcb3d

Please sign in to comment.