Skip to content

Commit 07fcb3d

Browse files
committed
jshint fixes and docs
1 parent 3e57dc8 commit 07fcb3d

26 files changed

+131
-102
lines changed

.jshintrc

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
// environments
33
"node" : true,
4-
"es5" : true,
54
"browser" : true,
65

76
// options

src/collision/ArrayCollisionMatrix.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function ArrayCollisionMatrix() {
1313
* @type {Array}
1414
*/
1515
this.matrix = [];
16-
};
16+
}
1717

1818
/**
1919
* Get an element

src/collision/GridBroadphase.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = GridBroadphase;
22

3-
var Broadphase = require('./Broadphase')
4-
, Vec3 = require('../math/Vec3')
5-
, Shape = require('../shapes/Shape')
3+
var Broadphase = require('./Broadphase');
4+
var Vec3 = require('../math/Vec3');
5+
var Shape = require('../shapes/Shape');
66

77
/**
88
* Axis aligned uniform grid broadphase.
@@ -35,7 +35,7 @@ function GridBroadphase(aabbMin,aabbMax,nx,ny,nz){
3535
this.bins[i]=[];
3636
this.binLengths[i]=0;
3737
}
38-
};
38+
}
3939
GridBroadphase.prototype = new Broadphase();
4040
GridBroadphase.prototype.constructor = GridBroadphase;
4141

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

110-
if (xoff0 < 0) xoff0 = 0; else if (xoff0 >= nx) xoff0 = nx - 1;
111-
if (yoff0 < 0) yoff0 = 0; else if (yoff0 >= ny) yoff0 = ny - 1;
112-
if (zoff0 < 0) zoff0 = 0; else if (zoff0 >= nz) zoff0 = nz - 1;
113-
if (xoff1 < 0) xoff1 = 0; else if (xoff1 >= nx) xoff1 = nx - 1;
114-
if (yoff1 < 0) yoff1 = 0; else if (yoff1 >= ny) yoff1 = ny - 1;
115-
if (zoff1 < 0) zoff1 = 0; else if (zoff1 >= nz) zoff1 = nz - 1;
110+
if (xoff0 < 0) { xoff0 = 0; } else if (xoff0 >= nx) { xoff0 = nx - 1; }
111+
if (yoff0 < 0) { yoff0 = 0; } else if (yoff0 >= ny) { yoff0 = ny - 1; }
112+
if (zoff0 < 0) { zoff0 = 0; } else if (zoff0 >= nz) { zoff0 = nz - 1; }
113+
if (xoff1 < 0) { xoff1 = 0; } else if (xoff1 >= nx) { xoff1 = nx - 1; }
114+
if (yoff1 < 0) { yoff1 = 0; } else if (yoff1 >= ny) { yoff1 = ny - 1; }
115+
if (zoff1 < 0) { zoff1 = 0; } else if (zoff1 >= nz) { zoff1 = nz - 1; }
116116

117117
xoff0 *= xstep;
118118
yoff0 *= ystep;

src/collision/ObjectCollisionMatrix.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function ObjectCollisionMatrix() {
1313
* @type {Object}
1414
*/
1515
this.matrix = {};
16-
};
16+
}
1717

