@math.gl/core 4.0.0 → 4.0.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 +220 -266
- package/dist/classes/base/matrix.d.ts +1 -2
- package/dist/classes/base/matrix.js +52 -53
- package/dist/classes/base/vector.d.ts +1 -2
- package/dist/classes/base/vector.js +121 -135
- package/dist/classes/euler.d.ts +2 -3
- package/dist/classes/euler.js +462 -533
- package/dist/classes/matrix3.d.ts +2 -3
- package/dist/classes/matrix3.js +185 -190
- package/dist/classes/matrix4.d.ts +1 -2
- package/dist/classes/matrix4.js +516 -452
- package/dist/classes/pose.d.ts +4 -5
- package/dist/classes/pose.js +104 -119
- package/dist/classes/quaternion.d.ts +1 -2
- package/dist/classes/quaternion.js +257 -233
- package/dist/classes/spherical-coordinates.d.ts +3 -4
- package/dist/classes/spherical-coordinates.js +138 -147
- package/dist/classes/vector2.d.ts +1 -2
- package/dist/classes/vector2.js +101 -85
- package/dist/classes/vector3.d.ts +1 -2
- package/dist/classes/vector3.js +125 -136
- package/dist/classes/vector4.d.ts +2 -3
- package/dist/classes/vector4.js +106 -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 +2 -1
- package/dist/gl-matrix/wip/mat2.d.ts +0 -1
- package/dist/gl-matrix/wip/mat2.js +333 -157
- package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
- package/dist/gl-matrix/wip/mat2d.js +377 -202
- package/dist/gl-matrix/wip/quat2.d.ts +0 -1
- package/dist/gl-matrix/wip/quat2.js +647 -409
- package/dist/index.cjs +60 -100
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +21 -22
- package/dist/index.js +23 -16
- package/dist/lib/assert.d.ts +0 -1
- package/dist/lib/assert.js +3 -4
- package/dist/lib/common.d.ts +2 -3
- package/dist/lib/common.js +163 -134
- package/dist/lib/gl-matrix-extras.d.ts +0 -1
- package/dist/lib/gl-matrix-extras.js +39 -36
- package/dist/lib/math-utils.d.ts +0 -1
- package/dist/lib/math-utils.js +2 -1
- package/dist/lib/validators.d.ts +0 -1
- package/dist/lib/validators.js +22 -25
- package/package.json +5 -6
- package/src/classes/matrix3.ts +1 -1
- 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/dist/gl-matrix/vec4.js
CHANGED
|
@@ -1,334 +1,620 @@
|
|
|
1
|
+
// @eslint-disable
|
|
2
|
+
// @ts-nocheck
|
|
1
3
|
import * as glMatrix from './common.js';
|
|
4
|
+
/**
|
|
5
|
+
* 4 Dimensional Vector
|
|
6
|
+
* @module vec4
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new, empty vec4
|
|
10
|
+
*
|
|
11
|
+
* @returns {vec4} a new 4D vector
|
|
12
|
+
*/
|
|
2
13
|
export function create() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
const out = new glMatrix.ARRAY_TYPE(4);
|
|
15
|
+
if (glMatrix.ARRAY_TYPE != Float32Array) {
|
|
16
|
+
out[0] = 0;
|
|
17
|
+
out[1] = 0;
|
|
18
|
+
out[2] = 0;
|
|
19
|
+
out[3] = 0;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new vec4 initialized with values from an existing vector
|
|
25
|
+
*
|
|
26
|
+
* @param {ReadonlyVec4} a vector to clone
|
|
27
|
+
* @returns {vec4} a new 4D vector
|
|
28
|
+
*/
|
|
14
29
|
export function clone(a) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
30
|
+
const out = new glMatrix.ARRAY_TYPE(4);
|
|
31
|
+
out[0] = a[0];
|
|
32
|
+
out[1] = a[1];
|
|
33
|
+
out[2] = a[2];
|
|
34
|
+
out[3] = a[3];
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new vec4 initialized with the given values
|
|
39
|
+
*
|
|
40
|
+
* @param {Number} x X component
|
|
41
|
+
* @param {Number} y Y component
|
|
42
|
+
* @param {Number} z Z component
|
|
43
|
+
* @param {Number} w W component
|
|
44
|
+
* @returns {vec4} a new 4D vector
|
|
45
|
+
*/
|
|
22
46
|
export function fromValues(x, y, z, w) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
47
|
+
const out = new glMatrix.ARRAY_TYPE(4);
|
|
48
|
+
out[0] = x;
|
|
49
|
+
out[1] = y;
|
|
50
|
+
out[2] = z;
|
|
51
|
+
out[3] = w;
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Copy the values from one vec4 to another
|
|
56
|
+
*
|
|
57
|
+
* @param {vec4} out the receiving vector
|
|
58
|
+
* @param {ReadonlyVec4} a the source vector
|
|
59
|
+
* @returns {vec4} out
|
|
60
|
+
*/
|
|
30
61
|
export function copy(out, a) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
62
|
+
out[0] = a[0];
|
|
63
|
+
out[1] = a[1];
|
|
64
|
+
out[2] = a[2];
|
|
65
|
+
out[3] = a[3];
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Set the components of a vec4 to the given values
|
|
70
|
+
*
|
|
71
|
+
* @param {vec4} out the receiving vector
|
|
72
|
+
* @param {Number} x X component
|
|
73
|
+
* @param {Number} y Y component
|
|
74
|
+
* @param {Number} z Z component
|
|
75
|
+
* @param {Number} w W component
|
|
76
|
+
* @returns {vec4} out
|
|
77
|
+
*/
|
|
37
78
|
export function set(out, x, y, z, w) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
79
|
+
out[0] = x;
|
|
80
|
+
out[1] = y;
|
|
81
|
+
out[2] = z;
|
|
82
|
+
out[3] = w;
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Adds two vec4's
|
|
87
|
+
*
|
|
88
|
+
* @param {vec4} out the receiving vector
|
|
89
|
+
* @param {ReadonlyVec4} a the first operand
|
|
90
|
+
* @param {ReadonlyVec4} b the second operand
|
|
91
|
+
* @returns {vec4} out
|
|
92
|
+
*/
|
|
44
93
|
export function add(out, a, b) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
94
|
+
out[0] = a[0] + b[0];
|
|
95
|
+
out[1] = a[1] + b[1];
|
|
96
|
+
out[2] = a[2] + b[2];
|
|
97
|
+
out[3] = a[3] + b[3];
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Subtracts vector b from vector a
|
|
102
|
+
*
|
|
103
|
+
* @param {vec4} out the receiving vector
|
|
104
|
+
* @param {ReadonlyVec4} a the first operand
|
|
105
|
+
* @param {ReadonlyVec4} b the second operand
|
|
106
|
+
* @returns {vec4} out
|
|
107
|
+
*/
|
|
51
108
|
export function subtract(out, a, b) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
109
|
+
out[0] = a[0] - b[0];
|
|
110
|
+
out[1] = a[1] - b[1];
|
|
111
|
+
out[2] = a[2] - b[2];
|
|
112
|
+
out[3] = a[3] - b[3];
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Multiplies two vec4's
|
|
117
|
+
*
|
|
118
|
+
* @param {vec4} out the receiving vector
|
|
119
|
+
* @param {ReadonlyVec4} a the first operand
|
|
120
|
+
* @param {ReadonlyVec4} b the second operand
|
|
121
|
+
* @returns {vec4} out
|
|
122
|
+
*/
|
|
58
123
|
export function multiply(out, a, b) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
124
|
+
out[0] = a[0] * b[0];
|
|
125
|
+
out[1] = a[1] * b[1];
|
|
126
|
+
out[2] = a[2] * b[2];
|
|
127
|
+
out[3] = a[3] * b[3];
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Divides two vec4's
|
|
132
|
+
*
|
|
133
|
+
* @param {vec4} out the receiving vector
|
|
134
|
+
* @param {ReadonlyVec4} a the first operand
|
|
135
|
+
* @param {ReadonlyVec4} b the second operand
|
|
136
|
+
* @returns {vec4} out
|
|
137
|
+
*/
|
|
65
138
|
export function divide(out, a, b) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
139
|
+
out[0] = a[0] / b[0];
|
|
140
|
+
out[1] = a[1] / b[1];
|
|
141
|
+
out[2] = a[2] / b[2];
|
|
142
|
+
out[3] = a[3] / b[3];
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Math.ceil the components of a vec4
|
|
147
|
+
*
|
|
148
|
+
* @param {vec4} out the receiving vector
|
|
149
|
+
* @param {ReadonlyVec4} a vector to ceil
|
|
150
|
+
* @returns {vec4} out
|
|
151
|
+
*/
|
|
72
152
|
export function ceil(out, a) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
153
|
+
out[0] = Math.ceil(a[0]);
|
|
154
|
+
out[1] = Math.ceil(a[1]);
|
|
155
|
+
out[2] = Math.ceil(a[2]);
|
|
156
|
+
out[3] = Math.ceil(a[3]);
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Math.floor the components of a vec4
|
|
161
|
+
*
|
|
162
|
+
* @param {vec4} out the receiving vector
|
|
163
|
+
* @param {ReadonlyVec4} a vector to floor
|
|
164
|
+
* @returns {vec4} out
|
|
165
|
+
*/
|
|
79
166
|
export function floor(out, a) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
167
|
+
out[0] = Math.floor(a[0]);
|
|
168
|
+
out[1] = Math.floor(a[1]);
|
|
169
|
+
out[2] = Math.floor(a[2]);
|
|
170
|
+
out[3] = Math.floor(a[3]);
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Returns the minimum of two vec4's
|
|
175
|
+
*
|
|
176
|
+
* @param {vec4} out the receiving vector
|
|
177
|
+
* @param {ReadonlyVec4} a the first operand
|
|
178
|
+
* @param {ReadonlyVec4} b the second operand
|
|
179
|
+
* @returns {vec4} out
|
|
180
|
+
*/
|
|
86
181
|
export function min(out, a, b) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
182
|
+
out[0] = Math.min(a[0], b[0]);
|
|
183
|
+
out[1] = Math.min(a[1], b[1]);
|
|
184
|
+
out[2] = Math.min(a[2], b[2]);
|
|
185
|
+
out[3] = Math.min(a[3], b[3]);
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns the maximum of two vec4's
|
|
190
|
+
*
|
|
191
|
+
* @param {vec4} out the receiving vector
|
|
192
|
+
* @param {ReadonlyVec4} a the first operand
|
|
193
|
+
* @param {ReadonlyVec4} b the second operand
|
|
194
|
+
* @returns {vec4} out
|
|
195
|
+
*/
|
|
93
196
|
export function max(out, a, b) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
197
|
+
out[0] = Math.max(a[0], b[0]);
|
|
198
|
+
out[1] = Math.max(a[1], b[1]);
|
|
199
|
+
out[2] = Math.max(a[2], b[2]);
|
|
200
|
+
out[3] = Math.max(a[3], b[3]);
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* symmetric round the components of a vec4
|
|
205
|
+
*
|
|
206
|
+
* @param {vec4} out the receiving vector
|
|
207
|
+
* @param {ReadonlyVec4} a vector to round
|
|
208
|
+
* @returns {vec4} out
|
|
209
|
+
*/
|
|
100
210
|
export function round(out, a) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
211
|
+
out[0] = glMatrix.round(a[0]);
|
|
212
|
+
out[1] = glMatrix.round(a[1]);
|
|
213
|
+
out[2] = glMatrix.round(a[2]);
|
|
214
|
+
out[3] = glMatrix.round(a[3]);
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Scales a vec4 by a scalar number
|
|
219
|
+
*
|
|
220
|
+
* @param {vec4} out the receiving vector
|
|
221
|
+
* @param {ReadonlyVec4} a the vector to scale
|
|
222
|
+
* @param {Number} b amount to scale the vector by
|
|
223
|
+
* @returns {vec4} out
|
|
224
|
+
*/
|
|
107
225
|
export function scale(out, a, b) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
226
|
+
out[0] = a[0] * b;
|
|
227
|
+
out[1] = a[1] * b;
|
|
228
|
+
out[2] = a[2] * b;
|
|
229
|
+
out[3] = a[3] * b;
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Adds two vec4's after scaling the second operand by a scalar value
|
|
234
|
+
*
|
|
235
|
+
* @param {vec4} out the receiving vector
|
|
236
|
+
* @param {ReadonlyVec4} a the first operand
|
|
237
|
+
* @param {ReadonlyVec4} b the second operand
|
|
238
|
+
* @param {Number} scale the amount to scale b by before adding
|
|
239
|
+
* @returns {vec4} out
|
|
240
|
+
*/
|
|
114
241
|
export function scaleAndAdd(out, a, b, scale) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
242
|
+
out[0] = a[0] + b[0] * scale;
|
|
243
|
+
out[1] = a[1] + b[1] * scale;
|
|
244
|
+
out[2] = a[2] + b[2] * scale;
|
|
245
|
+
out[3] = a[3] + b[3] * scale;
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Calculates the euclidian distance between two vec4's
|
|
250
|
+
*
|
|
251
|
+
* @param {ReadonlyVec4} a the first operand
|
|
252
|
+
* @param {ReadonlyVec4} b the second operand
|
|
253
|
+
* @returns {Number} distance between a and b
|
|
254
|
+
*/
|
|
121
255
|
export function distance(a, b) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
256
|
+
const x = b[0] - a[0];
|
|
257
|
+
const y = b[1] - a[1];
|
|
258
|
+
const z = b[2] - a[2];
|
|
259
|
+
const w = b[3] - a[3];
|
|
260
|
+
return Math.sqrt(x * x + y * y + z * z + w * w);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Calculates the squared euclidian distance between two vec4's
|
|
264
|
+
*
|
|
265
|
+
* @param {ReadonlyVec4} a the first operand
|
|
266
|
+
* @param {ReadonlyVec4} b the second operand
|
|
267
|
+
* @returns {Number} squared distance between a and b
|
|
268
|
+
*/
|
|
128
269
|
export function squaredDistance(a, b) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
270
|
+
const x = b[0] - a[0];
|
|
271
|
+
const y = b[1] - a[1];
|
|
272
|
+
const z = b[2] - a[2];
|
|
273
|
+
const w = b[3] - a[3];
|
|
274
|
+
return x * x + y * y + z * z + w * w;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Calculates the length of a vec4
|
|
278
|
+
*
|
|
279
|
+
* @param {ReadonlyVec4} a vector to calculate length of
|
|
280
|
+
* @returns {Number} length of a
|
|
281
|
+
*/
|
|
135
282
|
export function length(a) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
283
|
+
const x = a[0];
|
|
284
|
+
const y = a[1];
|
|
285
|
+
const z = a[2];
|
|
286
|
+
const w = a[3];
|
|
287
|
+
return Math.sqrt(x * x + y * y + z * z + w * w);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Calculates the squared length of a vec4
|
|
291
|
+
*
|
|
292
|
+
* @param {ReadonlyVec4} a vector to calculate squared length of
|
|
293
|
+
* @returns {Number} squared length of a
|
|
294
|
+
*/
|
|
142
295
|
export function squaredLength(a) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
296
|
+
const x = a[0];
|
|
297
|
+
const y = a[1];
|
|
298
|
+
const z = a[2];
|
|
299
|
+
const w = a[3];
|
|
300
|
+
return x * x + y * y + z * z + w * w;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Negates the components of a vec4
|
|
304
|
+
*
|
|
305
|
+
* @param {vec4} out the receiving vector
|
|
306
|
+
* @param {ReadonlyVec4} a vector to negate
|
|
307
|
+
* @returns {vec4} out
|
|
308
|
+
*/
|
|
149
309
|
export function negate(out, a) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
310
|
+
out[0] = -a[0];
|
|
311
|
+
out[1] = -a[1];
|
|
312
|
+
out[2] = -a[2];
|
|
313
|
+
out[3] = -a[3];
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Returns the inverse of the components of a vec4
|
|
318
|
+
*
|
|
319
|
+
* @param {vec4} out the receiving vector
|
|
320
|
+
* @param {ReadonlyVec4} a vector to invert
|
|
321
|
+
* @returns {vec4} out
|
|
322
|
+
*/
|
|
156
323
|
export function inverse(out, a) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
324
|
+
out[0] = 1.0 / a[0];
|
|
325
|
+
out[1] = 1.0 / a[1];
|
|
326
|
+
out[2] = 1.0 / a[2];
|
|
327
|
+
out[3] = 1.0 / a[3];
|
|
328
|
+
return out;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Normalize a vec4
|
|
332
|
+
*
|
|
333
|
+
* @param {vec4} out the receiving vector
|
|
334
|
+
* @param {ReadonlyVec4} a vector to normalize
|
|
335
|
+
* @returns {vec4} out
|
|
336
|
+
*/
|
|
163
337
|
export function normalize(out, a) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
338
|
+
const x = a[0];
|
|
339
|
+
const y = a[1];
|
|
340
|
+
const z = a[2];
|
|
341
|
+
const w = a[3];
|
|
342
|
+
let len = x * x + y * y + z * z + w * w;
|
|
343
|
+
if (len > 0) {
|
|
344
|
+
len = 1 / Math.sqrt(len);
|
|
345
|
+
}
|
|
346
|
+
out[0] = x * len;
|
|
347
|
+
out[1] = y * len;
|
|
348
|
+
out[2] = z * len;
|
|
349
|
+
out[3] = w * len;
|
|
350
|
+
return out;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Calculates the dot product of two vec4's
|
|
354
|
+
*
|
|
355
|
+
* @param {ReadonlyVec4} a the first operand
|
|
356
|
+
* @param {ReadonlyVec4} b the second operand
|
|
357
|
+
* @returns {Number} dot product of a and b
|
|
358
|
+
*/
|
|
180
359
|
export function dot(a, b) {
|
|
181
|
-
|
|
182
|
-
}
|
|
360
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Returns the cross-product of three vectors in a 4-dimensional space
|
|
364
|
+
*
|
|
365
|
+
* @param {ReadonlyVec4} result the receiving vector
|
|
366
|
+
* @param {ReadonlyVec4} U the first vector
|
|
367
|
+
* @param {ReadonlyVec4} V the second vector
|
|
368
|
+
* @param {ReadonlyVec4} W the third vector
|
|
369
|
+
* @returns {vec4} result
|
|
370
|
+
*/
|
|
183
371
|
export function cross(out, u, v, w) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
372
|
+
const A = v[0] * w[1] - v[1] * w[0];
|
|
373
|
+
const B = v[0] * w[2] - v[2] * w[0];
|
|
374
|
+
const C = v[0] * w[3] - v[3] * w[0];
|
|
375
|
+
const D = v[1] * w[2] - v[2] * w[1];
|
|
376
|
+
const E = v[1] * w[3] - v[3] * w[1];
|
|
377
|
+
const F = v[2] * w[3] - v[3] * w[2];
|
|
378
|
+
const G = u[0];
|
|
379
|
+
const H = u[1];
|
|
380
|
+
const I = u[2];
|
|
381
|
+
const J = u[3];
|
|
382
|
+
out[0] = H * F - I * E + J * D;
|
|
383
|
+
out[1] = -(G * F) + I * C - J * B;
|
|
384
|
+
out[2] = G * E - H * C + J * A;
|
|
385
|
+
out[3] = -(G * D) + H * B - I * A;
|
|
386
|
+
return out;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Performs a linear interpolation between two vec4's
|
|
390
|
+
*
|
|
391
|
+
* @param {vec4} out the receiving vector
|
|
392
|
+
* @param {ReadonlyVec4} a the first operand
|
|
393
|
+
* @param {ReadonlyVec4} b the second operand
|
|
394
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
395
|
+
* @returns {vec4} out
|
|
396
|
+
*/
|
|
200
397
|
export function lerp(out, a, b, t) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
398
|
+
const ax = a[0];
|
|
399
|
+
const ay = a[1];
|
|
400
|
+
const az = a[2];
|
|
401
|
+
const aw = a[3];
|
|
402
|
+
out[0] = ax + t * (b[0] - ax);
|
|
403
|
+
out[1] = ay + t * (b[1] - ay);
|
|
404
|
+
out[2] = az + t * (b[2] - az);
|
|
405
|
+
out[3] = aw + t * (b[3] - aw);
|
|
406
|
+
return out;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Generates a random vector with the given scale
|
|
410
|
+
*
|
|
411
|
+
* @param {vec4} out the receiving vector
|
|
412
|
+
* @param {Number} [scale] Length of the resulting vector. If omitted, a unit vector will be returned
|
|
413
|
+
* @returns {vec4} out
|
|
414
|
+
*/
|
|
211
415
|
export function random(out, scale) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
416
|
+
scale = scale === undefined ? 1.0 : scale;
|
|
417
|
+
// Marsaglia, George. Choosing a Point from the Surface of a
|
|
418
|
+
// Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.
|
|
419
|
+
// http://projecteuclid.org/euclid.aoms/1177692644;
|
|
420
|
+
let v1;
|
|
421
|
+
let v2;
|
|
422
|
+
let v3;
|
|
423
|
+
let v4;
|
|
424
|
+
let s1;
|
|
425
|
+
let s2;
|
|
426
|
+
do {
|
|
427
|
+
v1 = glMatrix.RANDOM() * 2 - 1;
|
|
428
|
+
v2 = glMatrix.RANDOM() * 2 - 1;
|
|
429
|
+
s1 = v1 * v1 + v2 * v2;
|
|
430
|
+
} while (s1 >= 1);
|
|
431
|
+
do {
|
|
432
|
+
v3 = glMatrix.RANDOM() * 2 - 1;
|
|
433
|
+
v4 = glMatrix.RANDOM() * 2 - 1;
|
|
434
|
+
s2 = v3 * v3 + v4 * v4;
|
|
435
|
+
} while (s2 >= 1);
|
|
436
|
+
const d = Math.sqrt((1 - s1) / s2);
|
|
437
|
+
out[0] = scale * v1;
|
|
438
|
+
out[1] = scale * v2;
|
|
439
|
+
out[2] = scale * v3 * d;
|
|
440
|
+
out[3] = scale * v4 * d;
|
|
441
|
+
return out;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Transforms the vec4 with a mat4.
|
|
445
|
+
*
|
|
446
|
+
* @param {vec4} out the receiving vector
|
|
447
|
+
* @param {ReadonlyVec4} a the vector to transform
|
|
448
|
+
* @param {ReadonlyMat4} m matrix to transform with
|
|
449
|
+
* @returns {vec4} out
|
|
450
|
+
*/
|
|
239
451
|
export function transformMat4(out, a, m) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
452
|
+
const x = a[0];
|
|
453
|
+
const y = a[1];
|
|
454
|
+
const z = a[2];
|
|
455
|
+
const w = a[3];
|
|
456
|
+
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
|
|
457
|
+
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
|
|
458
|
+
out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
|
|
459
|
+
out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
|
|
460
|
+
return out;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Transforms the vec4 with a quat
|
|
464
|
+
*
|
|
465
|
+
* @param {vec4} out the receiving vector
|
|
466
|
+
* @param {ReadonlyVec4} a the vector to transform
|
|
467
|
+
* @param {ReadonlyQuat} q quaternion to transform with
|
|
468
|
+
* @returns {vec4} out
|
|
469
|
+
*/
|
|
250
470
|
export function transformQuat(out, a, q) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
471
|
+
const x = a[0];
|
|
472
|
+
const y = a[1];
|
|
473
|
+
const z = a[2];
|
|
474
|
+
const qx = q[0];
|
|
475
|
+
const qy = q[1];
|
|
476
|
+
const qz = q[2];
|
|
477
|
+
const qw = q[3];
|
|
478
|
+
// calculate quat * vec
|
|
479
|
+
const ix = qw * x + qy * z - qz * y;
|
|
480
|
+
const iy = qw * y + qz * x - qx * z;
|
|
481
|
+
const iz = qw * z + qx * y - qy * x;
|
|
482
|
+
const iw = -qx * x - qy * y - qz * z;
|
|
483
|
+
// calculate result * inverse quat
|
|
484
|
+
out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
|
485
|
+
out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
|
486
|
+
out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
|
487
|
+
out[3] = a[3];
|
|
488
|
+
return out;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Set the components of a vec4 to zero
|
|
492
|
+
*
|
|
493
|
+
* @param {vec4} out the receiving vector
|
|
494
|
+
* @returns {vec4} out
|
|
495
|
+
*/
|
|
268
496
|
export function zero(out) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
497
|
+
out[0] = 0.0;
|
|
498
|
+
out[1] = 0.0;
|
|
499
|
+
out[2] = 0.0;
|
|
500
|
+
out[3] = 0.0;
|
|
501
|
+
return out;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Returns a string representation of a vector
|
|
505
|
+
*
|
|
506
|
+
* @param {ReadonlyVec4} a vector to represent as a string
|
|
507
|
+
* @returns {String} string representation of the vector
|
|
508
|
+
*/
|
|
275
509
|
export function str(a) {
|
|
276
|
-
|
|
277
|
-
}
|
|
510
|
+
return `vec4(${a[0]}, ${a[1]}, ${a[2]}, ${a[3]})`;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
|
|
514
|
+
*
|
|
515
|
+
* @param {ReadonlyVec4} a The first vector.
|
|
516
|
+
* @param {ReadonlyVec4} b The second vector.
|
|
517
|
+
* @returns {Boolean} True if the vectors are equal, false otherwise.
|
|
518
|
+
*/
|
|
278
519
|
export function exactEquals(a, b) {
|
|
279
|
-
|
|
280
|
-
}
|
|
520
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Returns whether or not the vectors have approximately the same elements in the same position.
|
|
524
|
+
*
|
|
525
|
+
* @param {ReadonlyVec4} a The first vector.
|
|
526
|
+
* @param {ReadonlyVec4} b The second vector.
|
|
527
|
+
* @returns {Boolean} True if the vectors are equal, false otherwise.
|
|
528
|
+
*/
|
|
281
529
|
export function equals(a, b) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
530
|
+
const a0 = a[0];
|
|
531
|
+
const a1 = a[1];
|
|
532
|
+
const a2 = a[2];
|
|
533
|
+
const a3 = a[3];
|
|
534
|
+
const b0 = b[0];
|
|
535
|
+
const b1 = b[1];
|
|
536
|
+
const b2 = b[2];
|
|
537
|
+
const b3 = b[3];
|
|
538
|
+
return (Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
|
|
539
|
+
Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
|
|
540
|
+
Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
|
|
541
|
+
Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)));
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Alias for {@link vec4.subtract}
|
|
545
|
+
* @function
|
|
546
|
+
*/
|
|
292
547
|
export const sub = subtract;
|
|
548
|
+
/**
|
|
549
|
+
* Alias for {@link vec4.multiply}
|
|
550
|
+
* @function
|
|
551
|
+
*/
|
|
293
552
|
export const mul = multiply;
|
|
553
|
+
/**
|
|
554
|
+
* Alias for {@link vec4.divide}
|
|
555
|
+
* @function
|
|
556
|
+
*/
|
|
294
557
|
export const div = divide;
|
|
558
|
+
/**
|
|
559
|
+
* Alias for {@link vec4.distance}
|
|
560
|
+
* @function
|
|
561
|
+
*/
|
|
295
562
|
export const dist = distance;
|
|
563
|
+
/**
|
|
564
|
+
* Alias for {@link vec4.squaredDistance}
|
|
565
|
+
* @function
|
|
566
|
+
*/
|
|
296
567
|
export const sqrDist = squaredDistance;
|
|
568
|
+
/**
|
|
569
|
+
* Alias for {@link vec4.length}
|
|
570
|
+
* @function
|
|
571
|
+
*/
|
|
297
572
|
export const len = length;
|
|
573
|
+
/**
|
|
574
|
+
* Alias for {@link vec4.squaredLength}
|
|
575
|
+
* @function
|
|
576
|
+
*/
|
|
298
577
|
export const sqrLen = squaredLength;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
578
|
+
/**
|
|
579
|
+
* Perform some operation over an array of vec4s.
|
|
580
|
+
*
|
|
581
|
+
* @param {Array} a the array of vectors to iterate over
|
|
582
|
+
* @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
|
|
583
|
+
* @param {Number} offset Number of elements to skip at the beginning of the array
|
|
584
|
+
* @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
|
|
585
|
+
* @param {Function} fn Function to call for each vector in the array
|
|
586
|
+
* @param {Object} [arg] additional argument to pass to fn
|
|
587
|
+
* @returns {Array} a
|
|
588
|
+
* @function
|
|
589
|
+
*/
|
|
590
|
+
export const forEach = (function () {
|
|
591
|
+
const vec = create();
|
|
592
|
+
return function (a, stride, offset, count, fn, arg) {
|
|
593
|
+
let i;
|
|
594
|
+
let l;
|
|
595
|
+
if (!stride) {
|
|
596
|
+
stride = 4;
|
|
597
|
+
}
|
|
598
|
+
if (!offset) {
|
|
599
|
+
offset = 0;
|
|
600
|
+
}
|
|
601
|
+
if (count) {
|
|
602
|
+
l = Math.min(count * stride + offset, a.length);
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
l = a.length;
|
|
606
|
+
}
|
|
607
|
+
for (i = offset; i < l; i += stride) {
|
|
608
|
+
vec[0] = a[i];
|
|
609
|
+
vec[1] = a[i + 1];
|
|
610
|
+
vec[2] = a[i + 2];
|
|
611
|
+
vec[3] = a[i + 3];
|
|
612
|
+
fn(vec, vec, arg);
|
|
613
|
+
a[i] = vec[0];
|
|
614
|
+
a[i + 1] = vec[1];
|
|
615
|
+
a[i + 2] = vec[2];
|
|
616
|
+
a[i + 3] = vec[3];
|
|
617
|
+
}
|
|
618
|
+
return a;
|
|
619
|
+
};
|
|
620
|
+
})();
|