@jarenjs/core 0.9.2

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 (58) hide show
  1. package/ARCHITECTURE.md +800 -0
  2. package/LICENSE +21 -0
  3. package/README.md +68 -0
  4. package/dist/types/array.d.ts +28 -0
  5. package/dist/types/bigint.d.ts +5 -0
  6. package/dist/types/dates.d.ts +79 -0
  7. package/dist/types/float.d.ts +32 -0
  8. package/dist/types/function.d.ts +22 -0
  9. package/dist/types/index.d.ts +119 -0
  10. package/dist/types/integer.d.ts +24 -0
  11. package/dist/types/math/float64.d.ts +121 -0
  12. package/dist/types/math/index.d.ts +5 -0
  13. package/dist/types/math/int32.d.ts +41 -0
  14. package/dist/types/math/vec2f64.d.ts +346 -0
  15. package/dist/types/math/vec2i32.d.ts +43 -0
  16. package/dist/types/math/vec3f64.d.ts +61 -0
  17. package/dist/types/number.d.ts +39 -0
  18. package/dist/types/object.d.ts +44 -0
  19. package/dist/types/scan.d.ts +64 -0
  20. package/dist/types/string.d.ts +65 -0
  21. package/dist/types/text/base64.d.ts +4 -0
  22. package/dist/types/text/basic.d.ts +5 -0
  23. package/dist/types/text/email.d.ts +3 -0
  24. package/dist/types/text/host.d.ts +14 -0
  25. package/dist/types/text/i18n.d.ts +13 -0
  26. package/dist/types/text/identifiers.d.ts +5 -0
  27. package/dist/types/text/index.d.ts +8 -0
  28. package/dist/types/text/iregexp.d.ts +36 -0
  29. package/dist/types/text/misc.d.ts +4 -0
  30. package/dist/types/text/punycode.d.ts +86 -0
  31. package/package.json +101 -0
  32. package/src/array.js +57 -0
  33. package/src/bigint.js +30 -0
  34. package/src/dates.js +371 -0
  35. package/src/float.js +107 -0
  36. package/src/function.js +56 -0
  37. package/src/index.js +223 -0
  38. package/src/integer.js +77 -0
  39. package/src/math/float64.js +316 -0
  40. package/src/math/index.js +5 -0
  41. package/src/math/int32.js +235 -0
  42. package/src/math/vec2f64.js +706 -0
  43. package/src/math/vec2i32.js +250 -0
  44. package/src/math/vec3f64.js +225 -0
  45. package/src/number.js +63 -0
  46. package/src/object.js +240 -0
  47. package/src/scan.js +96 -0
  48. package/src/string.js +194 -0
  49. package/src/text/base64.js +54 -0
  50. package/src/text/basic.js +23 -0
  51. package/src/text/email.js +61 -0
  52. package/src/text/host.js +335 -0
  53. package/src/text/i18n.js +294 -0
  54. package/src/text/identifiers.js +27 -0
  55. package/src/text/index.js +11 -0
  56. package/src/text/iregexp.js +308 -0
  57. package/src/text/misc.js +19 -0
  58. package/src/text/punycode.js +407 -0
