@oliversalzburg/js-utils 0.7.0 → 0.8.0

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.
Files changed (178) hide show
  1. package/lib/async/async.d.ts +44 -0
  2. package/lib/async/async.js +76 -0
  3. package/lib/async/async.js.map +1 -0
  4. package/lib/async/async.test.d.ts +1 -0
  5. package/lib/async/async.test.js +26 -0
  6. package/lib/async/async.test.js.map +1 -0
  7. package/lib/cli/args.d.ts +9 -0
  8. package/lib/cli/args.js +49 -0
  9. package/lib/cli/args.js.map +1 -0
  10. package/lib/cli/args.test.d.ts +1 -0
  11. package/lib/cli/args.test.js +31 -0
  12. package/lib/cli/args.test.js.map +1 -0
  13. package/lib/core.d.ts +43 -0
  14. package/lib/core.js +2 -0
  15. package/lib/core.js.map +1 -0
  16. package/lib/data/array.d.ts +55 -0
  17. package/lib/data/array.js +90 -0
  18. package/lib/data/array.js.map +1 -0
  19. package/lib/data/nil.d.ts +92 -0
  20. package/lib/data/nil.js +131 -0
  21. package/lib/data/nil.js.map +1 -0
  22. package/lib/data/random.d.ts +111 -0
  23. package/lib/data/random.js +381 -0
  24. package/lib/data/random.js.map +1 -0
  25. package/lib/data/string.d.ts +30 -0
  26. package/lib/data/string.js +53 -0
  27. package/lib/data/string.js.map +1 -0
  28. package/lib/data/tree.d.ts +28 -0
  29. package/lib/data/tree.js +45 -0
  30. package/lib/data/tree.js.map +1 -0
  31. package/lib/device/shake.d.ts +79 -0
  32. package/lib/device/shake.js +135 -0
  33. package/lib/device/shake.js.map +1 -0
  34. package/lib/dom/core.d.ts +21 -0
  35. package/lib/dom/core.js +41 -0
  36. package/lib/dom/core.js.map +1 -0
  37. package/lib/errors/AbstractError.d.ts +29 -0
  38. package/lib/errors/AbstractError.js +59 -0
  39. package/lib/errors/AbstractError.js.map +1 -0
  40. package/lib/errors/InternalError.d.ts +19 -0
  41. package/lib/errors/InternalError.js +38 -0
  42. package/lib/errors/InternalError.js.map +1 -0
  43. package/lib/errors/InvalidArgumentError.d.ts +13 -0
  44. package/lib/errors/InvalidArgumentError.js +22 -0
  45. package/lib/errors/InvalidArgumentError.js.map +1 -0
  46. package/lib/errors/InvalidOperationError.d.ts +13 -0
  47. package/lib/errors/InvalidOperationError.js +22 -0
  48. package/lib/errors/InvalidOperationError.js.map +1 -0
  49. package/lib/errors/NotImplementedError.d.ts +12 -0
  50. package/lib/errors/NotImplementedError.js +21 -0
  51. package/lib/errors/NotImplementedError.js.map +1 -0
  52. package/lib/errors/PermissionViolationError.d.ts +13 -0
  53. package/lib/errors/PermissionViolationError.js +22 -0
  54. package/lib/errors/PermissionViolationError.js.map +1 -0
  55. package/lib/errors/ResourceConflictError.d.ts +12 -0
  56. package/lib/errors/ResourceConflictError.js +21 -0
  57. package/lib/errors/ResourceConflictError.js.map +1 -0
  58. package/lib/errors/UnknownError.d.ts +16 -0
  59. package/lib/errors/UnknownError.js +25 -0
  60. package/lib/errors/UnknownError.js.map +1 -0
  61. package/lib/errors/console.d.ts +7 -0
  62. package/lib/errors/console.js +13 -0
  63. package/lib/errors/console.js.map +1 -0
  64. package/lib/errors/error-serializer.d.ts +45 -0
  65. package/lib/errors/error-serializer.js +74 -0
  66. package/lib/errors/error-serializer.js.map +1 -0
  67. package/lib/errors/error-serializer.test.d.ts +1 -0
  68. package/lib/errors/error-serializer.test.js +109 -0
  69. package/lib/errors/error-serializer.test.js.map +1 -0
  70. package/lib/errors/stream.d.ts +7 -0
  71. package/lib/errors/stream.js +15 -0
  72. package/lib/errors/stream.js.map +1 -0
  73. package/lib/errors/tools.d.ts +10 -0
  74. package/lib/errors/tools.js +13 -0
  75. package/lib/errors/tools.js.map +1 -0
  76. package/lib/events/event.d.ts +9 -0
  77. package/lib/events/event.js +10 -0
  78. package/lib/events/event.js.map +1 -0
  79. package/lib/format/bytes.d.ts +118 -0
  80. package/lib/format/bytes.js +138 -0
  81. package/lib/format/bytes.js.map +1 -0
  82. package/lib/format/bytes.test.d.ts +1 -0
  83. package/lib/format/bytes.test.js +146 -0
  84. package/lib/format/bytes.test.js.map +1 -0
  85. package/lib/format/count.d.ts +14 -0
  86. package/lib/format/count.js +51 -0
  87. package/lib/format/count.js.map +1 -0
  88. package/lib/format/count.test.d.ts +1 -0
  89. package/lib/format/count.test.js +42 -0
  90. package/lib/format/count.test.js.map +1 -0
  91. package/lib/format/milliseconds.d.ts +100 -0
  92. package/lib/format/milliseconds.js +199 -0
  93. package/lib/format/milliseconds.js.map +1 -0
  94. package/lib/format/milliseconds.test.d.ts +1 -0
  95. package/lib/format/milliseconds.test.js +393 -0
  96. package/lib/format/milliseconds.test.js.map +1 -0
  97. package/lib/format/string.d.ts +24 -0
  98. package/lib/format/string.js +32 -0
  99. package/lib/format/string.js.map +1 -0
  100. package/lib/format/string.test.d.ts +1 -0
  101. package/lib/format/string.test.js +17 -0
  102. package/lib/format/string.test.js.map +1 -0
  103. package/lib/graphics/canvas-sandbox-mp.d.ts +258 -0
  104. package/lib/graphics/canvas-sandbox-mp.js +280 -0
  105. package/lib/graphics/canvas-sandbox-mp.js.map +1 -0
  106. package/lib/graphics/canvas-sandbox.d.ts +255 -0
  107. package/lib/graphics/canvas-sandbox.js +358 -0
  108. package/lib/graphics/canvas-sandbox.js.map +1 -0
  109. package/lib/graphics/canvas.d.ts +57 -0
  110. package/lib/graphics/canvas.js +37 -0
  111. package/lib/graphics/canvas.js.map +1 -0
  112. package/lib/graphics/canvas2d-headless.d.ts +85 -0
  113. package/lib/graphics/canvas2d-headless.js +197 -0
  114. package/lib/graphics/canvas2d-headless.js.map +1 -0
  115. package/lib/graphics/canvas2d.d.ts +162 -0
  116. package/lib/graphics/canvas2d.js +332 -0
  117. package/lib/graphics/canvas2d.js.map +1 -0
  118. package/lib/graphics/canvas3d.d.ts +41 -0
  119. package/lib/graphics/canvas3d.js +67 -0
  120. package/lib/graphics/canvas3d.js.map +1 -0
  121. package/lib/graphics/color.d.ts +22 -0
  122. package/lib/graphics/color.js +38 -0
  123. package/lib/graphics/color.js.map +1 -0
  124. package/lib/graphics/core.d.ts +89 -0
  125. package/lib/graphics/core.js +146 -0
  126. package/lib/graphics/core.js.map +1 -0
  127. package/lib/graphics/palette-sampler.d.ts +7 -0
  128. package/lib/graphics/palette-sampler.js +21 -0
  129. package/lib/graphics/palette-sampler.js.map +1 -0
  130. package/lib/graphics/palette.d.ts +120 -0
  131. package/lib/graphics/palette.js +574 -0
  132. package/lib/graphics/palette.js.map +1 -0
  133. package/lib/graphics/palette.test.d.ts +1 -0
  134. package/lib/graphics/palette.test.js +43 -0
  135. package/lib/graphics/palette.test.js.map +1 -0
  136. package/lib/graphics/render-loop.d.ts +76 -0
  137. package/lib/graphics/render-loop.js +114 -0
  138. package/lib/graphics/render-loop.js.map +1 -0
  139. package/lib/graphics/shader.d.ts +56 -0
  140. package/lib/graphics/shader.js +80 -0
  141. package/lib/graphics/shader.js.map +1 -0
  142. package/lib/log/log.d.ts +11 -0
  143. package/lib/log/log.js +2 -0
  144. package/lib/log/log.js.map +1 -0
  145. package/lib/log/report.d.ts +57 -0
  146. package/lib/log/report.js +88 -0
  147. package/lib/log/report.js.map +1 -0
  148. package/lib/math/core.d.ts +85 -0
  149. package/lib/math/core.js +125 -0
  150. package/lib/math/core.js.map +1 -0
  151. package/lib/math/easing.d.ts +204 -0
  152. package/lib/math/easing.js +366 -0
  153. package/lib/math/easing.js.map +1 -0
  154. package/lib/math/euler.d.ts +18 -0
  155. package/lib/math/euler.js +22 -0
  156. package/lib/math/euler.js.map +1 -0
  157. package/lib/math/matrix3.d.ts +227 -0
  158. package/lib/math/matrix3.js +508 -0
  159. package/lib/math/matrix3.js.map +1 -0
  160. package/lib/math/quaternion.d.ts +119 -0
  161. package/lib/math/quaternion.js +270 -0
  162. package/lib/math/quaternion.js.map +1 -0
  163. package/lib/math/transformation.d.ts +26 -0
  164. package/lib/math/transformation.js +31 -0
  165. package/lib/math/transformation.js.map +1 -0
  166. package/lib/math/vector2.d.ts +202 -0
  167. package/lib/math/vector2.js +310 -0
  168. package/lib/math/vector2.js.map +1 -0
  169. package/lib/math/vector3.d.ts +293 -0
  170. package/lib/math/vector3.js +492 -0
  171. package/lib/math/vector3.js.map +1 -0
  172. package/lib/math/vector4.d.ts +182 -0
  173. package/lib/math/vector4.js +302 -0
  174. package/lib/math/vector4.js.map +1 -0
  175. package/lib/measurement/performance.d.ts +13 -0
  176. package/lib/measurement/performance.js +19 -0
  177. package/lib/measurement/performance.js.map +1 -0
  178. package/package.json +5 -7
