UNPKG

1.51 kBTypeScriptView Raw
1export type Matrix2Tuple = [
2 n11: number,
3 n12: number,
4 n21: number,
5 n22: number,
6];
7
8/**
9 * A class representing a 2x2 {@link https://en.wikipedia.org/wiki/Matrix_(mathematics) matrix}.
10 *
11 * @example
12 * const m = new Matrix2();
13 */
14export class Matrix2 {
15 readonly isMatrix2: true;
16
17 /**
18 * A {@link https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major} list of matrix values.
19 */
20 elements: Matrix2Tuple;
21
22 /**
23 * Creates a 2x2 {@link https://en.wikipedia.org/wiki/Identity_matrix identity matrix}.
24 */
25 constructor();
26
27 /**
28 * Creates a 2x2 matrix with the given arguments in row-major order.
29 */
30 constructor(n11: number, n12: number, n21: number, n22: number);
31
32 /**
33 * Resets this matrix to the 2x2 identity matrix:
34 */
35 identity(): this;
36
37 /**
38 * Sets the elements of this matrix based on an array in
39 * {@link https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major} format.
40 *
41 * @param array the array to read the elements from
42 * @param offset (optional) index of first element in the array. Default is `0`.
43 */
44 fromArray(array: ArrayLike<number>, offset?: number): this;
45
46 /**
47 * Sets the 2x2 matrix values to the given
48 * {@link https://en.wikipedia.org/wiki/Row-_and_column-major_order row-major} sequence of values:
49 * [n11, n12,
50 * n21, n22]
51 */
52 set(n11: number, n12: number, n21: number, n22: number): this;
53}