1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
.. default-domain:: js
.. highlight:: javascript
Matrix
======
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:
.. code-block:: default
/ 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:
.. code-block::
[a, b, c, d, e, f]
In TypeScript the Matrix type is defined as follows:
.. code-block::
type Matrix = [number, number, number, number, number, number]
Constructors
------------
.. class:: Matrix
|interface_type|
Matrices are not represented by a class; they are just plain arrays of six numbers.
Static properties
-----------------
.. data:: Matrix.identity
The identity matrix, short hand for ``[1, 0, 0, 1, 0, 0]``.
.. code-block::
var m = mupdf.Matrix.identity
Static methods
--------------
.. function:: Matrix.scale(sx, sy)
Returns a scaling matrix, short hand for ``[sx, 0, 0, sy, 0, 0]``.
:param number sx: X scale as a floating point number.
:param number sy: Y scale as a floating point number.
:returns: `Matrix`
.. code-block::
var m = mupdf.Matrix.scale(2, 2)
.. function:: Matrix.translate(tx, ty)
Return a translation matrix, short hand for ``[1, 0, 0, 1, tx, ty]``.
:param number tx: X translation as a floating point number.
:param number ty: Y translation as a floating point number.
:returns: `Matrix`
.. code-block::
var m = mupdf.Matrix.translate(2, 2)
.. function:: Matrix.rotate(theta)
Return a rotation matrix, short hand for
``[cos(theta), sin(theta), -sin(theta), cos(theta), 0, 0]``.
:param number theta: Rotation in degrees, positive for CW and negative for CCW.
:returns: `Matrix`
.. code-block::
var m = mupdf.Matrix.rotate(90)
.. function:: Matrix.concat(a, b)
Concatenate matrices ``a`` and ``b``. Bear in mind that matrix
multiplication is not commutative.
:param Matrix a: Left side matrix.
:param Matrix b: Right side matrix.
:returns: `Matrix`
.. code-block::
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]
.. function:: Matrix.invert(matrix)
Inverts the supplied matrix and returns the result.
:param Matrix matrix: Matrix to invert.
:returns: `Matrix`
.. code-block::
var m = mupdf.Matrix.invert([1, 0.5, 1, 1, 1, 1])
|