Matrix.md

October 15, 2018 · View on GitHub

Matrix

Kind: class


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

Creates a new transform matrix with the following structure:

| a c e |
| b d f |
| 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.


matrix.setFrom(otherMatrix)

Copies another matrix's values into this matrix.

Kind: instance method of Matrix

ParamTypeDescription
otherMatrix!MatrixThe matrix to copy values from.

matrix.clone()

Returns a copy of the matrix

Kind: instance method of Matrix
Returns: !Matrix


matrix.add(aOrMatrix, b, c, d, e, f) ⇒ !Matrix

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.

Kind: instance method of Matrix
Returns: !Matrix - The current matrix after right multiply.

ParamTypeDescription
aOrMatrixnumber!Matrix
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.

matrix.multLeft(aOrMatrix, b, c, d, e, f) ⇒ !Matrix

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.

Kind: instance method of Matrix
Returns: !Matrix - The current matrix after left multiply.

ParamTypeDescription
aOrMatrixnumber!Matrix
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.

matrix.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
Returns: !Matrix


matrix.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.

Kind: instance method of Matrix
Returns: !Matrix

ParamTypeDescription
txnumberhorizontal offset distance
tynumbervertical offset distance

matrix.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.

Kind: instance method of Matrix
Returns: !Matrix

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

matrix.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.

Kind: instance method of Matrix
Returns: !Matrix

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

matrix.x(x, y) ⇒ number

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

Kind: instance method of Matrix
Returns: number

ParamType
xnumber
ynumber

matrix.y(x, y) ⇒ number

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

Kind: instance method of Matrix
Returns: number

ParamType
xnumber
ynumber

matrix.transformPoint(point) ⇒ !{x:number, y:number}

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

Kind: instance method of Matrix
Returns: !{x:number, y:number}

ParamType
point!{x:number, y:number}

matrix.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.

Kind: instance method of Matrix
Returns: !{x:number, y:number, width:number, height:number}

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

matrix.getTranslate() ⇒ !Array.<number>

Kind: instance method of Matrix
Returns: !Array.<number> - The translation component of this matrix: [tx, ty]. Equals the e and f components of this matrix.


matrix.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
Returns: !{scaleX:number, scaleY:number}


matrix.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 - does not modify this matrix object.

Kind: instance method of Matrix
Returns: !Matrix - The matrix without the passed scaling factors.

ParamTypeDescription
scaleXnumberhorrizontal scale component to remove
scaleYnumbervertical scale component to remove

matrix.hasSkew() ⇒ boolean

Kind: instance method of Matrix
Returns: boolean - true, if the matrix includes any skew (shear)