npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nphyx/vectrix

v0.2.1

Published

A functional matrix math library for javascript

Downloads

3

Readme

Vectrix 0.2.1

Vectrix is a matrix math library for javascript aimed at allowing the developer to make conscious tradeoffs between performance, flexibility, and expressiveness. Compared to alternatives, it is:

  • 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.

Usage

Vectrix supports commonjs modules:

const matrices = require("dist/vectrix.js").matrices;
const vectors = require("dist/vectrix.js").vectors;
const quaternions = require("dist/vectrix.js").quaternions;

It also supports ES6 modules, via the babel preprocessor

import {matrices, vectors, quaternions} from "src/vectrix";

Create vectors:

let xy = vectors.create.vec2(0,1); // 2d vector
let xyz = vectors.create.vec3(1,0,1); // 3d vector
let xyzw = vectors.create.vec4(1,0,0,1); // 4d vector

Create matrices:

let xyz = vectors.create.vec3(4,3,11);
let trans = matrices.create.translation(xyz); // a translation matrix
let rotX = matrices.create.rotateX(3.24); // a rotation matrix (angle in radians)

Create quaternions:

let q = quaternions.create.identity(); // quaternion(1.0,1.0,1.0,0.0);

Vectrix uses a functional style:

// add something to xy
vectors.plus(xy, [7,3]); // vec2(7,4)
// find the dot product of two vectors
vectors.dot(xy, [6,3]); // 3
// do a linear interpolation
vectors.lerp(xy, [4,5], 0.3); // vec2(1.2000000476837158, 2.200000047683716)
// multiply a vector by a rotation matrix to rotate it
vectors.dot(rotX, xyz); // vec3(-3.6859018802642822,-3.3784799575805664,11)

It doesn't mutate its operands:

vectors.plus(xy, [7,3]); // vec2(7,4)
xy; // vec2(0,1)

... except when you ask it to:

vectors.mut_plus(xy, [7,3]);
xy; // vec2(7,4)

... and it supports optional out parameters if you need to save on memory and garbage collection:

let out = vectors.create.vec2();
vectors.plus(xy, [7,3], out); // vec2(7,4)
out; // vec2(7,4)
vectors.plus(xy, [7,3], out) === 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.wrap(xy);
xy.plus([7,3]).toArray(); // [7,4]
// wrapped objects also support GLSL-style aliases: 
xy.yx; // 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.

See the wiki for complete documentation*

*currently out of date, sorry

Install

npm install --only=production

Build

gulp

Testing

npm install --only=dev .
gulp test # test all modules
gulp test:vectors # only test vectors
gulp test:matrices # only test matrices
gulp test:quaterions # only test quaternions 
gulp test:coverage # run a coverage test with istanbul, lcov reports go in /coverage

License

MIT