1818
/**
1919
* @method get

src/collision/SAPBroadphase.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var Shape = require('../shapes/Shape')
2-
, Broadphase = require('../collision/Broadphase')
1+
var Shape = require('../shapes/Shape');
2+
var Broadphase = require('../collision/Broadphase');
33

44
module.exports = SAPBroadphase;
55

src/equations/ContactEquation.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = ContactEquation;
22

3-
var Equation = require('./Equation')
4-
, Vec3 = require('../math/Vec3')
5-
, Mat3 = require('../math/Mat3')
3+
var Equation = require('./Equation');
4+
var Vec3 = require('../math/Vec3');
5+
var Mat3 = require('../math/Mat3');
66

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

117117
var invIi_vmult_taui = ContactEquation_computeB_temp1;
118118
var invIj_vmult_tauj = ContactEquation_computeB_temp2;
119-
if(bi.invInertiaWorld) bi.invInertiaWorld.vmult(taui,invIi_vmult_taui);
120-
else invIi_vmult_taui.set(0,0,0);
121-
if(bj.invInertiaWorld) bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj);
122-
else invIj_vmult_tauj.set(0,0,0);
119+
if(bi.invInertiaWorld){
120+
bi.invInertiaWorld.vmult(taui,invIi_vmult_taui);
121+
} else {
122+
invIi_vmult_taui.set(0,0,0);
123+
}
124+
if(bj.invInertiaWorld){
125+
bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj);
126+
} else {
127+
invIj_vmult_tauj.set(0,0,0);
128+
}
123129

124130
// Compute iteration
125131
var ePlusOne = this.restitution+1;

src/equations/FrictionEquation.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = FrictionEquation;
22

3-
var Equation = require('./Equation')
4-
, Vec3 = require('../math/Vec3')
5-
, Mat3 = require('../math/Mat3')
3+
var Equation = require('./Equation');
4+
var Vec3 = require('../math/Vec3');
5+
var Mat3 = require('../math/Mat3');
66

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

3636
this.biInvInertiaTimesRixt = new Vec3();
3737
this.bjInvInertiaTimesRjxt = new Vec3();
38-
};
38+
}
3939

4040
FrictionEquation.prototype = new Equation();
4141
FrictionEquation.prototype.constructor = FrictionEquation;
@@ -90,18 +90,18 @@ FrictionEquation.prototype.computeB = function(h){
9090
// And remember, this is a pure velocity constraint, g is always zero!
9191
var GA = this.jacobianElementA,
9292
GB = this.jacobianElementB;
93-
t.negate(GA.spatial)
93+
t.negate(GA.spatial);
9494
rixt.negate(GA.rotational);
9595
GB.spatial.copy(t);
9696
GB.rotational.copy(rjxt);
9797

98-
if(bi.invInertiaWorld) bi.invInertiaWorld.vmult(taui,invIi_vmult_taui);
99-
else invIi_vmult_taui.set(0,0,0);
100-
if(bj.invInertiaWorld) bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj);
101-
else invIj_vmult_tauj.set(0,0,0);
98+
if(bi.invInertiaWorld){ bi.invInertiaWorld.vmult(taui,invIi_vmult_taui); }
99+
else { invIi_vmult_taui.set(0,0,0); }
100+
if(bj.invInertiaWorld){ bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj); }
101+
else { invIj_vmult_tauj.set(0,0,0); }
102102

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

106106
// we do only want to constrain velocity, so g=0
107107
var B = - GW * b - h*GiMf;

src/equations/RotationalEquation.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = RotationalEquation;
22

3-
var Vec3 = require('../math/Vec3')
4-
, Mat3 = require('../math/Mat3')
5-
, Equation = require('./Equation')
3+
var Vec3 = require('../math/Vec3');
4+
var Mat3 = require('../math/Mat3');
5+
var Equation = require('./Equation');
66

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

2929
this.relVel = new Vec3();
3030
this.relForce = new Vec3();
31-
};
31+
}
3232

3333
RotationalEquation.prototype = new Equation();
3434
RotationalEquation.prototype.constructor = RotationalEquation;

src/material/Material.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ function Material(name){
1414
*/
1515
this.name = name;
1616
this.id = Material.idCounter++;
17-
};
17+
}
1818

1919
Material.idCounter = 0;

src/math/JacobianElement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function JacobianElement(){
1818
* @property {Vec3} rotational
1919
*/
2020
this.rotational = new Vec3();
21-
};
21+
}
2222

