Skip to content

Commit

Permalink
fix(example): refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGerbeth committed Aug 12, 2018
1 parent d672c6c commit a03cdda
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@ const { calc, default: Vector } = require('../lib');

/* eslint-disable no-console */

// 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 offsetA = new Vector(() => dir * 30 + pos);
console.log('offsetA:', offsetA);
// offsetA: { [Number: 36.19] x: 35, y: 6, z: 7 }

const offsetB = calc(() => dir * 30 + pos);
// calc two Vectors
const offsetB = calc(() => dir * 20 + pos);
console.log('offsetB:', offsetB);
// offsetB: { [Number: 26.645825188948457] x: 25, y: 6, z: 7 }

// compare length
let way = offsetA;
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 a03cdda

Please sign in to comment.