ngraph.physics.primitives
Advanced tools
Comparing version 0.0.3 to 0.0.4
18
index.js
module.exports = { | ||
Body: Body, | ||
Vector2d: Vector2d | ||
// that's it for now | ||
Vector2d: Vector2d, | ||
Body3d: Body3d, | ||
Vector3d: Vector3d | ||
}; | ||
@@ -18,1 +19,14 @@ | ||
} | ||
function Body3d(x, y, z) { | ||
this.pos = new Vector3d(x, y, z); | ||
this.force = new Vector3d(); | ||
this.velocity = new Vector3d(); | ||
this.mass = 1; | ||
} | ||
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; | ||
} |
{ | ||
"name": "ngraph.physics.primitives", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Physics primitives for ngraph.* libraries", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
ngraph.physics.primitives | ||
========================= | ||
Module with basic 2d physics primitives for ngraph. It defines interface for physical bodies, used in [n-body](https://github.com/anvaka/ngraph.quadtreebh) simulation. | ||
Module with basic 2d and 3d physics primitives for ngraph. It defines interface for physical bodies, used in [n-body](https://github.com/anvaka/ngraph.quadtreebh) simulation. | ||
@@ -20,2 +20,5 @@ [![build status](https://secure.travis-ci.org/anvaka/ngraph.physics.primitives.png)](http://travis-ci.org/anvaka/ngraph.physics.primitives) | ||
console.log(direction.x, direction.y); // prints 0, 0 | ||
var spaceDirection = new physics.Vector3d(); // create a 3d vector | ||
console.log(spaceDirection.x, spaceDirection.y, spaceDirection.z); // prints 0, 0, 0 | ||
``` | ||
@@ -22,0 +25,0 @@ |
@@ -27,1 +27,28 @@ var test = require('tap').test, | ||
}); | ||
test('Body3d has properties force, pos and mass', function(t) { | ||
var body = new primitives.Body3d(); | ||
t.ok(body.force, 'Force attribute is missing on body'); | ||
t.ok(body.pos, 'Pos attribute is missing on body'); | ||
t.ok(body.velocity, 'Velocity attribute is missing on body'); | ||
t.ok(typeof body.mass === 'number' && body.mass !== 0, 'Body should have a mass'); | ||
t.end(); | ||
}); | ||
test('Vector3d has x and y and z', function(t) { | ||
var vector = new primitives.Vector3d(); | ||
t.ok(typeof vector.x === 'number', 'Vector has x coordinates'); | ||
t.ok(typeof vector.y === 'number', 'Vector has y coordinates'); | ||
t.ok(typeof vector.z === 'number', 'Vector has z coordinates'); | ||
var initialized = new primitives.Vector3d(1, 2, 3); | ||
t.equal(initialized.x, 1, 'Vector initialized imporperly'); | ||
t.equal(initialized.y, 2, 'Vector initialized imporperly'); | ||
t.equal(initialized.z, 3, 'Vector initialized imporperly'); | ||
var badInput = new primitives.Vector3d('hello world'); | ||
t.equal(badInput.x, 0, 'Vector should be resilient to bed input'); | ||
t.equal(badInput.y, 0, 'Vector should be resilient to bed input'); | ||
t.equal(badInput.z, 0, 'Vector should be resilient to bed input'); | ||
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
6332
72
34