2323
/**
2424
* Multiply with other JacobianElement

src/math/Mat3.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = Mat3;
22

3-
var Vec3 = require('./Vec3')
3+
var Vec3 = require('./Vec3');
44

55
/**
66
* A 3x3 matrix.
@@ -19,7 +19,7 @@ function Mat3(elements){
1919
} else {
2020
this.elements = [0,0,0,0,0,0,0,0,0];
2121
}
22-
};
22+
}
2323

2424
/**
2525
* Sets the matrix to identity

src/math/Quaternion.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = Quaternion;
22

3-
var Vec3 = require('./Vec3')
3+
var Vec3 = require('./Vec3');
44

55
/**
66
* 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.
@@ -33,7 +33,7 @@ function Quaternion(x,y,z,w){
3333
* @property {Number} w
3434
*/
3535
this.w = w!==undefined ? w : 1;
36-
};
36+
}
3737

3838
/**
3939
* Set the value of the quaternion.

src/objects/Body.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ var Box = require('../shapes/Box');
1414
* @class Body
1515
* @constructor
1616
* @extends EventTarget
17+
* @param {object} [options]
18+
* @param {Vec3} [options.position]
19+
* @param {number} [options.mass]
20+
* @param {number} [options.type]
21+
* @param {number} [options.linearDamping]
22+
* @example
23+
* var body = new Body({
24+
* mass: 1
25+
* });
26+
* var shape = new Sphere(1);
27+
* body.addShape(shape);
28+
* world.add(body);
1729
*/
1830
function Body(options){
1931
options = options || {};
@@ -543,7 +555,7 @@ var uiw_m1 = new Mat3(),
543555
*/
544556
Body.prototype.updateInertiaWorld = function(force){
545557
var I = this.invInertia;
546-
if (I.x == I.y && I.y == I.z && !force) {
558+
if (I.x === I.y && I.y === I.z && !force) {
547559
// If inertia M = s*I, where I is identity and s a scalar, then
548560
// R*M*R' = R*(s*I)*R' = s*R*I*R' = s*R*R' = s*I = M
549561
// where R is the rotation matrix.

src/objects/SPHSystem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ SPHSystem.prototype.update = function(){
143143
Pij = -neighbor.mass * (this.pressures[i] / (this.densities[i]*this.densities[i] + eps) + this.pressures[j] / (this.densities[j]*this.densities[j] + eps));
144144
this.gradw(r_vec, gradW);
145145
// Add to pressure acceleration
146-
gradW.mult(Pij , gradW)
146+
gradW.mult(Pij , gradW);
147147
a_pressure.vadd(gradW, a_pressure);
148148

149149
// Viscosity contribution

src/objects/Spring.js

+20-16
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ module.exports = Spring;
1010
* @param {Body} bodyA
1111
* @param {Body} bodyB
1212
* @param {Object} [options]
13-
* @param {number} options.restLength A number > 0. Default: 1
14-
* @param {number} options.stiffness A number >= 0. Default: 100
15-
* @param {number} options.damping A number >= 0. Default: 1
16-
* @param {Array} options.worldAnchorA Where to hook the spring to body A, in world coordinates.
17-
* @param {Array} options.worldAnchorB
18-
* @param {Array} options.localAnchorA Where to hook the spring to body A, in local body coordinates.
19-
* @param {Array} options.localAnchorB
13+
* @param {number} [options.restLength] A number > 0. Default: 1
14+
* @param {number} [options.stiffness] A number >= 0. Default: 100
15+
* @param {number} [options.damping] A number >= 0. Default: 1
16+
* @param {Vec3} [options.worldAnchorA] Where to hook the spring to body A, in world coordinates.
17+
* @param {Vec3} [options.worldAnchorB]
18+
* @param {Vec3} [options.localAnchorA] Where to hook the spring to body A, in local body coordinates.
19+
* @param {Vec3} [options.localAnchorB]
2020
*/
2121
function Spring(bodyA,bodyB,options){
2222
options = options || {};
@@ -70,15 +70,19 @@ function Spring(bodyA,bodyB,options){
7070
*/
7171
this.localAnchorB = new Vec3();
7272

73-
if(options.localAnchorA) this.localAnchorA.set( options.localAnchorA.x,
74-
options.localAnchorA.y,
75-
options.localAnchorA.z);
76-
if(options.localAnchorB) this.localAnchorB.set( options.localAnchorB.x,
77-
options.localAnchorB.y,
78-
options.localAnchorB.z);
79-
if(options.worldAnchorA) this.setWorldAnchorA(options.worldAnchorA);
80-
if(options.worldAnchorB) this.setWorldAnchorB(options.worldAnchorB);
81-
};
73+
if(options.localAnchorA){
74+
this.localAnchorA.copy(options.localAnchorA);
75+
}
76+
if(options.localAnchorB){
77+
this.localAnchorB.copy(options.localAnchorB.x);
78+
}
79+
if(options.worldAnchorA){
80+
this.setWorldAnchorA(options.worldAnchorA);
81+
}
82+
if(options.worldAnchorB){
83+
this.setWorldAnchorB(options.worldAnchorB);
84+
}
85+
}
8286

8387
/**
8488
* Set the anchor point on body A, using world coordinates.

src/shapes/Box.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = Box;
22

3-
var Shape = require('./Shape')
4-
, Vec3 = require('../math/Vec3')
5-
, ConvexPolyhedron = require('./ConvexPolyhedron')
3+
var Shape = require('./Shape');
4+
var Vec3 = require('../math/Vec3');
5+
var ConvexPolyhedron = require('./ConvexPolyhedron');
66

77
/**
88
* A 3d box shape.
@@ -32,7 +32,7 @@ function Box(halfExtents){
3232

3333
this.updateConvexPolyhedronRepresentation();
3434
this.updateBoundingSphereRadius();
35-
};
35+
}
3636
Box.prototype = new Shape();
3737
Box.prototype.constructor = Box;
3838

src/shapes/ConvexPolyhedron.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = ConvexPolyhedron;
22

3-
var Shape = require('./Shape')
4-
, Vec3 = require('../math/Vec3')
5-
, Quaternion = require('../math/Quaternion')
6-
, Transform = require('../math/Transform')
3+
var Shape = require('./Shape');
4+
var Vec3 = require('../math/Vec3');
5+
var Quaternion = require('../math/Quaternion');
6+
var Transform = require('../math/Transform');
77

88
/**
99
* A set of polygons describing a convex shape.
@@ -147,7 +147,7 @@ ConvexPolyhedron.prototype.computeNormals = function(){
147147
this.faceNormals[i] = n;
148148
var vertex = this.vertices[this.faces[i][0]];
149149
if(n.dot(vertex) < 0){
150-
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.");
150+
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.");
151151
for(var j=0; j<this.faces[i].length; j++){
152152
console.warn(".vertices["+this.faces[i][j]+"] = Vec3("+this.vertices[this.faces[i][j]].toString()+")");
153153
}
@@ -592,8 +592,9 @@ ConvexPolyhedron.prototype.clipFaceAgainstPlane = function(inVertices,outVertice
592592
var n_dot_first, n_dot_last;
593593
var numVerts = inVertices.length;
594594

595-
if(numVerts < 2)
595+
if(numVerts < 2){
596596
return outVertices;
597+
}
597598

598599
var firstVertex = inVertices[inVertices.length-1],
599600
lastVertex = inVertices[0];

src/shapes/Shape.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = Shape;
22

3-
var Shape = require('./Shape')
4-
, Vec3 = require('../math/Vec3')
5-
, Quaternion = require('../math/Quaternion')
6-
, Material = require('../material/Material')
3+
var Shape = require('./Shape');
4+
var Vec3 = require('../math/Vec3');
5+
var Quaternion = require('../math/Quaternion');
6+
var Material = require('../material/Material');
77

88
/**
99
* Base class for shapes

src/shapes/Sphere.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = Sphere;
22

3-
var Shape = require('./Shape')
4-
, Vec3 = require('../math/Vec3')
3+
var Shape = require('./Shape');
4+
var Vec3 = require('../math/Vec3');
55

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

2323
this.updateBoundingSphereRadius();
24-
};
24+
}
2525
Sphere.prototype = new Shape();
2626
Sphere.prototype.constructor = Sphere;
2727

0 commit comments

Comments
 (0)