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

trans-vector2d

v2.0.0

Published

Immutable 2d vector and transformation-matrix

Downloads

8

Readme

trans-vector2d

Immutable 2d vector and transformation-matrix.

Install

npm install trans-vector2d

Vector

import { Vector } from "transformation-matrix";

const v1 = new Vector(1, 2);
const v2 = new Vector(...[1, 2]);
const v3 = Vector.from({ x: 1, y: 2 });
const v4 = Vector.from({ y: 2 });
const vOne = Vector.one; // { x: 1, y: 1 }
const vZero = Vector.zero; // { x: 0, y: 0 }

const v = v1
  .add(v2)
  .sub(v2)
  .mlt(2)
  .div(2)
  .hadamard(v2);

console.log(v.x, v.y);
// v.x = 1; // error

const abs = v1.abs();
const norm = v1.norm();
const distance = v1.distance(v2);
const unitVector = v1.unit(); // norm = 1
const rotated = v1.rotate(Math.PI);
const angle = v1.angle();
const obj = v1.asObject(); // { x: 1, y: 2}
const art = v1.asArray(); // [1, 2]
const eq = v1.equals(v2); // false
const closing = v1.isClosedTo(v2); // false

Matrix

import { Matrix } from "transformation-matrix";

const m1 = new Matrix(1, 0, 0, 1, 2, 3);
/**
 * [a, c, e,
 *  b, d, f,
 *  0, 0, 1]
 */
const m2 = Matrix.from({ a: 1, b: 0, c: 0, d: 1, e: 4, f: 5 });
const m3 = Matrix.from({
  translation: { x: 6, y: 7 },
  rotation: Math.PI,
  scale: { x: 1, y: 1 }
});
const mE = Matrix.identity;

const m = m1
  .globalize(m2)
  .localize(m2)
  .globalizedBy(m2)
  .localizedBy(m2)
  .inverse()
  .translated({ x: 1, y: 2 })
  .rotated(Math.PI)
  .scaled({ x: 1, y: 1 });

console.log(m.a, m.b, m.c, m.d, m.e, m.e);
// m.a = 1; // error

const t = Matrix.translation({ x: 1, y: 2 });
const r = Matrix.rotation(Math.PI);
const s = Matrix.scaling({ x: 1, y: 2 });
const { translation, rotation. scale} = m1.decompose();
const gPoint = m1.globalizePoint({ x: 3, y: 4 });
const lPoint = m1.localizePoint({ x: 3, y: 4 });
const eq = m1.equals(m2); // false
const closing = m1.isClosedTo(m2); // false
const obj = m1.asObject();
const ary = m1.asArray();