Skip to content

Commit

Permalink
feat: vector normalize function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Aug 12, 2018
1 parent f08c7be commit beaedfb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,40 @@ describe('Vector test.', () => {
assert.isFalse(dir.len < pos.len, `${dir} should be longer than ${pos}`);

});

it('should change length to 1 when calling normalize', () => {

const pos = new Vector(5, 6, 7);
const dir = pos.normalize();

const length = dir.length;
assert(length > 0.99 && length < 1.01, `${dir} should have length 1, but is ${length}`);

});

it('only for readme', () => {

// create vector by numbers

const pos = new Vector(5, 6, 7);
const dir = new Vector(1, 0, 0);

console.log('pos:', pos, ' dir:', dir);
// pos: { [Number: 10.48] x: 5, y: 6, z: 7 } dir: { [Number: 1] x: 1, y: 0, z: 0 }

// or create vector by calculating other vectors and number
const offset = new Vector(() => dir * 30 + pos);

console.log('offset:', offset);
// offset: { [Number: 36.19] x: 35, y: 6, z: 7 }

// compare length
let way = offset;
if (way > 1) {
way = way.normalize();
}
console.log('way:', way);
// way: { [Number: 1] x: 0.96, y: 0.16, z: 0.19 }

});
});

0 comments on commit beaedfb

Please sign in to comment.