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