JSPM

transformist

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q16706F
  • 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 composing transforms and exporting as a matrix. This is essentially wrapping mat3 transforms, but with an API that might seem friendlier. Useful for 2D games and graphics.

js-standard-style

install

use npm

npm install transformist

examples

var transform = require('transformist')
var t = transform({translation: [1, 2], scale: 2})

t.apply([1, 1])
> [3, 4]
var t = transform({rotation: 90, scale: 2})

t.apply([[0, 0], [0, 1]])
> [[0, 0], [-2, 0]]

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. Equivalent to multiplying 3d transformation matrices.

t.tomat()

Return a mat3 representation of the transform.