A Matrix is used to compute transformations of points and graphics objects.
3-by-3 matrices of this form can perform 2-dimensional transformations such as translations, rotations, scaling, and skewing:
/ a b 0 \
| c d 0 |
\ e f 1 /Because of the fixes values in the right-most column, such a matrix is represented in Javascript as an array of six numbers:
[a, b, c, d, e, f]In TypeScript the Matrix type is defined as follows:
type Matrix = [number, number, number, number, number, number]This is an interface, not a concrete class!
Matrices are not represented by a class; they are just plain arrays of six numbers.
The identity matrix, short hand for
[1, 0, 0, 1, 0, 0].
var m = mupdf.Matrix.identityReturns a scaling matrix, short hand for
[sx, 0, 0, sy, 0, 0].
number) – X scale as a floating
point number.number) – Y scale as a floating
point number.var m = mupdf.Matrix.scale(2, 2)Return a translation matrix, short hand for
[1, 0, 0, 1, tx, ty].
number) – X translation as a
floating point number.number) – Y translation as a
floating point number.var m = mupdf.Matrix.translate(2, 2)Return a rotation matrix, short hand for
[cos(theta), sin(theta), -sin(theta), cos(theta), 0, 0].
number) – Rotation in degrees,
positive for CW and negative for CCW.var m = mupdf.Matrix.rotate(90)Concatenate matrices a and b. Bear in mind
that matrix multiplication is not commutative.
var m = mupdf.Matrix.concat([1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2])
// expected result [4, 4, 4, 4, 6, 6]Inverts the supplied matrix and returns the result.
var m = mupdf.Matrix.invert([1, 0.5, 1, 1, 1, 1])