@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/vec2.js
CHANGED
|
@@ -1,257 +1,574 @@
|
|
|
1
|
+
// @eslint-disable
|
|
2
|
+
// @ts-nocheck
|
|
1
3
|
import * as glMatrix from './common.js';
|
|
4
|
+
/**
|
|
5
|
+
* 2 Dimensional Vector
|
|
6
|
+
* @module vec2
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new, empty vec2
|
|
10
|
+
*
|
|
11
|
+
* @returns {NumericArray} a new 2D vector
|
|
12
|
+
*/
|
|
2
13
|
export function create() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
const out = new glMatrix.ARRAY_TYPE(2);
|
|
15
|
+
if (glMatrix.ARRAY_TYPE != Float32Array) {
|
|
16
|
+
out[0] = 0;
|
|
17
|
+
out[1] = 0;
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new vec2 initialized with values from an existing vector
|
|
23
|
+
*
|
|
24
|
+
* @param {Readonly<NumericArray>} a vector to clone
|
|
25
|
+
* @returns {NumericArray} a new 2D vector
|
|
26
|
+
*/
|
|
12
27
|
export function clone(a) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
28
|
+
const out = new glMatrix.ARRAY_TYPE(2);
|
|
29
|
+
out[0] = a[0];
|
|
30
|
+
out[1] = a[1];
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new vec2 initialized with the given values
|
|
35
|
+
*
|
|
36
|
+
* @param {Number} x X component
|
|
37
|
+
* @param {Number} y Y component
|
|
38
|
+
* @returns {NumericArray} a new 2D vector
|
|
39
|
+
*/
|
|
18
40
|
export function fromValues(x, y) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
41
|
+
const out = new glMatrix.ARRAY_TYPE(2);
|
|
42
|
+
out[0] = x;
|
|
43
|
+
out[1] = y;
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Copy the values from one vec2 to another
|
|
48
|
+
*
|
|
49
|
+
* @param {NumericArray} out the receiving vector
|
|
50
|
+
* @param {Readonly<NumericArray>} a the source vector
|
|
51
|
+
* @returns {NumericArray} out
|
|
52
|
+
*/
|
|
24
53
|
export function copy(out, a) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
54
|
+
out[0] = a[0];
|
|
55
|
+
out[1] = a[1];
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Set the components of a vec2 to the given values
|
|
60
|
+
*
|
|
61
|
+
* @param {NumericArray} out the receiving vector
|
|
62
|
+
* @param {Number} x X component
|
|
63
|
+
* @param {Number} y Y component
|
|
64
|
+
* @returns {NumericArray} out
|
|
65
|
+
*/
|
|
29
66
|
export function set(out, x, y) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
67
|
+
out[0] = x;
|
|
68
|
+
out[1] = y;
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Adds two vec2's
|
|
73
|
+
*
|
|
74
|
+
* @param {NumericArray} out the receiving vector
|
|
75
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
76
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
77
|
+
* @returns {NumericArray} out
|
|
78
|
+
*/
|
|
34
79
|
export function add(out, a, b) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
80
|
+
out[0] = a[0] + b[0];
|
|
81
|
+
out[1] = a[1] + b[1];
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Subtracts vector b from vector a
|
|
86
|
+
*
|
|
87
|
+
* @param {NumericArray} out the receiving vector
|
|
88
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
89
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
90
|
+
* @returns {NumericArray} out
|
|
91
|
+
*/
|
|
39
92
|
export function subtract(out, a, b) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
93
|
+
out[0] = a[0] - b[0];
|
|
94
|
+
out[1] = a[1] - b[1];
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Multiplies two vec2's
|
|
99
|
+
*
|
|
100
|
+
* @param {NumericArray} out the receiving vector
|
|
101
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
102
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
103
|
+
* @returns {NumericArray} out
|
|
104
|
+
*/
|
|
44
105
|
export function multiply(out, a, b) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
106
|
+
out[0] = a[0] * b[0];
|
|
107
|
+
out[1] = a[1] * b[1];
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Divides two vec2's
|
|
112
|
+
*
|
|
113
|
+
* @param {NumericArray} out the receiving vector
|
|
114
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
115
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
116
|
+
* @returns {NumericArray} out
|
|
117
|
+
*/
|
|
49
118
|
export function divide(out, a, b) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
119
|
+
out[0] = a[0] / b[0];
|
|
120
|
+
out[1] = a[1] / b[1];
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Math.ceil the components of a vec2
|
|
125
|
+
*
|
|
126
|
+
* @param {NumericArray} out the receiving vector
|
|
127
|
+
* @param {Readonly<NumericArray>} a vector to ceil
|
|
128
|
+
* @returns {NumericArray} out
|
|
129
|
+
*/
|
|
54
130
|
export function ceil(out, a) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
131
|
+
out[0] = Math.ceil(a[0]);
|
|
132
|
+
out[1] = Math.ceil(a[1]);
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Math.floor the components of a vec2
|
|
137
|
+
*
|
|
138
|
+
* @param {NumericArray} out the receiving vector
|
|
139
|
+
* @param {Readonly<NumericArray>} a vector to floor
|
|
140
|
+
* @returns {NumericArray} out
|
|
141
|
+
*/
|
|
59
142
|
export function floor(out, a) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
143
|
+
out[0] = Math.floor(a[0]);
|
|
144
|
+
out[1] = Math.floor(a[1]);
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Returns the minimum of two vec2's
|
|
149
|
+
*
|
|
150
|
+
* @param {NumericArray} out the receiving vector
|
|
151
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
152
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
153
|
+
* @returns {NumericArray} out
|
|
154
|
+
*/
|
|
64
155
|
export function min(out, a, b) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
156
|
+
out[0] = Math.min(a[0], b[0]);
|
|
157
|
+
out[1] = Math.min(a[1], b[1]);
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the maximum of two vec2's
|
|
162
|
+
*
|
|
163
|
+
* @param {NumericArray} out the receiving vector
|
|
164
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
165
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
166
|
+
* @returns {NumericArray} out
|
|
167
|
+
*/
|
|
69
168
|
export function max(out, a, b) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
169
|
+
out[0] = Math.max(a[0], b[0]);
|
|
170
|
+
out[1] = Math.max(a[1], b[1]);
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* symmetric round the components of a vec2
|
|
175
|
+
*
|
|
176
|
+
* @param {NumericArray} out the receiving vector
|
|
177
|
+
* @param {Readonly<NumericArray>} a vector to round
|
|
178
|
+
* @returns {NumericArray} out
|
|
179
|
+
*/
|
|
74
180
|
export function round(out, a) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
181
|
+
out[0] = glMatrix.round(a[0]);
|
|
182
|
+
out[1] = glMatrix.round(a[1]);
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Scales a vec2 by a scalar number
|
|
187
|
+
*
|
|
188
|
+
* @param {NumericArray} out the receiving vector
|
|
189
|
+
* @param {Readonly<NumericArray>} a the vector to scale
|
|
190
|
+
* @param {Number} b amount to scale the vector by
|
|
191
|
+
* @returns {NumericArray} out
|
|
192
|
+
*/
|
|
79
193
|
export function scale(out, a, b) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
194
|
+
out[0] = a[0] * b;
|
|
195
|
+
out[1] = a[1] * b;
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Adds two vec2's after scaling the second operand by a scalar value
|
|
200
|
+
*
|
|
201
|
+
* @param {NumericArray} out the receiving vector
|
|
202
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
203
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
204
|
+
* @param {Number} scale the amount to scale b by before adding
|
|
205
|
+
* @returns {NumericArray} out
|
|
206
|
+
*/
|
|
84
207
|
export function scaleAndAdd(out, a, b, scale) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
208
|
+
out[0] = a[0] + b[0] * scale;
|
|
209
|
+
out[1] = a[1] + b[1] * scale;
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Calculates the euclidian distance between two vec2's
|
|
214
|
+
*
|
|
215
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
216
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
217
|
+
* @returns {Number} distance between a and b
|
|
218
|
+
*/
|
|
89
219
|
export function distance(a, b) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
220
|
+
const x = b[0] - a[0];
|
|
221
|
+
const y = b[1] - a[1];
|
|
222
|
+
return Math.sqrt(x * x + y * y);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Calculates the squared euclidian distance between two vec2's
|
|
226
|
+
*
|
|
227
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
228
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
229
|
+
* @returns {Number} squared distance between a and b
|
|
230
|
+
*/
|
|
94
231
|
export function squaredDistance(a, b) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
232
|
+
const x = b[0] - a[0];
|
|
233
|
+
const y = b[1] - a[1];
|
|
234
|
+
return x * x + y * y;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Calculates the length of a vec2
|
|
238
|
+
*
|
|
239
|
+
* @param {Readonly<NumericArray>} a vector to calculate length of
|
|
240
|
+
* @returns {Number} length of a
|
|
241
|
+
*/
|
|
99
242
|
export function length(a) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
243
|
+
const x = a[0];
|
|
244
|
+
const y = a[1];
|
|
245
|
+
return Math.sqrt(x * x + y * y);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Calculates the squared length of a vec2
|
|
249
|
+
*
|
|
250
|
+
* @param {Readonly<NumericArray>} a vector to calculate squared length of
|
|
251
|
+
* @returns {Number} squared length of a
|
|
252
|
+
*/
|
|
104
253
|
export function squaredLength(a) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
254
|
+
const x = a[0];
|
|
255
|
+
const y = a[1];
|
|
256
|
+
return x * x + y * y;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Negates the components of a vec2
|
|
260
|
+
*
|
|
261
|
+
* @param {NumericArray} out the receiving vector
|
|
262
|
+
* @param {Readonly<NumericArray>} a vector to negate
|
|
263
|
+
* @returns {NumericArray} out
|
|
264
|
+
*/
|
|
109
265
|
export function negate(out, a) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
266
|
+
out[0] = -a[0];
|
|
267
|
+
out[1] = -a[1];
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Returns the inverse of the components of a vec2
|
|
272
|
+
*
|
|
273
|
+
* @param {NumericArray} out the receiving vector
|
|
274
|
+
* @param {Readonly<NumericArray>} a vector to invert
|
|
275
|
+
* @returns {NumericArray} out
|
|
276
|
+
*/
|
|
114
277
|
export function inverse(out, a) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
278
|
+
out[0] = 1.0 / a[0];
|
|
279
|
+
out[1] = 1.0 / a[1];
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Normalize a vec2
|
|
284
|
+
*
|
|
285
|
+
* @param {NumericArray} out the receiving vector
|
|
286
|
+
* @param {Readonly<NumericArray>} a vector to normalize
|
|
287
|
+
* @returns {NumericArray} out
|
|
288
|
+
*/
|
|
119
289
|
export function normalize(out, a) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
290
|
+
const x = a[0];
|
|
291
|
+
const y = a[1];
|
|
292
|
+
let len = x * x + y * y;
|
|
293
|
+
if (len > 0) {
|
|
294
|
+
// TODO: evaluate use of glm_invsqrt here?
|
|
295
|
+
len = 1 / Math.sqrt(len);
|
|
296
|
+
}
|
|
297
|
+
out[0] = a[0] * len;
|
|
298
|
+
out[1] = a[1] * len;
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Calculates the dot product of two vec2's
|
|
303
|
+
*
|
|
304
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
305
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
306
|
+
* @returns {Number} dot product of a and b
|
|
307
|
+
*/
|
|
132
308
|
export function dot(a, b) {
|
|
133
|
-
|
|
134
|
-
}
|
|
309
|
+
return a[0] * b[0] + a[1] * b[1];
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Computes the cross product of two vec2's
|
|
313
|
+
* Note that the cross product must by definition produce a 3D vector
|
|
314
|
+
*
|
|
315
|
+
* @param {vec3} out the receiving vector
|
|
316
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
317
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
318
|
+
* @returns {vec3} out
|
|
319
|
+
*/
|
|
135
320
|
export function cross(out, a, b) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
321
|
+
const z = a[0] * b[1] - a[1] * b[0];
|
|
322
|
+
out[0] = out[1] = 0;
|
|
323
|
+
out[2] = z;
|
|
324
|
+
return out;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Performs a linear interpolation between two vec2's
|
|
328
|
+
*
|
|
329
|
+
* @param {NumericArray} out the receiving vector
|
|
330
|
+
* @param {Readonly<NumericArray>} a the first operand
|
|
331
|
+
* @param {Readonly<NumericArray>} b the second operand
|
|
332
|
+
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
333
|
+
* @returns {NumericArray} out
|
|
334
|
+
*/
|
|
141
335
|
export function lerp(out, a, b, t) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
336
|
+
const ax = a[0];
|
|
337
|
+
const ay = a[1];
|
|
338
|
+
out[0] = ax + t * (b[0] - ax);
|
|
339
|
+
out[1] = ay + t * (b[1] - ay);
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Generates a random vector with the given scale
|
|
344
|
+
*
|
|
345
|
+
* @param {NumericArray} out the receiving vector
|
|
346
|
+
* @param {Number} [scale] Length of the resulting vector. If omitted, a unit vector will be returned
|
|
347
|
+
* @returns {NumericArray} out
|
|
348
|
+
*/
|
|
148
349
|
export function random(out, scale) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
350
|
+
scale = scale === undefined ? 1.0 : scale;
|
|
351
|
+
const r = glMatrix.RANDOM() * 2.0 * Math.PI;
|
|
352
|
+
out[0] = Math.cos(r) * scale;
|
|
353
|
+
out[1] = Math.sin(r) * scale;
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Transforms the vec2 with a mat2
|
|
358
|
+
*
|
|
359
|
+
* @param {NumericArray} out the receiving vector
|
|
360
|
+
* @param {Readonly<NumericArray>} a the vector to transform
|
|
361
|
+
* @param {ReadonlyMat2} m matrix to transform with
|
|
362
|
+
* @returns {NumericArray} out
|
|
363
|
+
*/
|
|
155
364
|
export function transformMat2(out, a, m) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
365
|
+
const x = a[0];
|
|
366
|
+
const y = a[1];
|
|
367
|
+
out[0] = m[0] * x + m[2] * y;
|
|
368
|
+
out[1] = m[1] * x + m[3] * y;
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Transforms the vec2 with a mat2d
|
|
373
|
+
*
|
|
374
|
+
* @param {NumericArray} out the receiving vector
|
|
375
|
+
* @param {Readonly<NumericArray>} a the vector to transform
|
|
376
|
+
* @param {ReadonlyMat2d} m matrix to transform with
|
|
377
|
+
* @returns {NumericArray} out
|
|
378
|
+
*/
|
|
162
379
|
export function transformMat2d(out, a, m) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
380
|
+
const x = a[0];
|
|
381
|
+
const y = a[1];
|
|
382
|
+
out[0] = m[0] * x + m[2] * y + m[4];
|
|
383
|
+
out[1] = m[1] * x + m[3] * y + m[5];
|
|
384
|
+
return out;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Transforms the vec2 with a mat3
|
|
388
|
+
* 3rd vector component is implicitly '1'
|
|
389
|
+
*
|
|
390
|
+
* @param {NumericArray} out the receiving vector
|
|
391
|
+
* @param {Readonly<NumericArray>} a the vector to transform
|
|
392
|
+
* @param {ReadonlyMat3} m matrix to transform with
|
|
393
|
+
* @returns {NumericArray} out
|
|
394
|
+
*/
|
|
169
395
|
export function transformMat3(out, a, m) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
396
|
+
const x = a[0];
|
|
397
|
+
const y = a[1];
|
|
398
|
+
out[0] = m[0] * x + m[3] * y + m[6];
|
|
399
|
+
out[1] = m[1] * x + m[4] * y + m[7];
|
|
400
|
+
return out;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Transforms the vec2 with a mat4
|
|
404
|
+
* 3rd vector component is implicitly '0'
|
|
405
|
+
* 4th vector component is implicitly '1'
|
|
406
|
+
*
|
|
407
|
+
* @param {NumericArray} out the receiving vector
|
|
408
|
+
* @param {Readonly<NumericArray>} a the vector to transform
|
|
409
|
+
* @param {ReadonlyMat4} m matrix to transform with
|
|
410
|
+
* @returns {NumericArray} out
|
|
411
|
+
*/
|
|
176
412
|
export function transformMat4(out, a, m) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
413
|
+
const x = a[0];
|
|
414
|
+
const y = a[1];
|
|
415
|
+
out[0] = m[0] * x + m[4] * y + m[12];
|
|
416
|
+
out[1] = m[1] * x + m[5] * y + m[13];
|
|
417
|
+
return out;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Rotate a 2D vector
|
|
421
|
+
* @param {NumericArray} out The receiving vec2
|
|
422
|
+
* @param {Readonly<NumericArray>} a The vec2 point to rotate
|
|
423
|
+
* @param {Readonly<NumericArray>} b The origin of the rotation
|
|
424
|
+
* @param {Number} rad The angle of rotation in radians
|
|
425
|
+
* @returns {NumericArray} out
|
|
426
|
+
*/
|
|
183
427
|
export function rotate(out, a, b, rad) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
428
|
+
// Translate point to the origin
|
|
429
|
+
const p0 = a[0] - b[0];
|
|
430
|
+
const p1 = a[1] - b[1];
|
|
431
|
+
const sinC = Math.sin(rad);
|
|
432
|
+
const cosC = Math.cos(rad);
|
|
433
|
+
// perform rotation and translate to correct position
|
|
434
|
+
out[0] = p0 * cosC - p1 * sinC + b[0];
|
|
435
|
+
out[1] = p0 * sinC + p1 * cosC + b[1];
|
|
436
|
+
return out;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Get the angle between two 2D vectors
|
|
440
|
+
* @param {Readonly<NumericArray>} a The first operand
|
|
441
|
+
* @param {Readonly<NumericArray>} b The second operand
|
|
442
|
+
* @returns {Number} The angle in radians
|
|
443
|
+
*/
|
|
192
444
|
export function angle(a, b) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
445
|
+
const x1 = a[0];
|
|
446
|
+
const y1 = a[1];
|
|
447
|
+
const x2 = b[0];
|
|
448
|
+
const y2 = b[1];
|
|
449
|
+
// mag is the product of the magnitudes of a and b
|
|
450
|
+
const mag = Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2));
|
|
451
|
+
// mag &&.. short circuits if mag == 0
|
|
452
|
+
const cosine = mag && (x1 * x2 + y1 * y2) / mag;
|
|
453
|
+
// Math.min(Math.max(cosine, -1), 1) clamps the cosine between -1 and 1
|
|
454
|
+
return Math.acos(Math.min(Math.max(cosine, -1), 1));
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Set the components of a vec2 to zero
|
|
458
|
+
*
|
|
459
|
+
* @param {NumericArray} out the receiving vector
|
|
460
|
+
* @returns {NumericArray} out
|
|
461
|
+
*/
|
|
201
462
|
export function zero(out) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
463
|
+
out[0] = 0.0;
|
|
464
|
+
out[1] = 0.0;
|
|
465
|
+
return out;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Returns a string representation of a vector
|
|
469
|
+
*
|
|
470
|
+
* @param {Readonly<NumericArray>} a vector to represent as a string
|
|
471
|
+
* @returns {String} string representation of the vector
|
|
472
|
+
*/
|
|
206
473
|
export function str(a) {
|
|
207
|
-
|
|
208
|
-
}
|
|
474
|
+
return `vec2(${a[0]}, ${a[1]})`;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)
|
|
478
|
+
*
|
|
479
|
+
* @param {Readonly<NumericArray>} a The first vector.
|
|
480
|
+
* @param {Readonly<NumericArray>} b The second vector.
|
|
481
|
+
* @returns {Boolean} True if the vectors are equal, false otherwise.
|
|
482
|
+
*/
|
|
209
483
|
export function exactEquals(a, b) {
|
|
210
|
-
|
|
211
|
-
}
|
|
484
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Returns whether or not the vectors have approximately the same elements in the same position.
|
|
488
|
+
*
|
|
489
|
+
* @param {Readonly<NumericArray>} a The first vector.
|
|
490
|
+
* @param {Readonly<NumericArray>} b The second vector.
|
|
491
|
+
* @returns {Boolean} True if the vectors are equal, false otherwise.
|
|
492
|
+
*/
|
|
212
493
|
export function equals(a, b) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
494
|
+
const a0 = a[0];
|
|
495
|
+
const a1 = a[1];
|
|
496
|
+
const b0 = b[0];
|
|
497
|
+
const b1 = b[1];
|
|
498
|
+
return (Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
|
|
499
|
+
Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)));
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Alias for {@link vec2.length}
|
|
503
|
+
* @function
|
|
504
|
+
*/
|
|
219
505
|
export const len = length;
|
|
506
|
+
/**
|
|
507
|
+
* Alias for {@link vec2.subtract}
|
|
508
|
+
* @function
|
|
509
|
+
*/
|
|
220
510
|
export const sub = subtract;
|
|
511
|
+
/**
|
|
512
|
+
* Alias for {@link vec2.multiply}
|
|
513
|
+
* @function
|
|
514
|
+
*/
|
|
221
515
|
export const mul = multiply;
|
|
516
|
+
/**
|
|
517
|
+
* Alias for {@link vec2.divide}
|
|
518
|
+
* @function
|
|
519
|
+
*/
|
|
222
520
|
export const div = divide;
|
|
521
|
+
/**
|
|
522
|
+
* Alias for {@link vec2.distance}
|
|
523
|
+
* @function
|
|
524
|
+
*/
|
|
223
525
|
export const dist = distance;
|
|
526
|
+
/**
|
|
527
|
+
* Alias for {@link vec2.squaredDistance}
|
|
528
|
+
* @function
|
|
529
|
+
*/
|
|
224
530
|
export const sqrDist = squaredDistance;
|
|
531
|
+
/**
|
|
532
|
+
* Alias for {@link vec2.squaredLength}
|
|
533
|
+
* @function
|
|
534
|
+
*/
|
|
225
535
|
export const sqrLen = squaredLength;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
536
|
+
/**
|
|
537
|
+
* Perform some operation over an array of vec2s.
|
|
538
|
+
*
|
|
539
|
+
* @param {Array} a the array of vectors to iterate over
|
|
540
|
+
* @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
|
|
541
|
+
* @param {Number} offset Number of elements to skip at the beginning of the array
|
|
542
|
+
* @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
|
|
543
|
+
* @param {Function} fn Function to call for each vector in the array
|
|
544
|
+
* @param {Object} [arg] additional argument to pass to fn
|
|
545
|
+
* @returns {Array} a
|
|
546
|
+
* @function
|
|
547
|
+
*/
|
|
548
|
+
export const forEach = (function () {
|
|
549
|
+
const vec = create();
|
|
550
|
+
return function (a, stride, offset, count, fn, arg) {
|
|
551
|
+
let i;
|
|
552
|
+
let l;
|
|
553
|
+
if (!stride) {
|
|
554
|
+
stride = 2;
|
|
555
|
+
}
|
|
556
|
+
if (!offset) {
|
|
557
|
+
offset = 0;
|
|
558
|
+
}
|
|
559
|
+
if (count) {
|
|
560
|
+
l = Math.min(count * stride + offset, a.length);
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
l = a.length;
|
|
564
|
+
}
|
|
565
|
+
for (i = offset; i < l; i += stride) {
|
|
566
|
+
vec[0] = a[i];
|
|
567
|
+
vec[1] = a[i + 1];
|
|
568
|
+
fn(vec, vec, arg);
|
|
569
|
+
a[i] = vec[0];
|
|
570
|
+
a[i + 1] = vec[1];
|
|
571
|
+
}
|
|
572
|
+
return a;
|
|
573
|
+
};
|
|
574
|
+
})();
|