@@ -0,0 +1,706 @@
1
+ //@ts-check
2
+
3
+ import {
4
+ mathf64_sqrt,
5
+ mathf64_sin,
6
+ mathf64_cos,
7
+ mathf64_abs,
8
+ mathf64_ceil,
9
+ mathf64_floor,
10
+ mathf64_round,
11
+ mathf64_min,
12
+ mathf64_max,
13
+ mathf64_EPSILON, // TODO: take epsilon from float.js
14
+ Float64,
15
+ } from './float64.js';
16
+
17
+ export class Vec2f64 {
18
+ constructor(x = 0.0, y = 0.0) {
19
+ this.x = +x;
20
+ this.y = +y;
21
+ }
22
+
23
+ /**
24
+ * Create a new 2 dimensional vector
25
+ * @param {number | Vec2f64} x a floating point number or a Vec2f64 instance
26
+ * @param {number | undefined} y a fl
27
+ * @returns {Vec2f64} a new vector structure
28
+ */
29
+ static new(x = 0.0, y = 0.0) {
30
+ return (x instanceof Vec2f64)
31
+ ? new Vec2f64(+x.x, +x.y)
32
+ : new Vec2f64(+x, +y);
33
+ }
34
+
35
+ //#region static vec2f pure operators
36
+
37
+ static neg(v = def_Vec2f64) {
38
+ return new Vec2f64(
39
+ +(-(+v.x)),
40
+ +(-(+v.y))
41
+ );
42
+ }
43
+
44
+ static add(a = def_Vec2f64, b = def_Vec2f64) {
45
+ return new Vec2f64(
46
+ +(+a.x + +b.x),
47
+ +(+a.y + +b.y)
48
+ );
49
+ }
50
+
51
+ static adds(v = def_Vec2f64, scalar = 0.0) {
52
+ return new Vec2f64(
53
+ +(+v.x + +scalar),
54
+ +(+v.y + +scalar)
55
+ );
56
+ }
57
+
58
+ static addms(a = def_Vec2f64, b = def_Vec2f64, scalar = 1.0) {
59
+ return new Vec2f64(
60
+ +(+a.x + +(+b.x * +scalar)),
61
+ +(+a.y + +(+b.y * +scalar)),
62
+ );
63
+ }
64
+
65
+ static sub(a = def_Vec2f64, b = def_Vec2f64) {
66
+ return new Vec2f64(
67
+ +(+a.x - +b.x),
68
+ +(+a.y - +b.y)
69
+ );
70
+ }
71
+
72
+ static subs(v = def_Vec2f64, scalar = 0.0) {
73
+ return new Vec2f64(
74
+ +(+v.x - +scalar),
75
+ +(+v.y - +scalar)
76
+ );
77
+ }
78
+
79
+ static mul(a = def_Vec2f64, b = def_Vec2f64) {
80
+ return new Vec2f64(
81
+ +(+a.x * +b.x),
82
+ +(+a.y * +b.y)
83
+ );
84
+ }
85
+
86
+ static muls(v = def_Vec2f64, scalar = 0.0) {
87
+ return new Vec2f64(
88
+ +(+v.x * +scalar),
89
+ +(+v.y * +scalar)
90
+ );
91
+ }
92
+
93
+ static div(a = def_Vec2f64, b = def_Vec2f64) {
94
+ return new Vec2f64(
95
+ +(+a.x / +b.x),
96
+ +(+a.y / +b.y)
97
+ );
98
+ }
99
+
100
+ static divs(v = def_Vec2f64, scalar = 0.0) {
101
+ return new Vec2f64(
102
+ +(+v.x / +scalar),
103
+ +(+v.y / +scalar)
104
+ );
105
+ }
106
+
107
+ static inv(v = def_Vec2f64) {
108
+ return new Vec2f64(
109
+ 1.0 / +v.x,
110
+ 1.0 / +v.y,
111
+ );
112
+ }
113
+
114
+ static ceil(v = def_Vec2f64) {
115
+ return new Vec2f64(
116
+ +mathf64_ceil(+v.x),
117
+ +mathf64_ceil(+v.y),
118
+ );
119
+ }
120
+
121
+ static floor(v = def_Vec2f64) {
122
+ return new Vec2f64(
123
+ +mathf64_floor(+v.x),
124
+ +mathf64_floor(+v.y),
125
+ );
126
+ }
127
+
128
+ static round(v = def_Vec2f64) {
129
+ return new Vec2f64(
130
+ +mathf64_round(+v.x),
131
+ +mathf64_round(+v.y),
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Returns the minimum of two vectors
137
+ * @param {Vec2f64} a the base vector
138
+ * @param {Vec2f64} b the target vector
139
+ * @returns {Vec2f64} the new minimum of two vectors
140
+ */
141
+ static min(a = def_Vec2f64, b = def_Vec2f64) {
142
+ return new Vec2f64(
143
+ +mathf64_min(+a.x, +b.x),
144
+ +mathf64_min(+a.y, +b.y),
145
+ );
146
+ }
147
+
148
+ /**
149
+ * Returns the maximum of two vectors
150
+ * @param {Vec2f64} a the base vector
151
+ * @param {Vec2f64} b the target vector
152
+ * @returns {Vec2f64} the new maximum of two vectors
153
+ */
154
+ static max(a = def_Vec2f64, b = def_Vec2f64) {
155
+ return new Vec2f64(
156
+ +mathf64_max(+a.x, +b.x),
157
+ +mathf64_max(+a.y, +b.y),
158
+ );
159
+ }
160
+
161
+ /**
162
+ * Returns true if two vectors are strictly equal
163
+ * @param {Vec2f64} a the base vector
164
+ * @param {Vec2f64} b the target vector
165
+ * @returns {boolean} true if two vectors are strictly equal
166
+ */
167
+ static eqstrict(a = def_Vec2f64, b = def_Vec2f64) {
168
+ return a.x === b.x && a.y === b.y;
169
+ }
170
+
171
+ /**
172
+ * Returns true if two vectors are equal within a small epsilon
173
+ * @param {Vec2f64} a the base vector
174
+ * @param {Vec2f64} b the target vector
175
+ * @returns {boolean} true if two vectors are equal within a small epsilon
176
+ */
177
+ static equals(a = def_Vec2f64, b = def_Vec2f64) {
178
+ const ax = +a.x;
179
+ const ay = +a.y;
180
+ const bx = +b.x;
181
+ const by = +b.y;
182
+ return (mathf64_abs(ax - bx)
183
+ <= mathf64_EPSILON * mathf64_max(1.0, mathf64_abs(ax), mathf64_abs(bx))
184
+ && mathf64_abs(ay - by)
185
+ <= mathf64_EPSILON * mathf64_max(1.0, mathf64_abs(ay), mathf64_abs(by))
186
+ );
187
+ }
188
+
189
+ /**
190
+ * Returns the square of the magnitude of the vector
191
+ * @param {Vec2f64} v the vector
192
+ * @returns {number} the square of the magnitude of the vector
193
+ */
194
+ static mag2(v = def_Vec2f64) {
195
+ return +Float64.mag2(v.x, v.y);
196
+ }
197
+
198
+ /**
199
+ * Returns the magnitude of the vector
200
+ * @param {Vec2f64} v the vector
201
+ * @returns {number} the magnitude of the vector
202
+ */
203
+ static mag(v = def_Vec2f64) {
204
+ return +Float64.mag(v.x, v.y);
205
+ }
206
+
207
+ /**
208
+ * Returns the square of the distance between two vectors
209
+ * @param {Vec2f64} a the base vector
210
+ * @param {Vec2f64} b the target vector
211
+ * @returns {number} the square of the distance between two vectors
212
+ */
213
+ static dist2(a = def_Vec2f64, b = def_Vec2f64) {
214
+ const dx = +(+b.x - +a.x);
215
+ const dy = +(+b.y - +a.y);
216
+ return +Float64.mag2(dx, dy);
217
+ }
218
+
219
+ /**
220
+ * Returns the distance between two vectors
221
+ * @param {Vec2f64} a the base vector
222
+ * @param {Vec2f64} b the target vector
223
+ * @returns {number} the distance between two vectors
224
+ */
225
+ static dist(a = def_Vec2f64, b = def_Vec2f64) {
226
+ return +mathf64_sqrt(+Vec2f64.dist2(a, b));
227
+ }
228
+
229
+ /**
230
+ * Returns the dot product of two vectors
231
+ * @param {Vec2f64} a the base vector
232
+ * @param {Vec2f64} b the target vector
233
+ * @returns {number} the dot product of two vectors
234
+ */
235
+ static dot(a = def_Vec2f64, b = def_Vec2f64) {
236
+ return +Float64.dot(+a.x, +a.y, +b.x, +b.y);
237
+ }
238
+
239
+ /**
240
+ * Returns the cross-product of two vectors
241
+ * @param {Vec2f64} a the base vector
242
+ * @param {Vec2f64} b the target vector
243
+ * @returns {number} the cross-product of two vectors
244
+ */
245
+ static cross(a = def_Vec2f64, b = def_Vec2f64) {
246
+ return +Float64.cross(+a.x, +a.y, +b.x, +b.y);
247
+ }
248
+
249
+ /**
250
+ * Returns the cross-product of three vectors
251
+ *
252
+ * You can determine which side of a line a point is on
253
+ * by converting the line to hyperplane form (implicitly
254
+ * or explicitly) and then computing the perpendicular
255
+ * (pseudo)distance from the point to the hyperplane.
256
+ *
257
+ * With the cross-product of two vectors A and B being the vector
258
+ *
259
+ * AxB = (AyBz − AzBy, AzBx − AxBz, AxBy − AyBx)
260
+ * with Az and Bz being zero you are left with the third component of that vector
261
+ *
262
+ * AxBy - AyBx
263
+ *
264
+ * With A being the vector from point a to b, and B being the vector from point a to c means
265
+ *
266
+ * Ax = (b[x]-a[x])
267
+ * Ay = (b[y]-a[y])
268
+ * Bx = (c[x]-a[x])
269
+ * By = (c[y]-a[y])
270
+ *
271
+ * giving
272
+ *
273
+ * AxBy - AyBx = (b[x]-a[x])*(c[y]-a[y])-(b[y]-a[y])*(c[x]-a[x])
274
+ *
275
+ * which is a scalar, the sign of that scalar will tell you wether point c
276
+ * lies to the left or right of vector ab
277
+ *
278
+ * @param {Vec2f64} a the base vector
279
+ * @param {Vec2f64} b the pivot vector
280
+ * @param {Vec2f64} c the target vector
281
+ * @returns {number} the cross-product of three vectors
282
+ */
283
+ static cross3(a = def_Vec2f64, b = def_Vec2f64, c = def_Vec2f64) {
284
+ const ax = +a.x;
285
+ const ay = +a.y;
286
+ const bx = +b.x;
287
+ const by = +b.y;
288
+ const cx = +c.x;
289
+ const cy = +c.y;
290
+ return +(
291
+ +(+(bx - ax) * +(cy - ay))
292
+ - +(+(by - ay) * +(cx - ax))
293
+ );
294
+ }
295
+
296
+ /**
297
+ * Returns the angle in radians of its vector
298
+ * @param {Vec2f64} v the base vector
299
+ * @returns {number} the angle in radians of its vector
300
+ */
301
+ static theta(v = def_Vec2f64) {
302
+ return +Float64.theta(v.x, v.y);
303
+ }
304
+
305
+ /**
306
+ * Returns the angle in radians of its vector
307
+ * @param {Vec2f64} v the base vector
308
+ * @returns {number} the angle in radians of its vector
309
+ */
310
+ static phi(v = def_Vec2f64) {
311
+ return +Float64.phi(+v.y, +Vec2f64.mag(v));
312
+ }
313
+
314
+ /**
315
+ * Returns the unit vector of its vector
316
+ * @param {Vec2f64} v the base vector
317
+ * @returns {Vec2f64} the new unit vector of its vector
318
+ */
319
+ static unit(v = def_Vec2f64) {
320
+ // const mag2 = +Vec2f64.mag2(v);
321
+ // return Vec2f64.divs(
322
+ // v,
323
+ // +(mag2 > 0 ? 1.0 / +mathf64_sqrt(mag2) : 1),
324
+ // );
325
+ return Vec2f64.divs(v, +Vec2f64.mag(v));
326
+ }
327
+
328
+ /**
329
+ * Returns the vector rotated 90 degrees counter-clockwise
330
+ * @param {Vec2f64} v the base vector
331
+ * @returns {Vec2f64} the new vector rotated 90 degrees counter-clockwise
332
+ */
333
+ static rotn90(v = def_Vec2f64) {
334
+ return new Vec2f64(
335
+ +v.y,
336
+ +(-(+v.x))
337
+ );
338
+ }
339
+
340
+ /**
341
+ * Returns the vector rotated 90 degrees clockwise
342
+ * @param {Vec2f64} v the base vector
343
+ * @returns {Vec2f64} the new vector rotated 90 degrees clockwise
344
+ */
345
+ static rot90(v = def_Vec2f64) {
346
+ return new Vec2f64(
347
+ +(-(+v.y)),
348
+ +v.x
349
+ );
350
+ }
351
+
352
+ /**
353
+ * Rotates a vector by the specified angle in radians
354
+ * @param {Vec2f64} v the base vector
355
+ * @param {number} radians the angle in radians
356
+ * @returns {Vec2f64} transformed output vector
357
+ */
358
+ static rotate(v = def_Vec2f64, radians = 0.0) {
359
+ return new Vec2f64(
360
+ +(+(+v.x * +mathf64_cos(+radians)) - +(+v.y * +mathf64_sin(+radians))),
361
+ +(+(+v.x * +mathf64_sin(+radians)) + +(+v.y * +mathf64_cos(+radians))),
362
+ );
363
+ }
364
+
365
+ /**
366
+ * Rotates a vector by the specified angle in radians about a specified vector
367
+ * @param {Vec2f64} a the base vector to rotate
368
+ * @param {Vec2f64} b the pivot vector to rotate about
369
+ * @param {number} radians the angle in radians
370
+ * @returns {Vec2f64} the new transformed output vector
371
+ */
372
+ static about(a = def_Vec2f64, b = def_Vec2f64, radians = 0.0) {
373
+ return new Vec2f64(
374
+ +(+b.x
375
+ + +(+(+(+a.x - +b.x) * +mathf64_cos(+radians))
376
+ - +(+(+a.y - +b.y) * +mathf64_sin(+radians)))),
377
+ +(+b.y
378
+ + +(+(+(+a.x - +b.x) * +mathf64_sin(+radians))
379
+ + +(+(+a.y - +b.y) * +mathf64_cos(+radians)))),
380
+ );
381
+ }
382
+
383
+ /**
384
+ * Linearly interpolates between two vectors
385
+ * @param {number} norm the interpolation factor
386
+ * @param {Vec2f64} a the base vector
387
+ * @param {Vec2f64} b the target vector
388
+ * @returns {Vec2f64} the new interpolated vector
389
+ */
390
+ static lerp(norm = 0.0, a = def_Vec2f64, b = def_Vec2f64) {
391
+ norm = +norm;
392
+ const ax = +a.x;
393
+ const ay = +a.y;
394
+ const bx = +b.x;
395
+ const by = +b.y;
396
+ return new Vec2f64(
397
+ +((ax + norm) * (bx - ax)),
398
+ +((ay + norm) * (by - ay)),
399
+ );
400
+ }
401
+
402
+ //#endregion
403
+
404
+ //#region vec2f in-place operators
405
+
406
+ /**
407
+ * Negates the vector in place
408
+ * @returns {Vec2f64} the negated vector
409
+ */
410
+ ineg() {
411
+ this.x = +(-(+this.x));
412
+ this.y = +(-(+this.y));
413
+ return this;
414
+ }
415
+
416
+ /**
417
+ * Adds a vector to the vector in place
418
+ * @param {Vec2f64} v the target vector
419
+ * @returns {Vec2f64} the sum of the vectors
420
+ */
421
+ iadd(v = def_Vec2f64) {
422
+ this.x += +v.x;
423
+ this.y += +v.y;
424
+ return this;
425
+ }
426
+
427
+ /**
428
+ * Adds a scalar to the vector in place
429
+ * @param {number} scalar
430
+ * @returns {Vec2f64} the vector with the scalar added
431
+ */
432
+ iadds(scalar = 0.0) {
433
+ this.x += +scalar;
434
+ this.y += +scalar;
435
+ return this;
436
+ }
437
+
438
+ /**
439
+ * Adds a vector scaled by a scalar to the vector in place
440
+ * @param {Vec2f64} v the target vector
441
+ * @param {number} scalar
442
+ * @returns {Vec2f64} the vector with the vector scaled by the scalar added
443
+ */
444
+ iaddms(v = def_Vec2f64, scalar = 1.0) {
445
+ this.x += +(+v.x * +scalar);
446
+ this.y += +(+v.y * +scalar);
447
+ return this;
448
+ }
449
+
450
+ /**
451
+ * Subtracts a vector from the vector in place
452
+ * @param {Vec2f64} v the target vector
453
+ * @returns {Vec2f64} the difference of the vectors
454
+ */
455
+ isub(v = def_Vec2f64) {
456
+ this.x -= +v.x;
457
+ this.y -= +v.y;
458
+ return this;
459
+ }
460
+
461
+ /**
462
+ * Subtracts a scalar from the vector in place
463
+ * @param {number} scalar
464
+ * @returns {Vec2f64} the vector with the scalar subtracted
465
+ */
466
+ isubs(scalar = 0.0) {
467
+ this.x -= +scalar;
468
+ this.y -= +scalar;
469
+ return this;
470
+ }
471
+
472
+ /**
473
+ * Multiplies the vector by a vector in place
474
+ * @param {Vec2f64} v the target vector
475
+ * @returns {Vec2f64} the product of the vectors
476
+ */
477
+ imul(v = def_Vec2f64) {
478
+ this.x *= +v.x;
479
+ this.y *= +v.y;
480
+ return this;
481
+ }
482
+
483
+ /**
484
+ * Multiplies the vector by a scalar in place
485
+ * @param {number} scalar
486
+ * @returns {Vec2f64} the vector with the scalar multiplied
487
+ */
488
+ imuls(scalar = 0.0) {
489
+ this.x *= +scalar;
490
+ this.y *= +scalar;
491
+ return this;
492
+ }
493
+
494
+ /**
495
+ * Divides the vector by a vector in place
496
+ * @param {Vec2f64} v the target vector
497
+ * @returns {Vec2f64} the quotient of the vectors
498
+ */
499
+ idiv(v = def_Vec2f64) {
500
+ this.x /= +v.x;
501
+ this.y /= +v.y;
502
+ return this;
503
+ }
504
+
505
+ /**
506
+ * Divides a vector by a scalar in place
507
+ * @param {number} scalar
508
+ * @returns {Vec2f64} the vector with the scalar divided
509
+ */
510
+ idivs(scalar = 0.0) {
511
+ this.x /= +scalar;
512
+ this.y /= +scalar;
513
+ return this;
514
+ }
515
+
516
+ /**
517
+ * Inverts the vector in place
518
+ * @returns {Vec2f64} the inverted vector
519
+ */
520
+ iinv() {
521
+ this.x = 1.0 / +this.x;
522
+ this.y = 1.0 / +this.y;
523
+ return this;
524
+ }
525
+
526
+ /**
527
+ * Rounds the vector in place
528
+ * @returns {Vec2f64} the rounded vector
529
+ */
530
+ iceil() {
531
+ this.x = +mathf64_ceil(+this.x);
532
+ this.y = +mathf64_ceil(+this.y);
533
+ return this;
534
+ }
535
+
536
+ /**
537
+ * Floors the vector in place
538
+ * @returns {Vec2f64} the floored vector
539
+ */
540
+ ifloor() {
541
+ this.x = +mathf64_floor(+this.x);
542
+ this.y = +mathf64_floor(+this.y);
543
+ return this;
544
+ }
545
+
546
+ /**
547
+ * Rounds the vector in place
548
+ * @returns {Vec2f64} the rounded vector
549
+ */
550
+ iround() {
551
+ this.x = +mathf64_round(+this.x);
552
+ this.y = +mathf64_round(+this.y);
553
+ return this;
554
+ }
555
+
556
+ /**
557
+ * Returns the minimum of two vectors in place
558
+ * @param {Vec2f64} v the target vector
559
+ * @returns {Vec2f64} the minimum of two vectors
560
+ */
561
+ imin(v = def_Vec2f64) {
562
+ this.x = +mathf64_min(+this.x, +v.x);
563
+ this.y = +mathf64_min(+this.y, +v.y);
564
+ return this;
565
+ }
566
+
567
+ /**
568
+ * Returns the maximum of two vectors in place
569
+ * @param {Vec2f64} v the target vector
570
+ * @returns {Vec2f64} the maximum of two vectors
571
+ */
572
+ imax(v = def_Vec2f64) {
573
+ this.x = +mathf64_max(+this.x, +v.x);
574
+ this.y = +mathf64_max(+this.y, +v.y);
575
+ return this;
576
+ }
577
+
578
+ /**
579
+ * Returns the square of the magnitude of the vector
580
+ * @returns {number} the square of the magnitude of the vector
581
+ */
582
+ mag2() {
583
+ return +Float64.mag2(+this.x, +this.y);
584
+ }
585
+
586
+ /**
587
+ * Returns the magnitude of the vector
588
+ * @returns {number} the magnitude of the vector
589
+ */
590
+ mag() {
591
+ return +Float64.mag(+this.x, +this.y);
592
+ }
593
+
594
+ /**
595
+ * Returns the angle in radians of its vector
596
+ * @returns {number} the angle in radians of its vector
597
+ */
598
+ phi() {
599
+ return Vec2f64.phi(this);
600
+ }
601
+
602
+ /**
603
+ * Returns the dot product of this vector and the target vector
604
+ * @param {Vec2f64} v the target vector
605
+ * @returns {number} the dot product of two vectors
606
+ */
607
+ dot(v = def_Vec2f64) {
608
+ return Vec2f64.dot(this, v);
609
+ }
610
+
611
+ /**
612
+ * Returns the cross-product of this vector and the target vector
613
+ * @param {Vec2f64} v the target vector
614
+ * @returns {number} The cross product of two vectors
615
+ */
616
+ cross(v = def_Vec2f64) {
617
+ return Vec2f64.cross(this, v);
618
+ }
619
+
620
+ /**
621
+ * Returns the cross-product of three vectors
622
+ * @param {Vec2f64} a B
623
+ * @param {Vec2f64} b C
624
+ * @returns {number} The cross product of three vectors
625
+ *
626
+ */
627
+ cross3(a = def_Vec2f64, b = def_Vec2f64) {
628
+ return Vec2f64.cross3(this, a, b);
629
+ }
630
+
631
+ /**
632
+ * Returns the angle in radians of its vector
633
+ *
634
+ * Math.atan2(dy, dx) === Math.asin(dy/Math.sqrt(dx*dx + dy*dy))
635
+ *
636
+ * @returns {number} the angle in radians of its vector
637
+ */
638
+ theta() {
639
+ return Float64.theta(+this.x, +this.y);
640
+ }
641
+
642
+
643
+ /**
644
+ * Returns the unit vector of its vector in place
645
+ * @returns {Vec2f64} the unit vector of its vector
646
+ */
647
+ iunit() {
648
+ return this.idivs(+this.mag());
649
+ }
650
+
651
+ /**
652
+ * Rotates a vector 90 degrees counter-clockwise in place
653
+ * @returns {Vec2f64} the vector rotated 90 degrees counter-clockwise
654
+ */
655
+ irotn90() {
656
+ const x = +this.x;
657
+ this.x = +this.y;
658
+ this.y = +(-x);
659
+ return this;
660
+ }
661
+
662
+ /**
663
+ * Rotates a vector 90 degrees clockwise in place
664
+ * @returns {Vec2f64} the vector rotated 90 degrees clockwise
665
+ */
666
+ irot90() {
667
+ const x = +this.x;
668
+ this.x = +(-(+this.y));
669
+ this.y = +x;
670
+ return this;
671
+ }
672
+
673
+ /**
674
+ * Rotates a vector by the specified angle in radians in place
675
+ * @param {number} radians angle in radians
676
+ * @returns {Vec2f64} transformed output vector
677
+ */
678
+ irotate(radians = 0.0) {
679
+ const x = +this.x;
680
+ const y = +this.y;
681
+ this.x = +(+(x * +mathf64_cos(+radians)) - +(y * +mathf64_sin(+radians)));
682
+ this.y = +(+(x * +mathf64_sin(+radians)) + +(y * +mathf64_cos(+radians)));
683
+ return this;
684
+ }
685
+
686
+ /**
687
+ * Rotates a vector by the specified angle in radians about a specified vector in place
688
+ * @param {Vec2f64} v the pivot vector
689
+ * @param {number} radians the angle in radians to rotate by
690
+ * @returns {Vec2f64} transformed output vector
691
+ */
692
+ iabout(v = def_Vec2f64, radians = 0.0) {
693
+ const dx = +(+this.x - +v.x);
694
+ const dy = +(+this.y - +v.y);
695
+ this.x = +(+v.x + +(+(dx * +mathf64_cos(+radians))
696
+ - +(dy * +mathf64_sin(+radians))));
697
+ this.y = +(+v.y + +(+(dx * +mathf64_sin(+radians))
698
+ + +(dy * +mathf64_cos(+radians))));
699
+ return this;
700
+ }
701
+
702
+ //#endregion
703
+
704
+ }
705
+
706
+ export const def_Vec2f64 = Object.freeze(Object.seal(Vec2f64.new()));