Skip to content

Latest commit

 

History

History
129 lines (93 loc) · 4.03 KB

Matrix2D.md

File metadata and controls

129 lines (93 loc) · 4.03 KB

Matrix2D

Kind: global class
Npmpackage:

new Matrix2D()

A 2D Matrix for transforming: translating, rotating, scaling, skewing
Import from ad-geom

Example

import { Matrix2D } from 'ad-geom'

const myMatrix = new Matrix2D()
myMatrix.rotate(0.785) // rotate 45 degrees
myMatrix.translate(30, 45) // x:30, y:45

// get the matrix as a css string to assign to style.tranform
const cssString = myMatrix.getCss() // "matrix(0.7071, 0.7071, -0.7071, 0.7071, 30, 45)"

// or get the transfrom from an element and apply to the matrix
const fromElemString = myDiv.style.transform // 'matrix(1,0,0,1,0,0)'
myMatrix.setFromCss(fromElemString)

Matrix2D.clear()

Resets the matrix back to the identity starting point

Kind: static method of Matrix2D

Matrix2D.rotate(radians) ⇒ Matrix2D

Rotates the matrix

Kind: static method of Matrix2D

Param Type Description
radians number The amount to rotate the matrix in radians

Matrix2D.rotate(x, y) ⇒ Matrix2D

Scale the matrix

Kind: static method of Matrix2D

Param Type Description
x number The amount to scale the matrix horizontally
y number The amount to scale the matrix vertically

Matrix2D.skew(ax, ay) ⇒ Matrix2D

Skew the matrix.

Kind: static method of Matrix2D

Param Type Description
ax number The amount to skew / slant the matrix horizontally
ay number The amount to skew / slant the matrix vertically

Matrix2D.translate(x, y) ⇒ Matrix2D

Move the matrix's position

Kind: static method of Matrix2D

Param Type Description
x number The amount to move the matrix horizontally
y number The amount to move the matrix vertically

Matrix2D.getCss() ⇒ String

Retrieves the matrix information as a css tranfrom formatted string

Kind: static method of Matrix2D
Example

myMatrix.getCss() // matrix(1,0,0,1,0,0)

Matrix2D.getX() ⇒ Number

Shorthand to retrieve the matrix's x position

Kind: static method of Matrix2D

Matrix2D.getY() ⇒ Number

Shorthand to retrieve the matrix's y position

Kind: static method of Matrix2D

Matrix2D.setFromCss(matrixString)

Assign the matrix's values based on existing css string

Kind: static method of Matrix2D

Param Type Description
matrixString string A css transfrom formatted string

Example

myMatrix.setFromCss('matrix(1,0,0,1,0,0)')