ngraph.physics.primitives
Advanced tools
Comparing version 0.0.5 to 0.0.6
31
index.js
@@ -10,2 +10,3 @@ module.exports = { | ||
this.pos = new Vector2d(x, y); | ||
this.prevPos = new Vector2d(x, y); | ||
this.force = new Vector2d(); | ||
@@ -17,4 +18,10 @@ this.velocity = new Vector2d(); | ||
function Vector2d(x, y) { | ||
this.x = typeof x === 'number' ? x : 0; | ||
this.y = typeof y === 'number' ? y : 0; | ||
if (x && typeof x !== 'number') { | ||
// could be another vector | ||
this.x = typeof x.x === 'number' ? x.x : 0; | ||
this.y = typeof x.y === 'number' ? x.y : 0; | ||
} else { | ||
this.x = typeof x === 'number' ? x : 0; | ||
this.y = typeof y === 'number' ? y : 0; | ||
} | ||
} | ||
@@ -24,6 +31,7 @@ | ||
this.x = this.y = 0; | ||
} | ||
}; | ||
function Body3d(x, y, z) { | ||
this.pos = new Vector3d(x, y, z); | ||
this.prevPos = new Vector3d(x, y, z); | ||
this.force = new Vector3d(); | ||
@@ -35,9 +43,16 @@ this.velocity = new Vector3d(); | ||
function Vector3d(x, y, z) { | ||
this.x = typeof x === 'number' ? x : 0; | ||
this.y = typeof y === 'number' ? y : 0; | ||
this.z = typeof z === 'number' ? z : 0; | ||
} | ||
if (x && typeof x !== 'number') { | ||
// could be another vector | ||
this.x = typeof x.x === 'number' ? x.x : 0; | ||
this.y = typeof x.y === 'number' ? x.y : 0; | ||
this.z = typeof x.z === 'number' ? x.z : 0; | ||
} else { | ||
this.x = typeof x === 'number' ? x : 0; | ||
this.y = typeof y === 'number' ? y : 0; | ||
this.z = typeof z === 'number' ? z : 0; | ||
} | ||
}; | ||
Vector3d.prototype.reset = function () { | ||
this.x = this.y = this.z = 0; | ||
} | ||
}; |
{ | ||
"name": "ngraph.physics.primitives", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Physics primitives for ngraph.* libraries", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -66,2 +66,11 @@ var test = require('tap').test, | ||
t.end(); | ||
}) | ||
}); | ||
test('vector can use copy constructor', function(t) { | ||
var a = new primitives.Vector3d(1, 2, 3); | ||
var b = new primitives.Vector3d(a); | ||
t.equal(b.x, a.x, 'Value copied'); | ||
t.equal(b.y, a.y, 'Value copied'); | ||
t.equal(b.z, a.z, 'Value copied'); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7568
113