Edit in GitHubLog an issue

Matrix

Kind: class

new Matrix()#

new Matrix(a, b, c, d, e, f): Matrix

Creates a new transform matrix with the following structure:

Copied to your clipboard
1| a c e |
2| b d f |
3| 0 0 1 |

Note: XD does not generally allow transform matrices with scale or shear (skew) components - only translate and rotate components are typically permitted.

If no arguments, creates a new identity matrix by default.

setFrom()#

setFrom(otherMatrix)

Copies another matrix's values into this matrix.

ParamTypeDescription
otherMatrixMatrixThe matrix to copy values from.

Kind: instance method of Matrix

clone()#

clone(): Matrix

Returns a copy of the matrix

Kind: instance method of Matrix

add()#

add(aOrMatrix, b, c, d, e, f): Matrix

Returns the current matrix after right multiply.

Multiplies a passed affine transform to the right: this * M. The result effectively applies the transform of the passed in matrix first, followed by the transform of this matrix second. Modifies this matrix object and also returns it so calls can be chained.

ParamTypeDescription
aOrMatrixnumber | MatrixA Matrix or the a component of an affine transform.
b?numberThe b component of an affine transform.
c?numberThe c component of an affine transform.
d?numberThe d component of an affine transform.
e?numberThe e component of an affine transform.
f?numberThe f component of an affine transform.

Kind: instance method of Matrix

multLeft()#

multLeft(aOrMatrix, b, c, d, e, f): Matrix

Returns the current matrix after left multiply.

Multiplies a passed affine transform to the left: M * this. The result effectively applies the transform of this matrix first, followed by the transform of the passed in matrix second. Modifies this matrix object and also returns it so calls can be chained.

ParamTypeDescription
aOrMatrixnumber | MatrixA Matrix or the a component of an affine transform.
b?numberThe b component of an affine transform.
c?numberThe c component of an affine transform.
d?numberThe d component of an affine transform.
e?numberThe e component of an affine transform.
f?numberThe f component of an affine transform.

Kind: instance method of Matrix

invert()#

invert(): Matrix

Returns an inverted version of the matrix. Returns a brand new matrix - does not modify this matrix object.

Kind: instance method of Matrix

translate()#

translate(tx, ty): Matrix

Applies translation before the current transform of this matrix, as if using the add() method. Modifies this matrix object and also returns it so calls can be chained.

ParamTypeDescription
txnumberhorizontal offset distance
tynumbervertical offset distance

Kind: instance method of Matrix

matrix.scale()#

scale(sx, sy, cx, cy): Matrix

Applies scaling before the current transform of this matrix, as if using the add() method. Modifies this matrix object and also returns it so calls can be chained.

Note: scale transforms are not generally permitted in XD.

ParamTypeDescription
sxnumberamount to be scaled, with 1 resulting in no change
sy?numberamount to scale along the vertical axis. (Otherwise sx applies to both axes.)
cx?numberhorizontal origin point from which to scale (if unspecified, scales from the local coordinates' origin point)
cy?numbervertical origin point from which to scale

Kind: instance method of Matrix

matrix.rotate()#

rotate(angle, cx, cy): Matrix

Applies clockwise rotation before the current transform of this matrix, as if using the add() method. Modifies this matrix object and also returns it so calls can be chained.

ParamTypeDescription
anglenumberangle of rotation, in degrees clockwise
cx?numberhorizontal origin point from which to rotate (if unspecified, scales from the local coordinates' origin point)
cy?numbervertical origin point from which to rotate

Kind: instance method of Matrix

x()#

x(x, y): number

Returns x coordinate of the given point after transformation described by this matrix. See also Matrix.y and Matrix.transformPoint.

ParamType
xnumber
ynumber

Kind: instance method of Matrix

y()#

y(x, y): number

Returns y coordinate of the given point after transformation described by this matrix. See also Matrix.x and Matrix.transformPoint.

ParamType
xnumber
ynumber

Kind: instance method of Matrix

transformPoint()#

transformPoint(point): {x:number, y:number}

Returns x & y coordinates of the given point after transformation described by this matrix.

ParamType
point{x:number, y:number}

Kind: instance method of Matrix

transformRect()#

transformRect(rect): {x:number, y:number, width:number, height:number}

Transforms a rectangle using this matrix, returning the axis-aligned bounds of the resulting rectangle. If this matrix has rotation, then the result will have different width & height from the original rectangle, due to axis alignment. See "Coordinate Spaces" for some illustrations of this.

ParamType
rect{x:number, y:number, width:number, height:number}

Kind: instance method of Matrix

getTranslate()#

getTranslate(): Array.<number>

Returns the translation component of this matrix: [tx, ty]. Equals the e and f components of this matrix.

Kind: instance method of Matrix

scaleFactors()#

scaleFactors(): {scaleX:number, scaleY:number}

Split the matrix into scale factors. This method assumes that there is no skew in the matrix.

Kind: instance method of Matrix

removedScaleMatrix()#

removedScaleMatrix(scaleX, scaleY): Matrix

Returns a new matrix that contains only the translate and rotate components of the current matrix, with the given scale factors stripped out. Must be passed the exact scale factors returned by scaleFactors() for this matrix, and this matrix must have no skew/shear component.

Returns a brand new matrix, and does not modify this matrix object.

ParamTypeDescription
scaleXnumberhorrizontal scale component to remove
scaleYnumbervertical scale component to remove

Kind: instance method of Matrix

hasSkew()#

hasSkew(): boolean

Returns true if the matrix includes any skew (shear).

Kind: instance method of Matrix

Was this helpful?
Copyright © 2021 Adobe. All rights reserved.