@@ -0,0 +1,492 @@
1
+ /**
2
+ * A vector with 3 components, labeled: `X`, `Y`, `Z`.
3
+ */
4
+ export class Vector3 {
5
+ /**
6
+ * The X component of the vector.
7
+ */
8
+ x;
9
+ /**
10
+ * The Y component of the vector.
11
+ */
12
+ y;
13
+ /**
14
+ * The Z component of the vector.
15
+ */
16
+ z;
17
+ /**
18
+ * Constructs a new {@linkcode Vector3}.
19
+ * @param x - The X component.
20
+ * @param y - The Y component.
21
+ * @param z - The Z component.
22
+ */
23
+ constructor(x = 0, y = 0, z = 0) {
24
+ this.x = x;
25
+ this.y = y;
26
+ this.z = z;
27
+ }
28
+ /**
29
+ * Creates a copy of another {@linkcode Vector3}.
30
+ * @param vector - The vector to copy.
31
+ * @returns A new vector.
32
+ */
33
+ static fromVector3(vector) {
34
+ return new Vector3(vector.x, vector.y, vector.z);
35
+ }
36
+ /**
37
+ * Sets the vector to new coordinates.
38
+ * @param vector - The coordinates to set the vector to.
39
+ * @returns This instance.
40
+ */
41
+ set(vector) {
42
+ return this.setXYZ(vector.x, vector.y, vector.z);
43
+ }
44
+ /**
45
+ * Sets the vector to new coordinates.
46
+ * @param x - The new X component for the vector.
47
+ * @param y - The new Y component for the vector.
48
+ * @param z - The new Z component for the vector.
49
+ * @returns This instance.
50
+ */
51
+ setXYZ(x, y, z) {
52
+ this.x = x;
53
+ this.y = y;
54
+ this.z = z;
55
+ return this;
56
+ }
57
+ /**
58
+ * Adds another vector to this vector.
59
+ * @param vector - The vector to add to this vector.
60
+ * @returns This instance.
61
+ */
62
+ add(vector) {
63
+ return this.addXYZ(vector.x, vector.y, vector.z);
64
+ }
65
+ /**
66
+ * Adds another vector to this vector.
67
+ * @param x - The value to add to the X component.
68
+ * @param y - The value to add to the Y component.
69
+ * @param z - The value to add to the Z component.
70
+ * @returns This instance.
71
+ */
72
+ addXYZ(x, y, z) {
73
+ this.x += x;
74
+ this.y += y;
75
+ this.z += z;
76
+ return this;
77
+ }
78
+ /**
79
+ * Scales another vector and adds it to this vector.
80
+ * @param vector - The vector to add to this vector.
81
+ * @param scale - The scaling to apply to the input vector.
82
+ * @returns This instance.
83
+ */
84
+ addMultiply(vector, scale) {
85
+ return this.addMultiplyXYZ(vector.x, vector.y, vector.z, scale);
86
+ }
87
+ /**
88
+ * Scales another vector and adds it to this vector.
89
+ * @param x - The value to add to the X component.
90
+ * @param y - The value to add to the Y component.
91
+ * @param z - The value to add to the Z component.
92
+ * @param scale - The scaling to apply to the input vector.
93
+ * @returns This instance.
94
+ */
95
+ addMultiplyXYZ(x, y, z, scale) {
96
+ this.x += x * scale;
97
+ this.y += y * scale;
98
+ this.z += z * scale;
99
+ return this;
100
+ }
101
+ /**
102
+ * Subtracts another vector from this vector.
103
+ * @param vector - The vector to subtract from this vector.
104
+ * @returns This instance.
105
+ */
106
+ subtract(vector) {
107
+ return this.subtractXYZ(vector.x, vector.y, vector.z);
108
+ }
109
+ /**
110
+ * Subtracts another vector from this vector.
111
+ * @param x - The value to subtract from the X component.
112
+ * @param y - The value to subtract from the Y component.
113
+ * @param z - The value to subtract from the Z component.
114
+ * @returns This instance.
115
+ */
116
+ subtractXYZ(x, y, z) {
117
+ this.x -= x;
118
+ this.y -= y;
119
+ this.z -= z;
120
+ return this;
121
+ }
122
+ /**
123
+ * Multiplies this vector by another vector.
124
+ * @param vector - The vector to multiply with this vector.
125
+ * @returns This instance.
126
+ */
127
+ multiply(vector) {
128
+ return this.multiplyXYZ(vector.x, vector.y, vector.z);
129
+ }
130
+ /**
131
+ * Multiplies this vector by another vector.
132
+ * @param x - The value to multiply with the X component.
133
+ * @param y - The value to multiply with the Y component.
134
+ * @param z - The value to multiply with the Z component.
135
+ * @returns This instance.
136
+ */
137
+ multiplyXYZ(x, y, z) {
138
+ this.x *= x;
139
+ this.y *= y;
140
+ this.z *= z;
141
+ return this;
142
+ }
143
+ /**
144
+ * Multiplies the vector by the given scale.
145
+ * @param scale - The scaling to apply to the vector.
146
+ * @returns This instance.
147
+ */
148
+ multiplyScale(scale) {
149
+ this.x *= scale;
150
+ this.y *= scale;
151
+ this.z *= scale;
152
+ return this;
153
+ }
154
+ /**
155
+ * Divides this vector by another vector.
156
+ * @param vector - The vector to divide this vector with.
157
+ * @returns This instance.
158
+ */
159
+ divide(vector) {
160
+ return this.divideXYZ(vector.x, vector.y, vector.z);
161
+ }
162
+ /**
163
+ * Divides this vector by another vector.
164
+ * @param x - The value to divide the X component with.
165
+ * @param y - The value to divide the Y component with.
166
+ * @param z - The value to divide the Z component with.
167
+ * @returns This instance.
168
+ */
169
+ divideXYZ(x, y, z) {
170
+ this.x /= x;
171
+ this.y /= y;
172
+ this.z /= z;
173
+ return this;
174
+ }
175
+ /**
176
+ * Divides the vector by the given scale.
177
+ * @param scale - The scaling to apply to the vector.
178
+ * @returns This instance.
179
+ */
180
+ divideScale(scale) {
181
+ this.x /= scale;
182
+ this.y /= scale;
183
+ this.z /= scale;
184
+ return this;
185
+ }
186
+ /**
187
+ * Inverts the direction of the vector.
188
+ * @returns This instance.
189
+ */
190
+ invertAdd() {
191
+ this.x = -this.x;
192
+ this.y = -this.y;
193
+ this.z = -this.z;
194
+ return this;
195
+ }
196
+ /**
197
+ * Inverts the vectors scale.
198
+ * @returns This instance.
199
+ */
200
+ invertMultiply() {
201
+ this.x = 1 / this.x;
202
+ this.y = 1 / this.y;
203
+ this.z = 1 / this.z;
204
+ return this;
205
+ }
206
+ /**
207
+ * Clamps the components of the vector at the given boundary.
208
+ * @param floor - The lowest value to allow.
209
+ * @param ceil - The largest value to allow.
210
+ * @returns This instance.
211
+ */
212
+ clamp(floor, ceil) {
213
+ if (this.x < floor) {
214
+ this.x = floor;
215
+ }
216
+ if (this.x > ceil) {
217
+ this.x = ceil;
218
+ }
219
+ if (this.y < floor) {
220
+ this.y = floor;
221
+ }
222
+ if (this.y > ceil) {
223
+ this.y = ceil;
224
+ }
225
+ if (this.z < floor) {
226
+ this.z = floor;
227
+ }
228
+ if (this.z > ceil) {
229
+ this.z = ceil;
230
+ }
231
+ return this;
232
+ }
233
+ /**
234
+ * Calculates the length of the vector.
235
+ * @returns The length of the vector.
236
+ */
237
+ length() {
238
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
239
+ }
240
+ /**
241
+ * Normalizes the vector.
242
+ * @returns This instance.
243
+ */
244
+ normalize() {
245
+ const length = this.length();
246
+ if (length === 0) {
247
+ return this;
248
+ }
249
+ this.x /= length;
250
+ this.y /= length;
251
+ this.z /= length;
252
+ return this;
253
+ }
254
+ /**
255
+ * Compares two vectors.
256
+ * @param vector - The vector to compare this vector to.
257
+ * @returns `true` if the vectors are idently, `false` otherwise.
258
+ */
259
+ compare(vector) {
260
+ return vector.x === this.x && vector.y === this.y && vector.z === this.z;
261
+ }
262
+ /**
263
+ * Linearly moves this vector towards a target vector.
264
+ * @param vector - The target vector.
265
+ * @param t - The location on the scale, from `0` to `1`.
266
+ * @returns This instance.
267
+ */
268
+ lerp(vector, t) {
269
+ const tn = 1 - t;
270
+ this.x = this.x * tn + vector.x * t;
271
+ this.y = this.y * tn + vector.y * t;
272
+ this.z = this.z * tn + vector.z * t;
273
+ return this;
274
+ }
275
+ /**
276
+ * Rotates the vector by the given rotation matrix.
277
+ * @param matrix - The rotation matrix to apply to the vector.
278
+ * @returns This instance.
279
+ */
280
+ rotate(matrix) {
281
+ const xn = this.x;
282
+ const yn = this.y;
283
+ const zn = this.z;
284
+ this.x = xn * matrix.m00 + yn * matrix.m10 + zn * matrix.m20;
285
+ this.y = xn * matrix.m01 + yn * matrix.m11 + zn * matrix.m21;
286
+ this.z = xn * matrix.m02 + yn * matrix.m12 + zn * matrix.m22;
287
+ return this;
288
+ }
289
+ /**
290
+ * Inversely rotates the vector by the given rotation matrix.
291
+ * @param matrix - The rotation matrix to apply to the vector.
292
+ * @returns This instance.
293
+ */
294
+ rotateInverse(matrix) {
295
+ const xn = this.x;
296
+ const yn = this.y;
297
+ const zn = this.z;
298
+ this.x = xn * matrix.m00 + yn * matrix.m01 + zn * matrix.m02;
299
+ this.y = xn * matrix.m10 + yn * matrix.m11 + zn * matrix.m12;
300
+ this.z = xn * matrix.m20 + yn * matrix.m21 + zn * matrix.m22;
301
+ return this;
302
+ }
303
+ /**
304
+ * Rotates the vector by the given rotation matrix around the given center.
305
+ * @param center - The center around which to rotate the vector.
306
+ * @param matrix - The rotation matrix to apply to the vector.
307
+ * @returns This instance.
308
+ */
309
+ rotateAround(center, matrix) {
310
+ const xn = this.x - center.x;
311
+ const yn = this.y - center.y;
312
+ const zn = this.z - center.z;
313
+ this.x = xn * matrix.m00 + yn * matrix.m10 + zn * matrix.m20 + center.x;
314
+ this.y = xn * matrix.m01 + yn * matrix.m11 + zn * matrix.m21 + center.y;
315
+ this.z = xn * matrix.m02 + yn * matrix.m12 + zn * matrix.m22 + center.z;
316
+ return this;
317
+ }
318
+ /**
319
+ * Inversely rotates the vector by the given rotation matrix around the given center.
320
+ * @param center - The center around which to rotate the vector.
321
+ * @param matrix - The rotation matrix to apply to the vector.
322
+ * @returns This instance.
323
+ */
324
+ rotateAroundInverse(center, matrix) {
325
+ const xn = this.x - center.x;
326
+ const yn = this.y - center.y;
327
+ const zn = this.z - center.z;
328
+ this.x = xn * matrix.m00 + yn * matrix.m01 + zn * matrix.m02 + center.x;
329
+ this.y = xn * matrix.m10 + yn * matrix.m11 + zn * matrix.m12 + center.y;
330
+ this.z = xn * matrix.m20 + yn * matrix.m21 + zn * matrix.m22 + center.z;
331
+ return this;
332
+ }
333
+ /**
334
+ * Transform the vector with a {@linkcode Transformation}.
335
+ * @param transformation - The transformation to apply.
336
+ * @returns This instance.
337
+ */
338
+ transform(transformation) {
339
+ return this.multiply(transformation.scale)
340
+ .rotate(transformation.rotation)
341
+ .add(transformation.position);
342
+ }
343
+ /**
344
+ * Inversely transform the vector with a {@linkcode Transformation}.
345
+ * @param transformation - The transformation to apply.
346
+ * @returns This instance.
347
+ */
348
+ transformInverse(transformation) {
349
+ return this.subtract(transformation.position)
350
+ .rotateInverse(transformation.rotation)
351
+ .divide(transformation.scale);
352
+ }
353
+ /**
354
+ * Returns the dot product between two vectors.
355
+ * @param vector - The other vector.
356
+ * @returns The dot product between the two vectors.
357
+ */
358
+ dot(vector) {
359
+ return this.dotXYZ(vector.x, vector.y, vector.z);
360
+ }
361
+ /**
362
+ * Returns the dot product between two vectors.
363
+ * @param x - The X component of the other vector.
364
+ * @param y - The Y component of the other vector.
365
+ * @param z - The Z component of the other vector.
366
+ * @returns The dot product between the two vectors.
367
+ */
368
+ dotXYZ(x, y, z) {
369
+ return this.x * x + this.y * y + this.z * z;
370
+ }
371
+ /**
372
+ * Calculates the dot product of this vector and another vector, and then
373
+ * sets this vector to the result.
374
+ * @param vector - The other vector.
375
+ * @returns This instance.
376
+ */
377
+ cross(vector) {
378
+ const xn = this.z * vector.y - this.y * vector.z;
379
+ const yn = this.x * vector.z - this.z * vector.x;
380
+ const zn = this.y * vector.x - this.x * vector.y;
381
+ this.x = xn;
382
+ this.y = yn;
383
+ this.z = zn;
384
+ return this;
385
+ }
386
+ /**
387
+ * Makes this vector perpendicular to the other 3 vectors.
388
+ * @param vector0 - The first vector.
389
+ * @param vector1 - The second vector.
390
+ * @param vector2 - The third vector.
391
+ * @returns This instance.
392
+ */
393
+ perpendicular(vector0, vector1, vector2) {
394
+ const px = vector2.x - vector1.x;
395
+ const py = vector2.y - vector1.y;
396
+ const pz = vector2.z - vector1.z;
397
+ const qx = vector0.x - vector1.x;
398
+ const qy = vector0.y - vector1.y;
399
+ const qz = vector0.z - vector1.z;
400
+ this.x = pz * qy - py * qz;
401
+ this.y = px * qz - pz * qx;
402
+ this.z = py * qx - px * qy;
403
+ return this;
404
+ }
405
+ /**
406
+ * Reflects this vector against the given normal and sets this vector to
407
+ * the result.
408
+ * @param normal - The normal against which to reflect.
409
+ * @returns This instance.
410
+ */
411
+ reflect(normal) {
412
+ const c = this.dot(normal) * 2;
413
+ this.x = this.x - c * normal.x;
414
+ this.y = this.y - c * normal.y;
415
+ this.z = this.z - c * normal.z;
416
+ return this;
417
+ }
418
+ /**
419
+ * Calculates the reflection of this vector, based on the angle of incident
420
+ * into a material with the given refractive index, according to Snell's law.
421
+ * This vector is then set to the result.
422
+ * @param normal - The normal against which to reflect.
423
+ * @param index - The refractive index of the material.
424
+ * @returns This instance.
425
+ */
426
+ fraction(normal, index) {
427
+ let c = -this.dot(normal);
428
+ const r = 1 + index * index * (c * c - 1);
429
+ if (r < 0)
430
+ return this.reflect(normal);
431
+ c = index * c - Math.sqrt(r);
432
+ this.x = index * this.x + c * normal.x;
433
+ this.y = index * this.y + c * normal.y;
434
+ this.z = index * this.z + c * normal.z;
435
+ return this;
436
+ }
437
+ /**
438
+ * Return the components of this vector as an array.
439
+ * @returns The components of this vector as an array.
440
+ */
441
+ asArray() {
442
+ return [this.x, this.y, this.z];
443
+ }
444
+ }
445
+ /**
446
+ * Adds two vectors and returns a new vector with the result.
447
+ * @param a - The first input vector.
448
+ * @param b - The second input vector.
449
+ * @returns A new {@linkcode Vector3}.
450
+ */
451
+ export const addVector3 = (a, b) => {
452
+ return new Vector3(a.x * b.x, a.y * b.y, a.z + b.z);
453
+ };
454
+ /**
455
+ * Multiplies two vectors and returns a new vector with the result.
456
+ * @param a - The first input vector.
457
+ * @param b - The second input vector.
458
+ * @returns A new {@linkcode Vector3}.
459
+ */
460
+ export const multiplyVector3 = (a, b) => {
461
+ return new Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
462
+ };
463
+ /**
464
+ * Subtracts two vectors and returns a new vector with the result.
465
+ * @param a - The first input vector.
466
+ * @param b - The second input vector.
467
+ * @returns A new {@linkcode Vector3}.
468
+ */
469
+ export const subtractVector3 = (a, b) => {
470
+ return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
471
+ };
472
+ /**
473
+ * Calculates the cross product between two vectors and returns a new vector with the result.
474
+ * @param a - The first input vector.
475
+ * @param b - The second input vector.
476
+ * @returns A new vector, which is the cross product of the two input vectors.
477
+ */
478
+ export const crossVector3 = (a, b) => {
479
+ const c = Vector3.fromVector3(a);
480
+ return c.cross(b);
481
+ };
482
+ /**
483
+ * Calculates the dot product between two vectors.
484
+ * @param a - The first input vector.
485
+ * @param b - The second input vector.
486
+ * @returns The dot product between the two vectors.
487
+ */
488
+ export const dotVector3 = (a, b) => {
489
+ const c = Vector3.fromVector3(a);
490
+ return c.dot(b);
491
+ };
492
+ //# sourceMappingURL=vector3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector3.js","sourceRoot":"","sources":["../../source/math/vector3.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB;;OAEG;IACH,CAAC,CAAS;IAEV;;OAEG;IACH,CAAC,CAAS;IAEV;;OAEG;IACH,CAAC,CAAS;IAEV;;;;;OAKG;IACH,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC;QAC9B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,MAAyB;QAC3C,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,MAAyB;QAC5B,OAAO,IAAI,CAAC,MA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AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC3B,CAAoB,EACpB,CAAoB,EACV,EAAE;IACZ,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACzB,CAAoB,EACpB,CAAoB,EACX,EAAE;IACX,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * A vector with 4 components, labeled: `X`, `Y`, `Z`, `W`.
3
+ */
4
+ export declare class Vector4 {
5
+ /**
6
+ * The components of the vector.
7
+ */
8
+ k: number[];
9
+ /**
10
+ * Get the X component of the vector.
11
+ * @returns The X component of the vector.
12
+ */
13
+ get x(): number;
14
+ /**
15
+ * Set the X component of the vector.
16
+ */
17
+ set x(value: number);
18
+ /**
19
+ * Get the Y component of the vector.
20
+ * @returns The Y component of the vector.
21
+ */
22
+ get y(): number;
23
+ /**
24
+ * Set the Y component of the vector.
25
+ */
26
+ set y(value: number);
27
+ /**
28
+ * Get the Z component of the vector.
29
+ * @returns The Z component of the vector.
30
+ */
31
+ get z(): number;
32
+ /**
33
+ * Set the Z component of the vector.
34
+ */
35
+ set z(value: number);
36
+ /**
37
+ * Get the W component of the vector.
38
+ * @returns The W component of the vector.
39
+ */
40
+ get w(): number;
41
+ /**
42
+ * Set the W component of the vector.
43
+ */
44
+ set w(value: number);
45
+ /**
46
+ * Constructs a new {@linkcode Vector4}.
47
+ * @param x - The X component.
48
+ * @param y - The Y component.
49
+ * @param z - The Z component.
50
+ * @param w - The W component.
51
+ */
52
+ constructor(x: number, y: number, z: number, w: number);
53
+ /**
54
+ * Creates a copy of another {@linkcode Vector4}.
55
+ * @param vector - The vector to copy.
56
+ * @returns A new vector.
57
+ */
58
+ static fromVector4(vector: Readonly<Vector4>): Vector4;
59
+ /**
60
+ * Sets the vector to new coordinates.
61
+ * @param vector - The coordinates to set the vector to.
62
+ * @returns This instance.
63
+ */
64
+ set(vector: Readonly<Vector4>): this;
65
+ /**
66
+ * Sets the vector to new coordinates.
67
+ * @param x - The new X component for the vector.
68
+ * @param y - The new Y component for the vector.
69
+ * @param z - The new Z component for the vector.
70
+ * @param w - The new W component for the vector.
71
+ * @returns This instance.
72
+ */
73
+ setXYZW(x: number, y: number, z: number, w: number): this;
74
+ /**
75
+ * Adds the XYZ components of another vector to this vector.
76
+ * @param vector - The vector to add to this vector.
77
+ * @returns This instance.
78
+ */
79
+ add3(vector: Readonly<Vector4>): this;
80
+ /**
81
+ * Adds the XYZ components of another vector to this vector.
82
+ * @param x - The value to add to the X component.
83
+ * @param y - The value to add to the Y component.
84
+ * @param z - The value to add to the Z component.
85
+ * @returns This instance.
86
+ */
87
+ add3XYZ(x: number, y: number, z: number): this;
88
+ /**
89
+ * Scales another vector and adds its XYZ components to this vector.
90
+ * @param vector - The vector to add to this vector.
91
+ * @param scale - The scaling to apply to the input vector.
92
+ * @returns This instance.
93
+ */
94
+ addMultiply3(vector: Readonly<Vector4>, scale: number): this;
95
+ /**
96
+ * Scales another vector and adds its XYZ components to this vector.
97
+ * @param x - The value to add to the X component.
98
+ * @param y - The value to add to the Y component.
99
+ * @param z - The value to add to the Z component.
100
+ * @param scale - The scaling to apply to the input vector.
101
+ * @returns This instance.
102
+ */
103
+ addMultiply3XYZ(x: number, y: number, z: number, scale: number): this;
104
+ /**
105
+ * Subtracts the XYZ components of another vector from this vector.
106
+ * @param vector - The vector to subtract from this vector.
107
+ * @returns This instance.
108
+ */
109
+ subtract3(vector: Readonly<Vector4>): this;
110
+ /**
111
+ * Subtracts the XYZ components of another vector from this vector.
112
+ * @param x - The value to subtract from the X component.
113
+ * @param y - The value to subtract from the Y component.
114
+ * @param z - The value to subtract from the Z component.
115
+ * @returns This instance.
116
+ */
117
+ subtract3XYZ(x: number, y: number, z: number): this;
118
+ /**
119
+ * Multiplies the XYZ components of this vector by another vector.
120
+ * @param vector - The vector to multiply with this vector.
121
+ * @returns This instance.
122
+ */
123
+ multiply3(vector: Readonly<Vector4>): this;
124
+ /**
125
+ * Multiplies the XYZ components of this vector by another vector.
126
+ * @param x - The value to multiply with the X component.
127
+ * @param y - The value to multiply with the Y component.
128
+ * @param z - The value to multiply with the Z component.
129
+ * @returns This instance.
130
+ */
131
+ multiply3XYZ(x: number, y: number, z: number): this;
132
+ /**
133
+ * Multiplies the XYZ components of the vector by the given scale.
134
+ * @param scale - The scaling to apply to the vector.
135
+ * @returns This instance.
136
+ */
137
+ multiply3Scale(scale: number): this;
138
+ /**
139
+ * Divides the XYZ components of this vector by another vector.
140
+ * @param vector - The vector to divide this vector with.
141
+ * @returns This instance.
142
+ */
143
+ divide3(vector: Readonly<Vector4>): this;
144
+ /**
145
+ * Divides the XYZ components of this vector by another vector.
146
+ * @param x - The value to divide the X component with.
147
+ * @param y - The value to divide the Y component with.
148
+ * @param z - The value to divide the Z component with.
149
+ * @returns This instance.
150
+ */
151
+ divide3XYZ(x: number, y: number, z: number): this;
152
+ /**
153
+ * Divides the XYZ components of the vector by the given scale.
154
+ * @param scale - The scaling to apply to the vector.
155
+ * @returns This instance.
156
+ */
157
+ divide3Scale(scale: number): this;
158
+ /**
159
+ * Inverts the direction of the vector.
160
+ * @returns This instance.
161
+ */
162
+ invertAdd3(): this;
163
+ /**
164
+ * Inverts the vectors scale.
165
+ * @returns This instance.
166
+ */
167
+ invertMultiply3(): this;
168
+ /**
169
+ * Clamps the components of the vector at the given boundary.
170
+ * @param floor - The lowest value to allow.
171
+ * @param ceil - The largest value to allow.
172
+ * @returns This instance.
173
+ */
174
+ clamp(floor: number, ceil: number): this;
175
+ /**
176
+ * Linearly moves this vector towards a target vector.
177
+ * @param vector - The target vector.
178
+ * @param t - The location on the scale, from `0` to `1`.
179
+ * @returns This instance.
180
+ */
181
+ lerp(vector: Readonly<Vector4>, t: number): this;
182
+ }