Package Exports
- transformation-matrix
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 (transformation-matrix) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
transformation-matrix
2d transformation matrix functions written in ES6 syntax. Tree shaking ready!
Setup
npm install transformation-matrix
Usage example (ES6)
import {scale, rotate, translate, transform} from 'transformation-matrix';
let matrix = transform(
translate(40,40),
rotate(Math.PI/2),
scale(2, 4)
);
let point = applyToPoint(matrix, {42, 42});
Reference
Functions
- identity() ⇒
Object
Identity matrix
- transform(...matrices) ⇒
Object
Merge multiple matrices into one
- inverse(matrix) ⇒
Object
Calculate a matrix that is the inverse of the provided matrix
- translate(tx, ty) ⇒
Object
Calculate a translate matrix
- scale(sx, sy) ⇒
Object
Calculate a scaling matrix
- rotate(angle) ⇒
Object
Calculate a rotation matrix
- rotateDEG(angle) ⇒
Object
Calculate a rotation matrix with a DEG angle
- applyToPoint(matrix, point) ⇒
Object
Calculate a point transformed with an affine matrix
- applyToPoints(matrix, points) ⇒
array
Calculate an array of points transformed with an affine matrix
- toCSS(matrix) ⇒
string
Serialize the matrix to a string that can be used with CSS or SVG
- toSVG(matrix) ⇒
string
Serialize the matrix to a string that can be used with CSS or SVG
- toString(matrix) ⇒
string
Serialize the matrix to a string that can be used with CSS or SVG
- fromString(string) ⇒
Object
Parse a string matrix formatted as matrix(a,b,c,d,e,f)
- isAffineMatrix(object) ⇒
boolean
Check if the object contain an affine matrix
- fromObject(object) ⇒
Object
Extract an affine matrix from an object that contains a,b,c,d,e,f keys Each value could be a float or a string that contains a float
Changelog
- 0.0.1 - Preview version
Contributing
Your contributions (issues and pull request) are very appreciated!
Author
License
MIT
API
identity() ⇒ Object
Identity matrix
Kind: global function
Returns: Object
- Affine matrix
transform(...matrices) ⇒ Object
Merge multiple matrices into one
Kind: global function
Returns: Object
- Affine matrix
Param | Type | Description |
---|---|---|
...matrices | object |
list of matrices |
inverse(matrix) ⇒ Object
Calculate a matrix that is the inverse of the provided matrix
Kind: global function
Returns: Object
- Affine matrix
Param | Description |
---|---|
matrix | Affine matrix |
translate(tx, ty) ⇒ Object
Calculate a translate matrix
Kind: global function
Returns: Object
- Affine matrix
Param | Description |
---|---|
tx | Translation on axis x |
ty | Translation on axis y |
scale(sx, sy) ⇒ Object
Calculate a scaling matrix
Kind: global function
Returns: Object
- Affine matrix
Param | Description |
---|---|
sx | Scaling on axis x |
sy | Scaling on axis y |
rotate(angle) ⇒ Object
Calculate a rotation matrix
Kind: global function
Returns: Object
- Affine matrix *
Param | Description |
---|---|
angle | Angle in radians |
rotateDEG(angle) ⇒ Object
Calculate a rotation matrix with a DEG angle
Kind: global function
Returns: Object
- Affine matrix
Param | Description |
---|---|
angle | Angle in degree |
applyToPoint(matrix, point) ⇒ Object
Calculate a point transformed with an affine matrix
Kind: global function
Returns: Object
- Point
Param | Description |
---|---|
matrix | Affine matrix |
point | Point |
applyToPoints(matrix, points) ⇒ array
Calculate an array of points transformed with an affine matrix
Kind: global function
Returns: array
- Array of points
Param | Description |
---|---|
matrix | Affine matrix |
points | Array of points |
toCSS(matrix) ⇒ string
Serialize the matrix to a string that can be used with CSS or SVG
Kind: global function
Returns: string
- String that contains a matrix formatted as matrix(a,b,c,d,e,f)
Param | Description |
---|---|
matrix | Affine matrix |
toSVG(matrix) ⇒ string
Serialize the matrix to a string that can be used with CSS or SVG
Kind: global function
Returns: string
- String that contains a matrix formatted as matrix(a,b,c,d,e,f)
Param | Description |
---|---|
matrix | Affine matrix |
toString(matrix) ⇒ string
Serialize the matrix to a string that can be used with CSS or SVG
Kind: global function
Returns: string
- String that contains a matrix formatted as matrix(a,b,c,d,e,f)
Param | Description |
---|---|
matrix | Affine matrix |
fromString(string) ⇒ Object
Parse a string matrix formatted as matrix(a,b,c,d,e,f)
Kind: global function
Returns: Object
- Affine matrix
Param | Description |
---|---|
string | String with a matrix |
isAffineMatrix(object) ⇒ boolean
Check if the object contain an affine matrix
Kind: global function
Param |
---|
object |
fromObject(object) ⇒ Object
Extract an affine matrix from an object that contains a,b,c,d,e,f keys Each value could be a float or a string that contains a float
Kind: global function
Returns: Object
- }
Param |
---|
object |