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

@azleur/transform

v0.2.5

Published

This TypeScript module offers a common representation for 2D coordinate transformations where the old `x` and `y` axes are kept parallel to the new ones. It also offers tools for calculating transforms and applying them to 2D vectors.

Downloads

8

Readme

Axis-aligned transforms

This TypeScript module offers a common representation for 2D coordinate transformations where the old x and y axes are kept parallel to the new ones. It also offers tools for calculating transforms and applying them to 2D vectors.

How it works

  • AffineTransform represents an axis-aligned coordinate transformation (map (x0,y0) in some coordinate system to (x1, y1) in a different coordinate system, keeping old and new (X, Y) axes parallel).
  • You can apply a transform to a point using TransformPoint(), and recover the original point using InverseTransformPoint().
  • Same for rects, using TransformRect() and InverseTransformRect().
  • You can stretch coordinates from one rectangle to another by using ScaleStretch().
  • You can fit coordinates from one rectangle into another (without stretching) by using ScaleFit().

Example

const bounds1 = new Rect(0, 0, 2, 3); // w: 2, h: 3, center: { x: 1, y: 1.5 }.
const bounds2 = new Rect(1, 1, 5, 10); // w: 4, h: 9, center: { x: 3, y: 5.5 }.

const rect0 = new Rect(1, 1, 2, 2); // w: 1, h: 1, center: {x: 1.5, y: 1.5}.
const v0 = new Vec2(1, 1); // {x: 1, y: 1}.

// --------

// Same relative position within rect:
const stretch = ScaleStretch(bounds1, bounds2); // Scale x by 2 and y by 3, send corners to corners and center to center.
const v1 = TransformPoint(v0, stretch); // v1 == { x: 3, y: 4 }.
const v2 = InverseTransformPoint(v1, stretch); // v2 == v0.
const rect1 = TransformRect(r0, stretch); // rect1 == { min: { x: 3, y: 4 }, max: { x: 5, y: 7 } }.
const rect2 = InverseTransformRect(r0, stretch); // rect2 == { min: { x: 0, y: 0 }, max: { x: 0.5, y: 0.333 } }.

// --------

// Don't stretch vectors (zoom equally on all directions):
const fit = ScaleFit(bounds1, bounds2); // Scale x and y by 2, send center to center.
const v3 = TransformPoint(v0, fit); // v3 == { x: 3, y: 4.5 }.
const v4 = InverseTransformPoint(v3, fit); // v4 == v0.
// etc.