@math.gl/core 4.0.0 → 4.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/base/math-array.d.ts +1 -2
- package/dist/classes/base/math-array.js +223 -266
- package/dist/classes/base/matrix.d.ts +1 -2
- package/dist/classes/base/matrix.js +56 -53
- package/dist/classes/base/vector.d.ts +1 -2
- package/dist/classes/base/vector.js +125 -135
- package/dist/classes/euler.d.ts +2 -3
- package/dist/classes/euler.js +464 -533
- package/dist/classes/matrix3.d.ts +9 -4
- package/dist/classes/matrix3.js +191 -190
- package/dist/classes/matrix4.d.ts +8 -4
- package/dist/classes/matrix4.js +521 -452
- package/dist/classes/pose.d.ts +4 -5
- package/dist/classes/pose.js +106 -119
- package/dist/classes/quaternion.d.ts +1 -2
- package/dist/classes/quaternion.js +261 -233
- package/dist/classes/spherical-coordinates.d.ts +3 -4
- package/dist/classes/spherical-coordinates.js +142 -147
- package/dist/classes/vector2.d.ts +6 -5
- package/dist/classes/vector2.js +103 -85
- package/dist/classes/vector3.d.ts +6 -5
- package/dist/classes/vector3.js +129 -136
- package/dist/classes/vector4.d.ts +7 -6
- package/dist/classes/vector4.js +108 -114
- package/dist/gl-matrix/common.d.ts +0 -1
- package/dist/gl-matrix/common.js +38 -6
- package/dist/gl-matrix/mat3.d.ts +0 -1
- package/dist/gl-matrix/mat3.js +699 -425
- package/dist/gl-matrix/mat4.d.ts +0 -1
- package/dist/gl-matrix/mat4.js +1879 -1339
- package/dist/gl-matrix/quat.d.ts +0 -1
- package/dist/gl-matrix/quat.js +655 -257
- package/dist/gl-matrix/vec2.d.ts +0 -1
- package/dist/gl-matrix/vec2.js +529 -212
- package/dist/gl-matrix/vec3.d.ts +0 -1
- package/dist/gl-matrix/vec3.js +703 -335
- package/dist/gl-matrix/vec4.d.ts +0 -1
- package/dist/gl-matrix/vec4.js +579 -293
- package/dist/gl-matrix/wip/index.d.ts +3 -4
- package/dist/gl-matrix/wip/index.js +5 -1
- package/dist/gl-matrix/wip/mat2.d.ts +1 -2
- package/dist/gl-matrix/wip/mat2.js +336 -157
- package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
- package/dist/gl-matrix/wip/mat2d.js +380 -202
- package/dist/gl-matrix/wip/quat2.d.ts +0 -1
- package/dist/gl-matrix/wip/quat2.js +650 -409
- package/dist/index.cjs +60 -100
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +27 -23
- package/dist/index.js +25 -16
- package/dist/lib/assert.d.ts +0 -1
- package/dist/lib/assert.js +6 -4
- package/dist/lib/common.d.ts +2 -3
- package/dist/lib/common.js +165 -134
- package/dist/lib/gl-matrix-extras.d.ts +0 -1
- package/dist/lib/gl-matrix-extras.js +42 -36
- package/dist/lib/math-utils.d.ts +0 -1
- package/dist/lib/math-utils.js +5 -1
- package/dist/lib/validators.d.ts +0 -1
- package/dist/lib/validators.js +25 -25
- package/package.json +5 -6
- package/src/classes/base/math-array.ts +4 -1
- package/src/classes/base/matrix.ts +4 -1
- package/src/classes/base/vector.ts +4 -1
- package/src/classes/euler.ts +4 -1
- package/src/classes/matrix3.ts +12 -3
- package/src/classes/matrix4.ts +11 -3
- package/src/classes/pose.ts +4 -1
- package/src/classes/quaternion.ts +4 -1
- package/src/classes/spherical-coordinates.ts +4 -1
- package/src/classes/vector2.ts +11 -4
- package/src/classes/vector3.ts +10 -4
- package/src/classes/vector4.ts +9 -4
- package/src/gl-matrix/wip/index.js +4 -0
- package/src/gl-matrix/wip/mat2.js +4 -0
- package/src/gl-matrix/wip/mat2d.js +4 -0
- package/src/gl-matrix/wip/quat2.ts +4 -0
- package/src/index.ts +10 -2
- package/src/lib/assert.ts +4 -0
- package/src/lib/common.ts +3 -1
- package/src/lib/gl-matrix-extras.ts +4 -0
- package/src/lib/gl-matrix.d.ts +4 -0
- package/src/lib/math-utils.ts +4 -0
- package/src/lib/validators.ts +4 -19
- package/dist/classes/base/math-array.d.ts.map +0 -1
- package/dist/classes/base/math-array.js.map +0 -1
- package/dist/classes/base/matrix.d.ts.map +0 -1
- package/dist/classes/base/matrix.js.map +0 -1
- package/dist/classes/base/vector.d.ts.map +0 -1
- package/dist/classes/base/vector.js.map +0 -1
- package/dist/classes/euler.d.ts.map +0 -1
- package/dist/classes/euler.js.map +0 -1
- package/dist/classes/matrix3.d.ts.map +0 -1
- package/dist/classes/matrix3.js.map +0 -1
- package/dist/classes/matrix4.d.ts.map +0 -1
- package/dist/classes/matrix4.js.map +0 -1
- package/dist/classes/pose.d.ts.map +0 -1
- package/dist/classes/pose.js.map +0 -1
- package/dist/classes/quaternion.d.ts.map +0 -1
- package/dist/classes/quaternion.js.map +0 -1
- package/dist/classes/spherical-coordinates.d.ts.map +0 -1
- package/dist/classes/spherical-coordinates.js.map +0 -1
- package/dist/classes/vector2.d.ts.map +0 -1
- package/dist/classes/vector2.js.map +0 -1
- package/dist/classes/vector3.d.ts.map +0 -1
- package/dist/classes/vector3.js.map +0 -1
- package/dist/classes/vector4.d.ts.map +0 -1
- package/dist/classes/vector4.js.map +0 -1
- package/dist/gl-matrix/common.d.ts.map +0 -1
- package/dist/gl-matrix/common.js.map +0 -1
- package/dist/gl-matrix/mat3.d.ts.map +0 -1
- package/dist/gl-matrix/mat3.js.map +0 -1
- package/dist/gl-matrix/mat4.d.ts.map +0 -1
- package/dist/gl-matrix/mat4.js.map +0 -1
- package/dist/gl-matrix/quat.d.ts.map +0 -1
- package/dist/gl-matrix/quat.js.map +0 -1
- package/dist/gl-matrix/vec2.d.ts.map +0 -1
- package/dist/gl-matrix/vec2.js.map +0 -1
- package/dist/gl-matrix/vec3.d.ts.map +0 -1
- package/dist/gl-matrix/vec3.js.map +0 -1
- package/dist/gl-matrix/vec4.d.ts.map +0 -1
- package/dist/gl-matrix/vec4.js.map +0 -1
- package/dist/gl-matrix/wip/index.d.ts.map +0 -1
- package/dist/gl-matrix/wip/index.js.map +0 -1
- package/dist/gl-matrix/wip/mat2.d.ts.map +0 -1
- package/dist/gl-matrix/wip/mat2.js.map +0 -1
- package/dist/gl-matrix/wip/mat2d.d.ts.map +0 -1
- package/dist/gl-matrix/wip/mat2d.js.map +0 -1
- package/dist/gl-matrix/wip/quat2.d.ts.map +0 -1
- package/dist/gl-matrix/wip/quat2.js.map +0 -1
- package/dist/gl-matrix/wip/types.d.js +0 -2
- package/dist/gl-matrix/wip/types.d.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/assert.d.ts.map +0 -1
- package/dist/lib/assert.js.map +0 -1
- package/dist/lib/common.d.ts.map +0 -1
- package/dist/lib/common.js.map +0 -1
- package/dist/lib/gl-matrix-extras.d.ts.map +0 -1
- package/dist/lib/gl-matrix-extras.js.map +0 -1
- package/dist/lib/gl-matrix.d.js +0 -2
- package/dist/lib/gl-matrix.d.js.map +0 -1
- package/dist/lib/math-utils.d.ts.map +0 -1
- package/dist/lib/math-utils.js.map +0 -1
- package/dist/lib/validators.d.ts.map +0 -1
- package/dist/lib/validators.js.map +0 -1
- package/src/gl-matrix/wip/types.d.ts +0 -93
|
@@ -1,251 +1,429 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/* eslint-disable */
|
|
1
6
|
import * as glMatrix from './common.js';
|
|
7
|
+
/**
|
|
8
|
+
* 2x3 Matrix
|
|
9
|
+
* @module mat2d
|
|
10
|
+
* @description
|
|
11
|
+
* A mat2d contains six elements defined as:
|
|
12
|
+
* <pre>
|
|
13
|
+
* [a, b,
|
|
14
|
+
* c, d,
|
|
15
|
+
* tx, ty]
|
|
16
|
+
* </pre>
|
|
17
|
+
* This is a short form for the 3x3 matrix:
|
|
18
|
+
* <pre>
|
|
19
|
+
* [a, b, 0,
|
|
20
|
+
* c, d, 0,
|
|
21
|
+
* tx, ty, 1]
|
|
22
|
+
* </pre>
|
|
23
|
+
* The last column is ignored so the array is shorter and operations are faster.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new identity mat2d
|
|
27
|
+
*
|
|
28
|
+
* @returns {mat2d} a new 2x3 matrix
|
|
29
|
+
*/
|
|
2
30
|
export function create() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
out[3] = 1;
|
|
14
|
-
return out;
|
|
31
|
+
let out = new glMatrix.ARRAY_TYPE(6);
|
|
32
|
+
if (glMatrix.ARRAY_TYPE != Float32Array) {
|
|
33
|
+
out[1] = 0;
|
|
34
|
+
out[2] = 0;
|
|
35
|
+
out[4] = 0;
|
|
36
|
+
out[5] = 0;
|
|
37
|
+
}
|
|
38
|
+
out[0] = 1;
|
|
39
|
+
out[3] = 1;
|
|
40
|
+
return out;
|
|
15
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new mat2d initialized with values from an existing matrix
|
|
44
|
+
*
|
|
45
|
+
* @param {ReadonlyMat2d} a matrix to clone
|
|
46
|
+
* @returns {mat2d} a new 2x3 matrix
|
|
47
|
+
*/
|
|
16
48
|
export function clone(a) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
let out = new glMatrix.ARRAY_TYPE(6);
|
|
50
|
+
out[0] = a[0];
|
|
51
|
+
out[1] = a[1];
|
|
52
|
+
out[2] = a[2];
|
|
53
|
+
out[3] = a[3];
|
|
54
|
+
out[4] = a[4];
|
|
55
|
+
out[5] = a[5];
|
|
56
|
+
return out;
|
|
25
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Copy the values from one mat2d to another
|
|
60
|
+
*
|
|
61
|
+
* @param {mat2d} out the receiving matrix
|
|
62
|
+
* @param {ReadonlyMat2d} a the source matrix
|
|
63
|
+
* @returns {mat2d} out
|
|
64
|
+
*/
|
|
26
65
|
export function copy(out, a) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
66
|
+
out[0] = a[0];
|
|
67
|
+
out[1] = a[1];
|
|
68
|
+
out[2] = a[2];
|
|
69
|
+
out[3] = a[3];
|
|
70
|
+
out[4] = a[4];
|
|
71
|
+
out[5] = a[5];
|
|
72
|
+
return out;
|
|
34
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Set a mat2d to the identity matrix
|
|
76
|
+
*
|
|
77
|
+
* @param {mat2d} out the receiving matrix
|
|
78
|
+
* @returns {mat2d} out
|
|
79
|
+
*/
|
|
35
80
|
export function identity(out) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
81
|
+
out[0] = 1;
|
|
82
|
+
out[1] = 0;
|
|
83
|
+
out[2] = 0;
|
|
84
|
+
out[3] = 1;
|
|
85
|
+
out[4] = 0;
|
|
86
|
+
out[5] = 0;
|
|
87
|
+
return out;
|
|
43
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a new mat2d with the given values
|
|
91
|
+
*
|
|
92
|
+
* @param {Number} a Component A (index 0)
|
|
93
|
+
* @param {Number} b Component B (index 1)
|
|
94
|
+
* @param {Number} c Component C (index 2)
|
|
95
|
+
* @param {Number} d Component D (index 3)
|
|
96
|
+
* @param {Number} tx Component TX (index 4)
|
|
97
|
+
* @param {Number} ty Component TY (index 5)
|
|
98
|
+
* @returns {mat2d} A new mat2d
|
|
99
|
+
*/
|
|
44
100
|
export function fromValues(a, b, c, d, tx, ty) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
101
|
+
let out = new glMatrix.ARRAY_TYPE(6);
|
|
102
|
+
out[0] = a;
|
|
103
|
+
out[1] = b;
|
|
104
|
+
out[2] = c;
|
|
105
|
+
out[3] = d;
|
|
106
|
+
out[4] = tx;
|
|
107
|
+
out[5] = ty;
|
|
108
|
+
return out;
|
|
53
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Set the components of a mat2d to the given values
|
|
112
|
+
*
|
|
113
|
+
* @param {mat2d} out the receiving matrix
|
|
114
|
+
* @param {Number} a Component A (index 0)
|
|
115
|
+
* @param {Number} b Component B (index 1)
|
|
116
|
+
* @param {Number} c Component C (index 2)
|
|
117
|
+
* @param {Number} d Component D (index 3)
|
|
118
|
+
* @param {Number} tx Component TX (index 4)
|
|
119
|
+
* @param {Number} ty Component TY (index 5)
|
|
120
|
+
* @returns {mat2d} out
|
|
121
|
+
*/
|
|
54
122
|
export function set(out, a, b, c, d, tx, ty) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
123
|
+
out[0] = a;
|
|
124
|
+
out[1] = b;
|
|
125
|
+
out[2] = c;
|
|
126
|
+
out[3] = d;
|
|
127
|
+
out[4] = tx;
|
|
128
|
+
out[5] = ty;
|
|
129
|
+
return out;
|
|
62
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Inverts a mat2d
|
|
133
|
+
*
|
|
134
|
+
* @param {mat2d} out the receiving matrix
|
|
135
|
+
* @param {ReadonlyMat2d} a the source matrix
|
|
136
|
+
* @returns {mat2d} out
|
|
137
|
+
*/
|
|
63
138
|
export function invert(out, a) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
out[1] = -ab * det;
|
|
79
|
-
out[2] = -ac * det;
|
|
80
|
-
out[3] = aa * det;
|
|
81
|
-
out[4] = (ac * aty - ad * atx) * det;
|
|
82
|
-
out[5] = (ab * atx - aa * aty) * det;
|
|
83
|
-
return out;
|
|
139
|
+
let aa = a[0], ab = a[1], ac = a[2], ad = a[3];
|
|
140
|
+
let atx = a[4], aty = a[5];
|
|
141
|
+
let det = aa * ad - ab * ac;
|
|
142
|
+
if (!det) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
det = 1.0 / det;
|
|
146
|
+
out[0] = ad * det;
|
|
147
|
+
out[1] = -ab * det;
|
|
148
|
+
out[2] = -ac * det;
|
|
149
|
+
out[3] = aa * det;
|
|
150
|
+
out[4] = (ac * aty - ad * atx) * det;
|
|
151
|
+
out[5] = (ab * atx - aa * aty) * det;
|
|
152
|
+
return out;
|
|
84
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Calculates the determinant of a mat2d
|
|
156
|
+
*
|
|
157
|
+
* @param {ReadonlyMat2d} a the source matrix
|
|
158
|
+
* @returns {Number} determinant of a
|
|
159
|
+
*/
|
|
85
160
|
export function determinant(a) {
|
|
86
|
-
|
|
161
|
+
return a[0] * a[3] - a[1] * a[2];
|
|
87
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Multiplies two mat2d's
|
|
165
|
+
*
|
|
166
|
+
* @param {mat2d} out the receiving matrix
|
|
167
|
+
* @param {ReadonlyMat2d} a the first operand
|
|
168
|
+
* @param {ReadonlyMat2d} b the second operand
|
|
169
|
+
* @returns {mat2d} out
|
|
170
|
+
*/
|
|
88
171
|
export function multiply(out, a, b) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
b3 = b[3],
|
|
99
|
-
b4 = b[4],
|
|
100
|
-
b5 = b[5];
|
|
101
|
-
out[0] = a0 * b0 + a2 * b1;
|
|
102
|
-
out[1] = a1 * b0 + a3 * b1;
|
|
103
|
-
out[2] = a0 * b2 + a2 * b3;
|
|
104
|
-
out[3] = a1 * b2 + a3 * b3;
|
|
105
|
-
out[4] = a0 * b4 + a2 * b5 + a4;
|
|
106
|
-
out[5] = a1 * b4 + a3 * b5 + a5;
|
|
107
|
-
return out;
|
|
172
|
+
let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
|
|
173
|
+
let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];
|
|
174
|
+
out[0] = a0 * b0 + a2 * b1;
|
|
175
|
+
out[1] = a1 * b0 + a3 * b1;
|
|
176
|
+
out[2] = a0 * b2 + a2 * b3;
|
|
177
|
+
out[3] = a1 * b2 + a3 * b3;
|
|
178
|
+
out[4] = a0 * b4 + a2 * b5 + a4;
|
|
179
|
+
out[5] = a1 * b4 + a3 * b5 + a5;
|
|
180
|
+
return out;
|
|
108
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Rotates a mat2d by the given angle
|
|
184
|
+
*
|
|
185
|
+
* @param {mat2d} out the receiving matrix
|
|
186
|
+
* @param {ReadonlyMat2d} a the matrix to rotate
|
|
187
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
188
|
+
* @returns {mat2d} out
|
|
189
|
+
*/
|
|
109
190
|
export function rotate(out, a, rad) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
out[2] = a0 * -s + a2 * c;
|
|
121
|
-
out[3] = a1 * -s + a3 * c;
|
|
122
|
-
out[4] = a4;
|
|
123
|
-
out[5] = a5;
|
|
124
|
-
return out;
|
|
191
|
+
let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
|
|
192
|
+
let s = Math.sin(rad);
|
|
193
|
+
let c = Math.cos(rad);
|
|
194
|
+
out[0] = a0 * c + a2 * s;
|
|
195
|
+
out[1] = a1 * c + a3 * s;
|
|
196
|
+
out[2] = a0 * -s + a2 * c;
|
|
197
|
+
out[3] = a1 * -s + a3 * c;
|
|
198
|
+
out[4] = a4;
|
|
199
|
+
out[5] = a5;
|
|
200
|
+
return out;
|
|
125
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Scales the mat2d by the dimensions in the given vec2
|
|
204
|
+
*
|
|
205
|
+
* @param {mat2d} out the receiving matrix
|
|
206
|
+
* @param {ReadonlyMat2d} a the matrix to translate
|
|
207
|
+
* @param {ReadonlyVec2} v the vec2 to scale the matrix by
|
|
208
|
+
* @returns {mat2d} out
|
|
209
|
+
**/
|
|
126
210
|
export function scale(out, a, v) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
out[1] = a1 * v0;
|
|
137
|
-
out[2] = a2 * v1;
|
|
138
|
-
out[3] = a3 * v1;
|
|
139
|
-
out[4] = a4;
|
|
140
|
-
out[5] = a5;
|
|
141
|
-
return out;
|
|
211
|
+
let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
|
|
212
|
+
let v0 = v[0], v1 = v[1];
|
|
213
|
+
out[0] = a0 * v0;
|
|
214
|
+
out[1] = a1 * v0;
|
|
215
|
+
out[2] = a2 * v1;
|
|
216
|
+
out[3] = a3 * v1;
|
|
217
|
+
out[4] = a4;
|
|
218
|
+
out[5] = a5;
|
|
219
|
+
return out;
|
|
142
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Translates the mat2d by the dimensions in the given vec2
|
|
223
|
+
*
|
|
224
|
+
* @param {mat2d} out the receiving matrix
|
|
225
|
+
* @param {ReadonlyMat2d} a the matrix to translate
|
|
226
|
+
* @param {ReadonlyVec2} v the vec2 to translate the matrix by
|
|
227
|
+
* @returns {mat2d} out
|
|
228
|
+
**/
|
|
143
229
|
export function translate(out, a, v) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
out[1] = a1;
|
|
154
|
-
out[2] = a2;
|
|
155
|
-
out[3] = a3;
|
|
156
|
-
out[4] = a0 * v0 + a2 * v1 + a4;
|
|
157
|
-
out[5] = a1 * v0 + a3 * v1 + a5;
|
|
158
|
-
return out;
|
|
230
|
+
let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
|
|
231
|
+
let v0 = v[0], v1 = v[1];
|
|
232
|
+
out[0] = a0;
|
|
233
|
+
out[1] = a1;
|
|
234
|
+
out[2] = a2;
|
|
235
|
+
out[3] = a3;
|
|
236
|
+
out[4] = a0 * v0 + a2 * v1 + a4;
|
|
237
|
+
out[5] = a1 * v0 + a3 * v1 + a5;
|
|
238
|
+
return out;
|
|
159
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Creates a matrix from a given angle
|
|
242
|
+
* This is equivalent to (but much faster than):
|
|
243
|
+
*
|
|
244
|
+
* mat2d.identity(dest);
|
|
245
|
+
* mat2d.rotate(dest, dest, rad);
|
|
246
|
+
*
|
|
247
|
+
* @param {mat2d} out mat2d receiving operation result
|
|
248
|
+
* @param {Number} rad the angle to rotate the matrix by
|
|
249
|
+
* @returns {mat2d} out
|
|
250
|
+
*/
|
|
160
251
|
export function fromRotation(out, rad) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return out;
|
|
252
|
+
let s = Math.sin(rad), c = Math.cos(rad);
|
|
253
|
+
out[0] = c;
|
|
254
|
+
out[1] = s;
|
|
255
|
+
out[2] = -s;
|
|
256
|
+
out[3] = c;
|
|
257
|
+
out[4] = 0;
|
|
258
|
+
out[5] = 0;
|
|
259
|
+
return out;
|
|
170
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Creates a matrix from a vector scaling
|
|
263
|
+
* This is equivalent to (but much faster than):
|
|
264
|
+
*
|
|
265
|
+
* mat2d.identity(dest);
|
|
266
|
+
* mat2d.scale(dest, dest, vec);
|
|
267
|
+
*
|
|
268
|
+
* @param {mat2d} out mat2d receiving operation result
|
|
269
|
+
* @param {ReadonlyVec2} v Scaling vector
|
|
270
|
+
* @returns {mat2d} out
|
|
271
|
+
*/
|
|
171
272
|
export function fromScaling(out, v) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
273
|
+
out[0] = v[0];
|
|
274
|
+
out[1] = 0;
|
|
275
|
+
out[2] = 0;
|
|
276
|
+
out[3] = v[1];
|
|
277
|
+
out[4] = 0;
|
|
278
|
+
out[5] = 0;
|
|
279
|
+
return out;
|
|
179
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Creates a matrix from a vector translation
|
|
283
|
+
* This is equivalent to (but much faster than):
|
|
284
|
+
*
|
|
285
|
+
* mat2d.identity(dest);
|
|
286
|
+
* mat2d.translate(dest, dest, vec);
|
|
287
|
+
*
|
|
288
|
+
* @param {mat2d} out mat2d receiving operation result
|
|
289
|
+
* @param {ReadonlyVec2} v Translation vector
|
|
290
|
+
* @returns {mat2d} out
|
|
291
|
+
*/
|
|
180
292
|
export function fromTranslation(out, v) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
293
|
+
out[0] = 1;
|
|
294
|
+
out[1] = 0;
|
|
295
|
+
out[2] = 0;
|
|
296
|
+
out[3] = 1;
|
|
297
|
+
out[4] = v[0];
|
|
298
|
+
out[5] = v[1];
|
|
299
|
+
return out;
|
|
188
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Returns a string representation of a mat2d
|
|
303
|
+
*
|
|
304
|
+
* @param {ReadonlyMat2d} a matrix to represent as a string
|
|
305
|
+
* @returns {String} string representation of the matrix
|
|
306
|
+
*/
|
|
189
307
|
export function str(a) {
|
|
190
|
-
|
|
308
|
+
return ('mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ')');
|
|
191
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Returns Frobenius norm of a mat2d
|
|
312
|
+
*
|
|
313
|
+
* @param {ReadonlyMat2d} a the matrix to calculate Frobenius norm of
|
|
314
|
+
* @returns {Number} Frobenius norm
|
|
315
|
+
*/
|
|
192
316
|
export function frob(a) {
|
|
193
|
-
|
|
317
|
+
return Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3] + a[4] * a[4] + a[5] * a[5] + 1);
|
|
194
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Adds two mat2d's
|
|
321
|
+
*
|
|
322
|
+
* @param {mat2d} out the receiving matrix
|
|
323
|
+
* @param {ReadonlyMat2d} a the first operand
|
|
324
|
+
* @param {ReadonlyMat2d} b the second operand
|
|
325
|
+
* @returns {mat2d} out
|
|
326
|
+
*/
|
|
195
327
|
export function add(out, a, b) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
328
|
+
out[0] = a[0] + b[0];
|
|
329
|
+
out[1] = a[1] + b[1];
|
|
330
|
+
out[2] = a[2] + b[2];
|
|
331
|
+
out[3] = a[3] + b[3];
|
|
332
|
+
out[4] = a[4] + b[4];
|
|
333
|
+
out[5] = a[5] + b[5];
|
|
334
|
+
return out;
|
|
203
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Subtracts matrix b from matrix a
|
|
338
|
+
*
|
|
339
|
+
* @param {mat2d} out the receiving matrix
|
|
340
|
+
* @param {ReadonlyMat2d} a the first operand
|
|
341
|
+
* @param {ReadonlyMat2d} b the second operand
|
|
342
|
+
* @returns {mat2d} out
|
|
343
|
+
*/
|
|
204
344
|
export function subtract(out, a, b) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
345
|
+
out[0] = a[0] - b[0];
|
|
346
|
+
out[1] = a[1] - b[1];
|
|
347
|
+
out[2] = a[2] - b[2];
|
|
348
|
+
out[3] = a[3] - b[3];
|
|
349
|
+
out[4] = a[4] - b[4];
|
|
350
|
+
out[5] = a[5] - b[5];
|
|
351
|
+
return out;
|
|
212
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Multiply each element of the matrix by a scalar.
|
|
355
|
+
*
|
|
356
|
+
* @param {mat2d} out the receiving matrix
|
|
357
|
+
* @param {ReadonlyMat2d} a the matrix to scale
|
|
358
|
+
* @param {Number} b amount to scale the matrix's elements by
|
|
359
|
+
* @returns {mat2d} out
|
|
360
|
+
*/
|
|
213
361
|
export function multiplyScalar(out, a, b) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
362
|
+
out[0] = a[0] * b;
|
|
363
|
+
out[1] = a[1] * b;
|
|
364
|
+
out[2] = a[2] * b;
|
|
365
|
+
out[3] = a[3] * b;
|
|
366
|
+
out[4] = a[4] * b;
|
|
367
|
+
out[5] = a[5] * b;
|
|
368
|
+
return out;
|
|
221
369
|
}
|
|
370
|
+
/**
|
|
371
|
+
* Adds two mat2d's after multiplying each element of the second operand by a scalar value.
|
|
372
|
+
*
|
|
373
|
+
* @param {mat2d} out the receiving vector
|
|
374
|
+
* @param {ReadonlyMat2d} a the first operand
|
|
375
|
+
* @param {ReadonlyMat2d} b the second operand
|
|
376
|
+
* @param {Number} scale the amount to scale b's elements by before adding
|
|
377
|
+
* @returns {mat2d} out
|
|
378
|
+
*/
|
|
222
379
|
export function multiplyScalarAndAdd(out, a, b, scale) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
380
|
+
out[0] = a[0] + b[0] * scale;
|
|
381
|
+
out[1] = a[1] + b[1] * scale;
|
|
382
|
+
out[2] = a[2] + b[2] * scale;
|
|
383
|
+
out[3] = a[3] + b[3] * scale;
|
|
384
|
+
out[4] = a[4] + b[4] * scale;
|
|
385
|
+
out[5] = a[5] + b[5] * scale;
|
|
386
|
+
return out;
|
|
230
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
|
|
390
|
+
*
|
|
391
|
+
* @param {ReadonlyMat2d} a The first matrix.
|
|
392
|
+
* @param {ReadonlyMat2d} b The second matrix.
|
|
393
|
+
* @returns {Boolean} True if the matrices are equal, false otherwise.
|
|
394
|
+
*/
|
|
231
395
|
export function exactEquals(a, b) {
|
|
232
|
-
|
|
396
|
+
return (a[0] === b[0] &&
|
|
397
|
+
a[1] === b[1] &&
|
|
398
|
+
a[2] === b[2] &&
|
|
399
|
+
a[3] === b[3] &&
|
|
400
|
+
a[4] === b[4] &&
|
|
401
|
+
a[5] === b[5]);
|
|
233
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Returns whether or not the matrices have approximately the same elements in the same position.
|
|
405
|
+
*
|
|
406
|
+
* @param {ReadonlyMat2d} a The first matrix.
|
|
407
|
+
* @param {ReadonlyMat2d} b The second matrix.
|
|
408
|
+
* @returns {Boolean} True if the matrices are equal, false otherwise.
|
|
409
|
+
*/
|
|
234
410
|
export function equals(a, b) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
b2 = b[2],
|
|
244
|
-
b3 = b[3],
|
|
245
|
-
b4 = b[4],
|
|
246
|
-
b5 = b[5];
|
|
247
|
-
return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5));
|
|
411
|
+
let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3], a4 = a[4], a5 = a[5];
|
|
412
|
+
let b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5];
|
|
413
|
+
return (Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
|
|
414
|
+
Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
|
|
415
|
+
Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
|
|
416
|
+
Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
|
|
417
|
+
Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
|
|
418
|
+
Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)));
|
|
248
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Alias for {@link mat2d.multiply}
|
|
422
|
+
* @function
|
|
423
|
+
*/
|
|
249
424
|
export const mul = multiply;
|
|
425
|
+
/**
|
|
426
|
+
* Alias for {@link mat2d.subtract}
|
|
427
|
+
* @function
|
|
428
|
+
*/
|
|
250
429
|
export const sub = subtract;
|
|
251
|
-
//# sourceMappingURL=mat2d.js.map
|