JSPM

transformist

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q16734F
  • License MIT

simple transformations in the plane

Package Exports

  • transformist

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (transformist) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

transformist

Simple transformations in the plane. A transform in two dimensions is defined here as a translation, a rotation, and a scaling. This module lets you specify this kind of transform and apply it, or its inverse, to one or more points. Methods are also provided for comparing and composing transforms. Useful for 2D games and graphics.

js-standard-style

install

use npm

npm install transformist

usage

t = transform(opts)

create a new transform

  • opts.translation two-dimensional array in the form [x, y], default [0, 0]
  • opts.rotation angle of rotation in degrees, default 0
  • opts.scale scale factor, default 1

t.apply(points)

Apply transformation to one or more points of the form [[x, y], [x, y]...] or [x, y]. Applies in order: scale, rotation, translation.

t.invert(points)

Undo a transformation on one or more points of the form [[x, y], [x, y]...] or [x, y]. Applies the inverse transform in order: translation, rotation, scale.

t.compose(other)

Compose this transform with a transform other, modifies in place. Translations and angles are added, scales are multiplied.

t.difference(other)

Compute difference between this transform and a transform other. Returns an object

{
    translation: [dx, dy]
    rotation: dr
    scale: ds
}

t.distance(other)

Compute distance between this transform and a transform other. Returns an object

{
    translation: sqrt(dx^2 + dy^2)
    rotation: abs(dr)
    scale: abs(ds)
}