- more expressive and generalized than gl-matrix, but around 1.25 to 10x slower depending on operation and usage
- less general and less powerful than Math.js but easier to use and up to 30x faster
Vectrix is still a work in progress and is not recommended for production.
Vectrix supports commonjs modules:
const matrices = matrices;const vectors = vectors;const quaternions = quaternions;
It also supports ES6 modules, via the babel preprocessor
let xy = vectorscreate; // 2d vectorlet xyz = vectorscreate; // 3d vectorlet xyzw = vectorscreate; // 4d vector
let xyz = vectorscreate;let trans = matricescreate; // a translation matrixlet rotX = matricescreate; // a rotation matrix (angle in radians)
let q = quaternionscreate; // quaternion(1.0,1.0,1.0,0.0);
Vectrix uses a functional style:
// add something to xyvectors; // vec2(7,4)// find the dot product of two vectorsvectors; // 3// do a linear interpolationvectors; // vec2(1.2000000476837158, 2.200000047683716)// multiply a vector by a rotation matrix to rotate itvectors; // vec3(-3.6859018802642822,-3.3784799575805664,11)
It doesn't mutate its operands:
vectors; // vec2(7,4)xy; // vec2(0,1)
... except when you ask it to:
vectors;xy; // vec2(7,4)
... and it supports optional out parameters if you need to save on memory and garbage collection:
let out = vectorscreate;vectors; // vec2(7,4)out; // vec2(7,4)vectors === out; // true
In fact, if you use out parameters wherever they're supported vectrix will almost never allocate memory, because it pre-allocates everything it needs during library initialization (and don't worry, it's a really small footprint).
Vectors, matrices, and quaternions can be wrapped as objects for more expressive usage, at the cost of performance:
// alternatively,xy = vectors;xy; // [7,4]// wrapped objects also support GLSL-style aliases:xyyx; // vec2(1,0);
When performance really matters, use the functional style with out parameters. When you need it to be easier to reason about and manipulate, the object oriented wrappers are helpful.
*currently out of date, sorry
npm install --only=production
npm install --only=dev .gulp test # test all modulesgulp test:vectors # only test vectorsgulp test:matrices # only test matricesgulp test:quaterions # only test quaternionsgulp test:coverage # run a coverage test with istanbul, lcov reports go in /coverage