@omjs/matrix2d
v1.0.1
Published
CSS tranform-2D matrix
Downloads
1
Readme
Matrix2D
A class derived from @omjs/iterable for describing css 2D-transformation, which is featured by ECMAScript 2015
and Immutable
, where a polyfill for Symbol
is needed for old browsers.
Now version: 1.0.0
Publish date: 2018.06.08
INSTALL
npm
npm i @omjs/matrix2d
browser
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
<script src="node_modules/@omjs/matrix2d/dist/matrix2D.min.js"></script>
USAGE
import { Matrix2D } from '@omjs/matrix2d';
QUICK START
import { Matrix2D, lmul } from '@omjs/matrix2d';
let mat1 = new Matrix2D(1, 0, 0, 1, 0, 0); // constructor => matrix(1,0,0,1,0,0)
// using babel-plugin-transform-function-bind
let mat2 = mat1::lmul([-1, 0, 0, -1, 0, 0]); // matrix muliply => matrix(-1,0,0,-1,0,0)
mat2.toString(); // => matrix(-1,0,0,-1,0,0)
LICENCE
APIs
Contructor
Serveral Numbers, Number Arrays or Strings are allowed to create a Matrix2D Object.
Matrix2D([a=1],[b=0],[c=0],[d=1],[tx=0],[ty=0])
Matrix2D([array, [...]])
Matrix2D([string, [...]])
e.g.
let mat1 = new Matrix2D(); // matrix(1,0,0,1,0,0)
let mat2 = new Matrix2D(1, 0, 0, 1, 0, 0); // matrix(1,0,0,1,0,0)
let mat3 = new Matrix2D([1, 0, 0, 1, 0, 0]); // matrix(1,0,0,1)
let mat4 = new Matrix2D('matrix(1,0,0,1,0,0)'); // matrix(1,0,0,1,0,0)
let mat5 = new Matrix2D(mat1); // matrix(1,0,0,1,0,0)
Static Properties
Matrix2D.MUL_DIR
The direction of multiply.
- Matrix2D.MUL_DIR.L - left
- Matrix2D.MUL_DIR.R - Right
Matrix2D.ROTATE_DIR
The direction of rotate.
- Matrix2D.ROTATE_DIR.CW - clockwise
- Matrix2D.ROTATE_DIR.ACW - anticlockwise
version
: string
The code version, current version is 1.0.0;
Properties
[]
Get the matrix's data by index.
e.g.
let mat = new Matrix2D();
mat[0]; // 1
mat[1]; // 0
mat[2]; // 0
mat[3]; // 1
mat[4]; // 0
mat[5]; // 0
Static Methods
Matrix2D.isMatrix2D(obj: any)
=> boolean
Check whether the obj's type is matrix2d or not;
e.g.
let mat = new Matrix2D(1, 0, 0, 1, 0, 0);
Matrix2D.isMatrix2D(mat); // true
Matrix2D.isMatrix2D([1, 0, 0, 1, 0, 0]); // false
Methods
toString()
=> string
Convert to string.
e.g.
let mat = new Matrix2D(1, 0, 0, 1, 0, 0);
mat.toString(); // matrix(1,0,0,1,0,0)
valueOf()
=> Array(6)
Get the value of matrix2d object
e.g.
let mat = new Matrix2D();
mat.valueOf(); // [1,0,0,1,0,0]
clone()
=> Matrix2D
Get a deep clone.
e.g.
let mat = new Matrix2D();
mat.clone(); // matrix(1,0,0,1,0,0);
mat == mat.clone(); // false
Operations
lmul(mat: Matrix2D | Array)
=> Matrix2D
Pre-multiplied by given matrix, and return a new Matrix2D, used to compose transformation.
e.g.
let mat = new Matrix2d();
mat::lmul([-1, 0, 0, -1, 0, 0]); // matrix(-1,0,0,-1,0,0)
rmul(mat: Matrix2D | Array)
=> Matrix2D
Post-multiplied by given matrix, and return a new Matrix2D, used to compose transformation.
e.g.
let mat = new Matrix2d();
mat::rmul([-1, 0, 0, -1, 0, 0]); // matrix(-1,0,0,-1,0,0)
mul(mat: Matrix2D | Array, dir: Matrix2D.MUL_DIR)
=> Matrix2D
Multiplied by given matrix and direction, and return a new Matrix2D, used to compose transformation.
e.g.
let mat = new Matrix2d();
mat::mul([-1, 0, 0, -1, 0, 0], Matrix2D.MUL_DIR.L); // matrix(-1,0,0,-1,0,0)