@fimbul-works/vec 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Claus Nuoskanen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @fimbul-works/vec
2
+
3
+ A high-performance TypeScript vector math library providing 2D, 3D, and 4D vector operations with a focus on performance and type safety.
4
+
5
+ [![npm version](https://badge.fury.io/js/%40fimbul-works%2Fvec.svg)](https://www.npmjs.com/package/@fimbul-works/vec)
6
+ [![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/microsoft/TypeScript)
7
+
8
+ ## Features
9
+
10
+ - 🚀 **Optimized Performance**: Uses `Float64Array` with magnitude caching and private fields
11
+ - 🛡️ **Type Safety**: Full TypeScript support with strict typing and readonly options
12
+ - 📏 **Multiple Distance Metrics**: Euclidean, Manhattan, Chebyshev, and Minkowski
13
+ - 🔒 **Immutability Support**: Both mutable and immutable operation modes
14
+ - 🎨 **Color Operations**: Built-in RGBA and RGB color handling
15
+ - 🎮 **Graphics Ready**: Homogeneous coordinates and transformation support
16
+ - 🧮 **Math Features**: Comprehensive geometric and arithmetic operations
17
+ - ⚡ **Memory Efficient**: Zero-allocation options for performance-critical code
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @fimbul-works/vec
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ import { Vec2, Vec3, Vec4 } from "@fimbul-works/vec";
29
+
30
+ // Create and manipulate vectors
31
+ const position = new Vec2(100, 200);
32
+ const direction = new Vec2(1, 0).rotate(Math.PI / 4);
33
+ const movement = Vec2.scale(direction, 5);
34
+
35
+ position.add(movement);
36
+
37
+ // 3D graphics with homogeneous coordinates
38
+ const point = new Vec4(x, y, z, 1); // Point in 3D space
39
+ const vector = new Vec4(dx, dy, dz, 0); // Direction in 3D space
40
+
41
+ // Color manipulation
42
+ const color = new Vec4(1, 0, 0, 0.5); // Semi-transparent red
43
+ ```
44
+
45
+ ## Zero-Allocation Usage
46
+
47
+ ```typescript
48
+ // Reuse vectors to avoid garbage collection
49
+ const result = new Vec2();
50
+ const temp = new Vec2();
51
+
52
+ // Chain operations without creating intermediates
53
+ position
54
+ .add(velocity.scale(deltaTime, temp))
55
+ .clamp(0, 100);
56
+ ```
57
+
58
+ ## Core Operations
59
+
60
+ ```typescript
61
+ // Static operations (immutable)
62
+ const sum = Vec2.add(v1, v2);
63
+ const dot = Vec3.dot(v1, v2);
64
+ const cross = Vec3.cross(v1, v2);
65
+
66
+ // Method chaining (mutable)
67
+ const result = new Vec3(1, 0, 0)
68
+ .rotate(angle)
69
+ .scale(2)
70
+ .normalize();
71
+
72
+ // Distance calculations
73
+ const dist = v1.distance(v2);
74
+ const manhattan = v1.distanceManhattan(v2);
75
+ ```
76
+
77
+ ## Complete API Documentation
78
+
79
+ - [Vec2 API Documentation](./VEC2.md)
80
+ - [Vec3 API Documentation](./VEC3.md)
81
+ - [Vec4 API Documentation](./VEC4.md)
82
+
83
+ ## License
84
+
85
+ MIT License - See [LICENSE](LICENSE) file for details.
86
+
87
+ ---
88
+
89
+ Built with ⚡ by [FimbulWorks](https://github.com/fimbul-works)
@@ -0,0 +1,3 @@
1
+ export * from "./vec2.js";
2
+ export * from "./vec3.js";
3
+ export * from "./vec4.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./vec2.js";
2
+ export * from "./vec3.js";
3
+ export * from "./vec4.js";
package/dist/vec2.d.ts ADDED
@@ -0,0 +1,531 @@
1
+ /**
2
+ * Represents a 2D vector with various operations.
3
+ */
4
+ export declare class Vec2 {
5
+ #private;
6
+ /**
7
+ * Creates a new Vec2 instance.
8
+ * @param x - The x-coordinate of the vector.
9
+ * @param y - The y-coordinate of the vector.
10
+ */
11
+ constructor(x?: number, y?: number);
12
+ /**
13
+ * Adds two vectors.
14
+ * @param v - The first vector.
15
+ * @param w - The second vector.
16
+ * @returns A new Vec2 instance representing the sum.
17
+ */
18
+ static add(v: Vec2, w: Vec2): Vec2;
19
+ /**
20
+ * Subtracts one vector from another.
21
+ * @param v - The vector to subtract from.
22
+ * @param w - The vector to subtract.
23
+ * @returns A new Vec2 instance representing the difference.
24
+ */
25
+ static subtract(v: Vec2, w: Vec2): Vec2;
26
+ /**
27
+ * Multiplies one vector with another.
28
+ * @param v - The first vector.
29
+ * @param w - The second vector.
30
+ * @returns A new Vec2 instance representing the multiplied value.
31
+ */
32
+ static multiply(v: Vec2, w: Vec2): Vec2;
33
+ /**
34
+ * Divides one vector with another.
35
+ * @param v - Divident.
36
+ * @param w - Divisor.
37
+ * @returns A new Vec2 instance representing the divided value.
38
+ */
39
+ static divide(v: Vec2, w: Vec2): Vec2;
40
+ /**
41
+ * Calculates the angle between two vectors.
42
+ * @param v - The first vector.
43
+ * @param w - The second vector.
44
+ * @returns The angle between the vectors in radians.
45
+ */
46
+ static angleBetween(v: Vec2, w: Vec2): number;
47
+ /**
48
+ * Calculates the Euclidean distance between two vectors.
49
+ * @param v - The first vector.
50
+ * @param w - The second vector.
51
+ * @returns The distance between the vectors.
52
+ */
53
+ static distance(v: Vec2, w: Vec2): number;
54
+ /**
55
+ * Calculates the Chebyshev distance between two vectors.
56
+ * @param v - The first vector.
57
+ * @param w - The second vector.
58
+ * @returns The Chebyshev distance between the vectors.
59
+ */
60
+ static distanceChebyshev(v: Vec2, w: Vec2): number;
61
+ /**
62
+ * Calculates the Manhattan distance between two vectors.
63
+ * @param v - The first vector.
64
+ * @param w - The second vector.
65
+ * @returns The Manhattan distance between the vectors.
66
+ */
67
+ static distanceManhattan(v: Vec2, w: Vec2): number;
68
+ /**
69
+ * Calculates the Minkowski distance between two vectors.
70
+ * @param v - The first vector.
71
+ * @param w - The second vector.
72
+ * @param p - The order of the Minkowski distance.
73
+ * @returns The Minkowski distance between the vectors.
74
+ */
75
+ static distanceMinkowski(v: Vec2, w: Vec2, p: number): number;
76
+ /**
77
+ * Calculates the squared Euclidean distance between two vectors.
78
+ * @param v - The first vector.
79
+ * @param w - The second vector.
80
+ * @returns The squared distance between the vectors.
81
+ */
82
+ static distanceSq(v: Vec2, w: Vec2): number;
83
+ /**
84
+ * Calculates the dot product of two vectors.
85
+ * @param v - The first vector.
86
+ * @param w - The second vector.
87
+ * @returns The dot product of the vectors.
88
+ */
89
+ static dot(v: Vec2, w: Vec2): number;
90
+ /**
91
+ * Calculates the cross product of two vectors.
92
+ * @param v - The first vector.
93
+ * @param w - The second vector.
94
+ * @returns The cross product scalar value.
95
+ */
96
+ static cross(v: Vec2, w: Vec2): number;
97
+ /**
98
+ * Reflects the vector across a normal vector.
99
+ * @param v - The vector to reflect.
100
+ * @param normal - The normal vector to reflect across (must be normalized).
101
+ * @returns A new Vec2 instance representing the reflected vector.
102
+ */
103
+ static reflect(v: Vec2, normal: Vec2): Vec2;
104
+ /**
105
+ * Creates a Vec2 instance from polar coordinates.
106
+ * @param r - The radius.
107
+ * @param theta - The angle in radians.
108
+ * @returns A new Vec2 instance.
109
+ */
110
+ static fromPolarCoords(r: number, theta: number): Vec2;
111
+ /**
112
+ * Creates an immutable Vec2-like object.
113
+ * @param x - The x-coordinate of the vector.
114
+ * @param y - The y-coordinate of the vector.
115
+ * @returns An immutable object with Vec2-like properties.
116
+ */
117
+ static immutable(x?: number, y?: number): Readonly<{
118
+ angleX: number;
119
+ angleY: number;
120
+ isInfinite: boolean;
121
+ isNaN: boolean;
122
+ isZero: boolean;
123
+ magnitude: number;
124
+ magnitudeSq: number;
125
+ x: number;
126
+ xy: readonly number[];
127
+ y: number;
128
+ }>;
129
+ /**
130
+ * Checks if a vector has infinite components.
131
+ * @param v - The vector to check.
132
+ * @returns True if the vector has infinite components, false otherwise.
133
+ */
134
+ static isInfinite(v: Vec2): boolean;
135
+ /**
136
+ * Checks if a vector has NaN components.
137
+ * @param v - The vector to check.
138
+ * @returns True if the vector has NaN components, false otherwise.
139
+ */
140
+ static isNaN(v: Vec2): boolean;
141
+ /**
142
+ * Checks if a vector is zero.
143
+ * @param v - The vector to check.
144
+ * @returns True if the vector is zero, false otherwise.
145
+ */
146
+ static isZero(v: Vec2): boolean;
147
+ /**
148
+ * Performs linear interpolation between two vectors.
149
+ * @param v - The first vector.
150
+ * @param w - The second vector.
151
+ * @param t - The interpolation parameter (0 to 1).
152
+ * @returns A new Vec2 instance representing the interpolated vector.
153
+ */
154
+ static lerp(v: Vec2, w: Vec2, t: number): Vec2;
155
+ /**
156
+ * Negates a vector.
157
+ * @param v - The vector to negate.
158
+ * @returns A new Vec2 instance representing the negated vector.
159
+ */
160
+ static negate(v: Vec2): Vec2;
161
+ /**
162
+ * Normalizes a vector.
163
+ * @param v - The vector to normalize.
164
+ * @returns A new Vec2 instance representing the normalized vector.
165
+ */
166
+ static normalize(v: Vec2): Vec2;
167
+ /**
168
+ * Projects one vector onto another.
169
+ * @param v - The vector to project.
170
+ * @param w - The vector to project onto.
171
+ * @returns A new Vec2 instance representing the projected vector.
172
+ */
173
+ static project(v: Vec2, w: Vec2): Vec2;
174
+ /**
175
+ * Creates a random unit vector.
176
+ * @param random - A function that returns a random number between 0 and 1.
177
+ * @returns A new Vec2 instance representing a random unit vector.
178
+ */
179
+ static random(random?: () => number): Vec2;
180
+ /**
181
+ * Checks if two vectors are equal.
182
+ * @param v - The first vector.
183
+ * @param w - The second vector.
184
+ * @returns True if the vectors are equal, false otherwise.
185
+ */
186
+ static satisfyEquality(v: Vec2, w: Vec2): boolean;
187
+ /**
188
+ * Checks if two vectors are opposite.
189
+ * @param v - The first vector.
190
+ * @param w - The second vector.
191
+ * @returns True if the vectors are opposite, false otherwise.
192
+ */
193
+ static satisfyOpposition(v: Vec2, w: Vec2): boolean;
194
+ /**
195
+ * Compares a vector with another vector using an epsilon value for floating-point comparison.
196
+ * @param v - The first vector.
197
+ * @param w - The second vector.
198
+ * @param epsilon - The maximum difference between components to consider them equal.
199
+ * @returns True if the vectors are equal within epsilon, false otherwise.
200
+ */
201
+ static equals(v: Vec2, w: Vec2, epsilon?: number): boolean;
202
+ /**
203
+ * Scales a vector by a scalar value.
204
+ * @param v - The vector to scale.
205
+ * @param c - The scalar value.
206
+ * @returns A new Vec2 instance representing the scaled vector.
207
+ */
208
+ static scale(v: Vec2, c: number): Vec2;
209
+ /**
210
+ * Creates a zero vector.
211
+ * @returns A new Vec2 instance representing a zero vector.
212
+ */
213
+ static zero(): Vec2;
214
+ /**
215
+ * Creates a vector with all components set to 1.0.
216
+ * @returns A new Vec2 instance representing a vector with all components set to 1.0.
217
+ */
218
+ static one(): Vec2;
219
+ /**
220
+ * Creates a Vec2 from an array.
221
+ * @returns A new Vec2 instance.
222
+ */
223
+ static fromArray(arr: [number, number] | number[]): Vec2;
224
+ /**
225
+ * Creates a Vec2 from an object with x and y properties.
226
+ * @returns A new Vec2 instance.
227
+ */
228
+ static fromObject(obj: {
229
+ x: number;
230
+ y: number;
231
+ }): Vec2;
232
+ /**
233
+ * Creates a Vec2 instance from a JSON-parsed object.
234
+ * @param json - The JSON-parsed object containing x and y properties.
235
+ * @returns A new Vec2 instance.
236
+ */
237
+ static fromJSON(json: {
238
+ x: number;
239
+ y: number;
240
+ }): Vec2;
241
+ /**
242
+ * Gets the x-component of the vector.
243
+ * @returns The x-component.
244
+ */
245
+ get x(): number;
246
+ /**
247
+ * Sets the x-component of the vector.
248
+ * @param x - The new x-component.
249
+ */
250
+ set x(x: number);
251
+ /**
252
+ * Gets the y-component of the vector.
253
+ * @returns The y-component.
254
+ */
255
+ get y(): number;
256
+ /**
257
+ * Sets the y-component of the vector.
258
+ * @param y - The new y-component.
259
+ */
260
+ set y(y: number);
261
+ /**
262
+ * Gets a copy of the vector's components as an array.
263
+ * @returns An array containing the x and y components of the vector.
264
+ */
265
+ get xy(): [number, number];
266
+ /**
267
+ * Sets both components of the vector at once.
268
+ * @param xy - An array containing the new x and y components.
269
+ */
270
+ set xy(xy: [number, number] | number[]);
271
+ /**
272
+ * Gets the angle between the vector and the positive x-axis in radians.
273
+ * @returns The angle in radians, always in the range [0, 2π).
274
+ */
275
+ get angleX(): number;
276
+ /**
277
+ * Sets the angle between the vector and the positive x-axis, maintaining the vector's magnitude.
278
+ * @param phi - The new angle in radians.
279
+ */
280
+ set angleX(phi: number);
281
+ /**
282
+ * Gets the angle between the vector and the positive y-axis in radians.
283
+ * @returns The angle in radians, always in the range [0, 2π).
284
+ */
285
+ get angleY(): number;
286
+ /**
287
+ * Sets the angle between the vector and the positive y-axis, maintaining the vector's magnitude.
288
+ * @param phi - The new angle in radians.
289
+ */
290
+ set angleY(phi: number);
291
+ /**
292
+ * Gets the magnitude (length) of the vector.
293
+ * @returns The magnitude of the vector.
294
+ */
295
+ get magnitude(): number;
296
+ /**
297
+ * Sets the magnitude (length) of the vector, maintaining its direction.
298
+ * @param m - The new magnitude.
299
+ */
300
+ set magnitude(m: number);
301
+ /**
302
+ * Gets the squared magnitude of the vector.
303
+ * This is faster to compute than the actual magnitude and is useful for comparisons.
304
+ * @returns The squared magnitude of the vector.
305
+ */
306
+ get magnitudeSq(): number;
307
+ /**
308
+ * Adds another vector to this vector.
309
+ * @param v - The vector to add.
310
+ * @returns This Vec2 instance for method chaining.
311
+ */
312
+ add(v: Vec2): this;
313
+ /**
314
+ * Subtracts another vector from this vector.
315
+ * @param v - The vector to subtract.
316
+ * @returns This Vec2 instance for method chaining.
317
+ */
318
+ subtract(v: Vec2): this;
319
+ /**
320
+ * Multiplies this vector with another vector.
321
+ * @param v - The vector to multiply with.
322
+ * @returns This Vec2 instance for method chaining.
323
+ */
324
+ multiply(v: Vec2): this;
325
+ /**
326
+ * Divides this vector with another vector.
327
+ * @param v - The vector to divide with.
328
+ * @returns This Vec2 instance for method chaining.
329
+ */
330
+ divide(v: Vec2): this;
331
+ /**
332
+ * Calculates the angle between this vector and another vector.
333
+ * @param v - The other vector.
334
+ * @returns The angle between the vectors in radians.
335
+ */
336
+ angleBetween(v: Vec2): number;
337
+ /**
338
+ * Clamps the magnitude of this vector between a minimum and maximum value.
339
+ * @param min - The minimum magnitude.
340
+ * @param max - The maximum magnitude.
341
+ * @returns This Vec2 instance for method chaining.
342
+ */
343
+ clamp(min: number, max: number): this;
344
+ /**
345
+ * Creates a copy of this vector.
346
+ * @returns A new Vec2 instance with the same components.
347
+ */
348
+ clone(): Vec2;
349
+ /**
350
+ * Copies the components of another vector to this vector.
351
+ * @param v - The vector to copy from.
352
+ * @returns This Vec2 instance for method chaining.
353
+ */
354
+ copy(v: Vec2): this;
355
+ /**
356
+ * Calculates the distance between this vector and another vector.
357
+ * @param v - The other vector.
358
+ * @returns The distance between the vectors.
359
+ */
360
+ distance(v: Vec2): number;
361
+ /**
362
+ * Calculates the Chebyshev distance between this vector and another vector.
363
+ * @param v - The other vector.
364
+ * @returns The Chebyshev distance between the vectors.
365
+ */
366
+ distanceChebyshev(v: Vec2): number;
367
+ /**
368
+ * Calculates the Manhattan distance between this vector and another vector.
369
+ * @param v - The other vector.
370
+ * @returns The Manhattan distance between the vectors.
371
+ */
372
+ distanceManhattan(v: Vec2): number;
373
+ /**
374
+ * Calculates the Minkowski distance between this vector and another vector.
375
+ * @param v - The other vector.
376
+ * @param p - The order of the Minkowski distance.
377
+ * @returns The Minkowski distance between the vectors.
378
+ */
379
+ distanceMinkowski(v: Vec2, p: number): number;
380
+ /**
381
+ * Calculates the squared distance between this vector and another vector.
382
+ * @param v - The other vector.
383
+ * @returns The squared distance between the vectors.
384
+ */
385
+ distanceSq(v: Vec2): number;
386
+ /**
387
+ * Calculates the dot product of this vector with another vector.
388
+ * @param v - The other vector.
389
+ * @returns The dot product of the vectors.
390
+ */
391
+ dot(v: Vec2): number;
392
+ /**
393
+ * Calculates the cross product of this vector with another vector.
394
+ * @param v - The other vector.
395
+ * @returns The cross product of the vectors.
396
+ */
397
+ cross(v: Vec2): number;
398
+ /**
399
+ * Reflects this vector across a normal vector.
400
+ * @param normal - The normal vector to reflect across (must be normalized).
401
+ * @returns A new Vec2 instance representing the reflected vector.
402
+ */
403
+ reflect(normal: Vec2): Vec2;
404
+ /**
405
+ * Checks if this vector has infinite components.
406
+ * @returns True if the vector has infinite components, false otherwise.
407
+ */
408
+ isInfinite(): boolean;
409
+ /**
410
+ * Checks if this vector has NaN components.
411
+ * @returns True if the vector has NaN components, false otherwise.
412
+ */
413
+ isNaN(): boolean;
414
+ /**
415
+ * Checks if this vector is zero.
416
+ * @returns True if the vector is zero, false otherwise.
417
+ */
418
+ isZero(): boolean;
419
+ /**
420
+ * Limits the maximum magnitude of this vector.
421
+ * @param max - The maximum magnitude.
422
+ * @returns This Vec2 instance for method chaining.
423
+ */
424
+ limitMax(max: number): this;
425
+ /**
426
+ * Limits the minimum magnitude of this vector.
427
+ * @param min - The minimum magnitude.
428
+ * @returns This Vec2 instance for method chaining.
429
+ */
430
+ limitMin(min: number): this;
431
+ /**
432
+ * Sets this vector to point towards another vector.
433
+ * @param v - The vector to look at.
434
+ * @returns This Vec2 instance for method chaining.
435
+ */
436
+ lookAt(v: Vec2): this;
437
+ /**
438
+ * Negates this vector.
439
+ * @returns This Vec2 instance for method chaining.
440
+ */
441
+ negate(): this;
442
+ /**
443
+ * Normalizes this vector.
444
+ * @returns This Vec2 instance for method chaining.
445
+ */
446
+ normalize(): this;
447
+ /**
448
+ * Projects this vector onto another vector.
449
+ * @param v - The vector to project onto.
450
+ * @returns This Vec2 instance for method chaining.
451
+ */
452
+ project(v: Vec2): this;
453
+ /**
454
+ * Sets this vector to a random direction with the same magnitude.
455
+ * @param random - A function that returns a random number between 0 and 1.
456
+ * @returns This Vec2 instance for method chaining.
457
+ */
458
+ random(random?: () => number): this;
459
+ /**
460
+ * Rotates this vector around the Z-axis.
461
+ * @param phi - The angle of rotation in radians.
462
+ * @returns This Vec2 instance for method chaining.
463
+ */
464
+ rotateZ(phi: number): this;
465
+ /**
466
+ * Checks if this vector is equal to another vector.
467
+ * @param v - The other vector.
468
+ * @returns True if the vectors are equal, false otherwise.
469
+ */
470
+ satisfyEquality(v: Vec2): boolean;
471
+ /**
472
+ * Checks if this vector is opposite to another vector.
473
+ * @param v - The other vector.
474
+ * @returns True if the vectors are opposite, false otherwise.
475
+ */
476
+ satisfyOpposition(v: Vec2): boolean;
477
+ /**
478
+ * Compares this vector with another vector using an epsilon value for floating-point comparison.
479
+ * @param v - The vector to compare with.
480
+ * @param epsilon - The maximum difference between components to consider them equal.
481
+ * @returns True if the vectors are equal within epsilon, false otherwise.
482
+ */
483
+ equals(v: Vec2, epsilon?: number): boolean;
484
+ /**
485
+ * Scales this vector by a scalar value.
486
+ * @param c - The scalar value.
487
+ * @returns This Vec2 instance for method chaining.
488
+ */
489
+ scale(c: number): this;
490
+ /**
491
+ * Rotates this vector 90 degrees to the left.
492
+ * @returns This Vec2 instance for method chaining.
493
+ */
494
+ turnLeft(): this;
495
+ /**
496
+ * Rotates this vector 90 degrees to the right.
497
+ * @returns This Vec2 instance for method chaining.
498
+ */
499
+ turnRight(): this;
500
+ /**
501
+ * Sets this vector to zero.
502
+ * @returns This Vec2 instance for method chaining.
503
+ */
504
+ zero(): this;
505
+ /**
506
+ * Makes the Vec2 instance iterable.
507
+ * @yields The x and y components of the vector.
508
+ */
509
+ [Symbol.iterator](): IterableIterator<number>;
510
+ /**
511
+ * Returns a string representation of the vector.
512
+ * @returns A string in the format "Vec2(x, y)".
513
+ */
514
+ toString(): string;
515
+ /**
516
+ * Converts the vector to a plain object.
517
+ * @returns An object with x and y properties.
518
+ */
519
+ toObject(): {
520
+ x: number;
521
+ y: number;
522
+ };
523
+ /**
524
+ * Serializes the vector to a JSON-friendly format.
525
+ * @returns A JSON-friendly object representation of the vector.
526
+ */
527
+ toJSON(): {
528
+ x: number;
529
+ y: number;
530
+ };
531
+ }