@fimbul-works/vec 1.0.2 → 1.1.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/README.md CHANGED
@@ -14,6 +14,7 @@ A high-performance TypeScript vector math library providing 2D, 3D, and 4D vecto
14
14
  - 🎮 **Graphics Ready**: Homogeneous coordinates and transformation support
15
15
  - 🧮 **Math Features**: Comprehensive geometric and arithmetic operations
16
16
  - ⚡ **Memory Efficient**: Zero-allocation options for performance-critical code
17
+ - 🎨 **Color Support**: RGB/RGBA accessors for seamless color manipulation
17
18
 
18
19
  ## Installation
19
20
 
@@ -36,6 +37,15 @@ position.add(movement);
36
37
  // 3D graphics with homogeneous coordinates
37
38
  const point = new Vec4(x, y, z, 1); // Point in 3D space
38
39
  const vector = new Vec4(dx, dy, dz, 0); // Direction in 3D space
40
+
41
+ // Color manipulation with RGB accessors
42
+ const color = new Vec3(0.8, 0.2, 0.4); // RGB values
43
+ color.r = 1.0; // Set red component
44
+ const [red, green, blue] = color.rgb;
45
+
46
+ // RGBA colors with transparency
47
+ const colorWithAlpha = new Vec4(0.8, 0.2, 0.4, 0.9);
48
+ colorWithAlpha.a = 0.5; // Set alpha to 50%
39
49
  ```
40
50
 
41
51
  ## Zero-Allocation Usage
package/VEC2.md ADDED
@@ -0,0 +1,147 @@
1
+ # Vec2
2
+
3
+ A 2D vector implementation with comprehensive mathematical operations and utility methods.
4
+
5
+ ## Constructor
6
+
7
+ ### Vec2
8
+
9
+ - `constructor(x: number = 0, y: number = x)`: Creates a new vector with the given x and y coordinates
10
+
11
+ ## Static Methods
12
+
13
+ ### Creation and Conversion
14
+
15
+ - `fromArray(arr: [number, number] | number[])`: Creates a Vec2 from an array
16
+ - `fromObject(obj: { x: number; y: number })`: Creates a Vec2 from an object with x and y properties
17
+ - `fromJSON(json: { x: number; y: number })`: Creates a Vec2 from a JSON object
18
+ - `fromPolarCoords(r: number, theta: number)`: Creates a Vec2 from polar coordinates
19
+ - `immutable(x: number = 0, y: number = 0)`: Creates an immutable Vec2-like object
20
+ - `one()`: Creates a vector with all components set to 1.0
21
+ - `random(random: () => number = Math.random)`: Creates a random unit vector
22
+ - `zero()`: Creates a zero vector
23
+
24
+ ### Vector Operations
25
+
26
+ - `add(v: Vec2, w: Vec2)`: Adds two vectors
27
+ - `subtract(v: Vec2, w: Vec2)`: Subtracts one vector from another
28
+ - `multiply(v: Vec2, w: Vec2)`: Multiplies two vectors component-wise
29
+ - `divide(v: Vec2, w: Vec2)`: Divides two vectors component-wise
30
+ - `dot(v: Vec2, w: Vec2)`: Calculates the dot product
31
+ - `cross(v: Vec2, w: Vec2)`: Calculates the cross product
32
+ - `scale(v: Vec2, c: number)`: Scales a vector by a scalar value
33
+ - `negate(v: Vec2)`: Negates a vector
34
+ - `normalize(v: Vec2)`: Normalizes a vector
35
+ - `project(v: Vec2, w: Vec2)`: Projects one vector onto another
36
+ - `reflect(v: Vec2, normal: Vec2)`: Reflects a vector across a normal vector
37
+ - `lerp(v: Vec2, w: Vec2, t: number)`: Performs linear interpolation between vectors
38
+
39
+ ### Distance Calculations
40
+
41
+ - `distance(v: Vec2, w: Vec2)`: Calculates Euclidean distance between vectors
42
+ - `distanceSq(v: Vec2, w: Vec2)`: Calculates squared Euclidean distance
43
+ - `distanceChebyshev(v: Vec2, w: Vec2)`: Calculates Chebyshev distance
44
+ - `distanceManhattan(v: Vec2, w: Vec2)`: Calculates Manhattan distance
45
+ - `distanceMinkowski(v: Vec2, w: Vec2, p: number)`: Calculates Minkowski distance
46
+
47
+ ### Comparison and State
48
+
49
+ - `angleBetween(v: Vec2, w: Vec2)`: Calculates angle between vectors
50
+ - `equals(v: Vec2, w: Vec2, epsilon?: number)`: Compares vectors with optional epsilon
51
+ - `isInfinite(v: Vec2)`: Checks if vector has infinite components
52
+ - `isNaN(v: Vec2)`: Checks if vector has NaN components
53
+ - `isZero(v: Vec2)`: Checks if vector is zero
54
+ - `satisfyEquality(v: Vec2, w: Vec2)`: Checks if vectors are equal
55
+ - `satisfyOpposition(v: Vec2, w: Vec2)`: Checks if vectors are opposite
56
+
57
+ ## Instance Properties
58
+
59
+ ### Getters and Setters
60
+
61
+ - `x`: Gets or sets the x-component
62
+ - `y`: Gets or sets the y-component
63
+ - `xy`: Gets or sets both components as an array
64
+ - `magnitude`: Gets or sets the vector's magnitude
65
+ - `magnitudeSq`: Gets the squared magnitude (read-only)
66
+ - `angleX`: Gets or sets the angle with positive x-axis
67
+ - `angleY`: Gets or sets the angle with positive y-axis
68
+
69
+ ## Instance Methods
70
+
71
+ ### Vector Operations
72
+
73
+ - `add(v: Vec2)`: Adds another vector
74
+ - `subtract(v: Vec2)`: Subtracts another vector
75
+ - `multiply(v: Vec2)`: Multiplies with another vector
76
+ - `divide(v: Vec2)`: Divides by another vector
77
+ - `scale(c: number)`: Scales by a scalar value
78
+ - `normalize()`: Normalizes the vector
79
+ - `negate()`: Negates the vector
80
+ - `project(v: Vec2)`: Projects onto another vector
81
+ - `reflect(normal: Vec2)`: Reflects across a normal vector
82
+ - `rotateZ(phi: number)`: Rotates around Z-axis
83
+ - `turnLeft()`: Rotates 90 degrees left
84
+ - `turnRight()`: Rotates 90 degrees right
85
+ - `zero()`: Sets to zero vector
86
+ - `random(random?: () => number)`: Sets to random direction
87
+
88
+ ### Distance Calculations
89
+
90
+ - `distance(v: Vec2)`: Calculates Euclidean distance to another vector
91
+ - `distanceSq(v: Vec2)`: Calculates squared Euclidean distance
92
+ - `distanceChebyshev(v: Vec2)`: Calculates Chebyshev distance
93
+ - `distanceManhattan(v: Vec2)`: Calculates Manhattan distance
94
+ - `distanceMinkowski(v: Vec2, p: number)`: Calculates Minkowski distance
95
+
96
+ ### Comparison and State
97
+
98
+ - `angleBetween(v: Vec2)`: Calculates angle to another vector
99
+ - `equals(v: Vec2, epsilon?: number)`: Compares with another vector
100
+ - `isInfinite()`: Checks for infinite components
101
+ - `isNaN()`: Checks for NaN components
102
+ - `isZero()`: Checks if zero vector
103
+ - `satisfyEquality(v: Vec2)`: Checks equality with another vector
104
+ - `satisfyOpposition(v: Vec2)`: Checks opposition with another vector
105
+
106
+ ### Magnitude Operations
107
+
108
+ - `clamp(min: number, max: number)`: Clamps magnitude between values
109
+ - `limitMax(max: number)`: Limits maximum magnitude
110
+ - `limitMin(min: number)`: Limits minimum magnitude
111
+
112
+ ### Utility Methods
113
+
114
+ - `clone()`: Creates a copy of the vector
115
+ - `copy(v: Vec2)`: Copies components from another vector
116
+ - `lookAt(v: Vec2)`: Points towards another vector
117
+ - `toString()`: Returns string representation
118
+ - `toObject()`: Converts to plain object
119
+ - `toJSON()`: Converts to JSON format
120
+
121
+ ## Iteration
122
+
123
+ Vec2 implements the iterator protocol, allowing it to be used with for...of loops and spread operators. The iterator yields the x and y components in order.
124
+
125
+ ## Example Usage
126
+
127
+ ```typescript
128
+ // Create vectors
129
+ const v1 = new Vec2(3, 4);
130
+ const v2 = new Vec2(1, 2);
131
+
132
+ // Basic operations
133
+ const sum = Vec2.add(v1, v2);
134
+ const dot = Vec2.dot(v1, v2);
135
+
136
+ // Method chaining
137
+ v1.normalize()
138
+ .scale(2)
139
+ .rotate(Math.PI / 4);
140
+
141
+ // Get properties
142
+ console.log(v1.magnitude);
143
+ console.log(v1.angleX);
144
+
145
+ // Convert to array
146
+ const [x, y] = v1;
147
+ ```
package/VEC3.md ADDED
@@ -0,0 +1,172 @@
1
+ # Vec3
2
+
3
+ A 3D vector implementation with comprehensive mathematical operations and utility methods.
4
+
5
+ ## Constructor
6
+
7
+ ### Vec3
8
+
9
+ - `constructor(x: number = 0, y: number = 0, z: number = 0)`: Creates a new vector with the given x, y and z coordinates
10
+
11
+ ## Static Methods
12
+
13
+ ### Creation and Conversion
14
+
15
+ - `fromArray(arr: [number, number, number] | number[])`: Creates a Vec3 from an array
16
+ - `fromObject(obj: { x: number; y: number; z: number })`: Creates a Vec3 from an object with x, y and z properties
17
+ - `fromJSON(json: { x: number; y: number; z: number })`: Creates a Vec3 from a JSON object
18
+ - `fromCylindricalCoords(r: number, phi: number, z: number)`: Creates a Vec3 from cylindrical coordinates
19
+ - `fromSphericalCoords(r: number, theta: number, phi: number)`: Creates a Vec3 from spherical coordinates
20
+ - `immutable(x: number = 0, y: number = 0, z: number = 0)`: Creates an immutable Vec3-like object
21
+ - `one()`: Creates a vector with all components set to 1.0
22
+ - `random(random: () => number = Math.random)`: Creates a random unit vector
23
+ - `zero()`: Creates a zero vector
24
+
25
+ ### Vector Operations
26
+
27
+ - `add(v: Vec3, w: Vec3)`: Adds two vectors
28
+ - `subtract(v: Vec3, w: Vec3)`: Subtracts one vector from another
29
+ - `multiply(v: Vec3, w: Vec3)`: Multiplies two vectors component-wise
30
+ - `divide(v: Vec3, w: Vec3)`: Divides two vectors component-wise
31
+ - `dot(v: Vec3, w: Vec3)`: Calculates the dot product
32
+ - `cross(v: Vec3, w: Vec3)`: Calculates the cross product
33
+ - `scale(v: Vec3, c: number)`: Scales a vector by a scalar value
34
+ - `negate(v: Vec3)`: Negates a vector
35
+ - `normalize(v: Vec3)`: Normalizes a vector
36
+ - `project(v: Vec3, w: Vec3)`: Projects one vector onto another
37
+ - `reflect(v: Vec3, normal: Vec3)`: Reflects a vector across a normal vector
38
+ - `lerp(v: Vec3, w: Vec3, t: number)`: Performs linear interpolation between vectors
39
+
40
+ ### Distance Calculations
41
+
42
+ - `distance(v: Vec3, w: Vec3)`: Calculates Euclidean distance between vectors
43
+ - `distanceSq(v: Vec3, w: Vec3)`: Calculates squared Euclidean distance
44
+ - `distanceChebyshev(v: Vec3, w: Vec3)`: Calculates Chebyshev distance
45
+ - `distanceManhattan(v: Vec3, w: Vec3)`: Calculates Manhattan distance
46
+ - `distanceMinkowski(v: Vec3, w: Vec3, p: number)`: Calculates Minkowski distance
47
+
48
+ ### Comparison and State
49
+
50
+ - `angleBetween(v: Vec3, w: Vec3)`: Calculates angle between vectors
51
+ - `equals(v: Vec3, w: Vec3, epsilon?: number)`: Compares vectors with optional epsilon
52
+ - `isInfinite(v: Vec3)`: Checks if vector has infinite components
53
+ - `isNaN(v: Vec3)`: Checks if vector has NaN components
54
+ - `isZero(v: Vec3)`: Checks if vector is zero
55
+ - `satisfyEquality(v: Vec3, w: Vec3)`: Checks if vectors are equal
56
+ - `satisfyOpposition(v: Vec3, w: Vec3)`: Checks if vectors are opposite
57
+
58
+ ## Instance Properties
59
+
60
+ ### Getters and Setters
61
+
62
+ - `x`: Gets or sets the x-component
63
+ - `y`: Gets or sets the y-component
64
+ - `z`: Gets or sets the z-component
65
+ - `xyz`: Gets or sets all components as an array
66
+ - `r`: Gets or sets the red component (alias for x)
67
+ - `g`: Gets or sets the green component (alias for y)
68
+ - `b`: Gets or sets the blue component (alias for z)
69
+ - `rgb`: Gets or sets all color components as an array (alias for xyz)
70
+ - `magnitude`: Gets or sets the vector's magnitude
71
+ - `magnitudeSq`: Gets the squared magnitude (read-only)
72
+ - `angleX`: Gets the angle with positive x-axis
73
+ - `angleY`: Gets the angle with positive y-axis
74
+ - `angleZ`: Gets the angle with positive z-axis
75
+
76
+ ## Instance Methods
77
+
78
+ ### Vector Operations
79
+
80
+ - `add(v: Vec3)`: Adds another vector
81
+ - `subtract(v: Vec3)`: Subtracts another vector
82
+ - `multiply(v: Vec3)`: Multiplies with another vector
83
+ - `divide(v: Vec3)`: Divides by another vector
84
+ - `scale(c: number)`: Scales by a scalar value
85
+ - `normalize()`: Normalizes the vector
86
+ - `negate()`: Negates the vector
87
+ - `project(v: Vec3)`: Projects onto another vector
88
+ - `reflect(normal: Vec3)`: Reflects across a normal vector
89
+ - `rotateX(phi: number)`: Rotates around X-axis
90
+ - `rotateY(phi: number)`: Rotates around Y-axis
91
+ - `rotateZ(phi: number)`: Rotates around Z-axis
92
+ - `zero()`: Sets to zero vector
93
+ - `random(random?: () => number)`: Sets to random direction
94
+
95
+ ### Distance Calculations
96
+
97
+ - `distance(v: Vec3)`: Calculates Euclidean distance to another vector
98
+ - `distanceSq(v: Vec3)`: Calculates squared Euclidean distance
99
+ - `distanceChebyshev(v: Vec3)`: Calculates Chebyshev distance
100
+ - `distanceManhattan(v: Vec3)`: Calculates Manhattan distance
101
+ - `distanceMinkowski(v: Vec3, p: number)`: Calculates Minkowski distance
102
+
103
+ ### Cross Product
104
+
105
+ - `cross(v: Vec3)`: Calculates the cross product with another vector
106
+
107
+ ### Comparison and State
108
+
109
+ - `angleBetween(v: Vec3)`: Calculates angle to another vector
110
+ - `equals(v: Vec3, epsilon?: number)`: Compares with another vector
111
+ - `isInfinite()`: Checks for infinite components
112
+ - `isNaN()`: Checks for NaN components
113
+ - `isZero()`: Checks if zero vector
114
+ - `satisfyEquality(v: Vec3)`: Checks equality with another vector
115
+ - `satisfyOpposition(v: Vec3)`: Checks opposition with another vector
116
+
117
+ ### Magnitude Operations
118
+
119
+ - `clamp(min: number, max: number)`: Clamps magnitude between values
120
+ - `limitMax(max: number)`: Limits maximum magnitude
121
+ - `limitMin(min: number)`: Limits minimum magnitude
122
+
123
+ ### Utility Methods
124
+
125
+ - `clone()`: Creates a copy of the vector
126
+ - `copy(v: Vec3)`: Copies components from another vector
127
+ - `lookAt(v: Vec3)`: Points towards another vector
128
+ - `toString()`: Returns string representation
129
+ - `toObject()`: Converts to plain object
130
+ - `toJSON()`: Converts to JSON format
131
+
132
+ ## Iteration
133
+
134
+ Vec3 implements the iterator protocol, allowing it to be used with for...of loops and spread operators. The iterator yields the x, y, and z components in order.
135
+
136
+ ## Example Usage
137
+
138
+ ```typescript
139
+ // Create vectors
140
+ const v1 = new Vec3(3, 4, 5);
141
+ const v2 = new Vec3(1, 2, 3);
142
+
143
+ // Basic operations
144
+ const sum = Vec3.add(v1, v2);
145
+ const crossProduct = Vec3.cross(v1, v2);
146
+ const dot = Vec3.dot(v1, v2);
147
+
148
+ // Method chaining
149
+ v1.normalize()
150
+ .scale(2)
151
+ .rotateX(Math.PI / 4);
152
+
153
+ // Get properties
154
+ console.log(v1.magnitude);
155
+ console.log(v1.angleX);
156
+
157
+ // Convert to array
158
+ const [x, y, z] = v1;
159
+
160
+ // Create from special coordinates
161
+ const cylindrical = Vec3.fromCylindricalCoords(2, Math.PI/4, 5);
162
+ const spherical = Vec3.fromSphericalCoords(2, Math.PI/3, Math.PI/4);
163
+
164
+ // Color operations
165
+ const color = new Vec3(1.0, 0.5, 0.2); // RGB color
166
+ color.r = 0.8; // Modify red channel
167
+ color.g *= 0.9; // Darken green channel
168
+
169
+ // Access as RGB array
170
+ const [red, green, blue] = color.rgb;
171
+ color.rgb = [0.2, 0.7, 0.9]; // Set new RGB values
172
+ ```
package/VEC4.md ADDED
@@ -0,0 +1,161 @@
1
+ # Vec4
2
+
3
+ A 4D vector implementation with comprehensive mathematical operations and utility methods.
4
+
5
+ ## Constructor
6
+
7
+ ### Vec4
8
+
9
+ - `constructor(x: number = 0, y: number = 0, z: number = 0, w: number = 0)`: Creates a new vector with the given x, y, z, and w coordinates
10
+
11
+ ## Static Methods
12
+
13
+ ### Creation and Conversion
14
+
15
+ - `fromArray(arr: [number, number, number, number] | number[])`: Creates a Vec4 from an array
16
+ - `fromObject(obj: { x: number; y: number; z: number; w: number })`: Creates a Vec4 from an object with x, y, z, and w properties
17
+ - `fromJSON(json: { x: number; y: number; z: number; w: number })`: Creates a Vec4 from a JSON object
18
+ - `immutable(x: number = 0, y: number = 0, z: number = 0, w: number = 0)`: Creates an immutable Vec4-like object
19
+ - `one()`: Creates a vector with all components set to 1.0
20
+ - `random(random: () => number = Math.random)`: Creates a random unit vector
21
+ - `zero()`: Creates a zero vector
22
+
23
+ ### Vector Operations
24
+
25
+ - `add(v: Vec4, w: Vec4)`: Adds two vectors
26
+ - `subtract(v: Vec4, w: Vec4)`: Subtracts one vector from another
27
+ - `multiply(v: Vec4, w: Vec4)`: Multiplies two vectors component-wise
28
+ - `divide(v: Vec4, w: Vec4)`: Divides two vectors component-wise
29
+ - `dot(v: Vec4, w: Vec4)`: Calculates the dot product
30
+ - `scale(v: Vec4, c: number)`: Scales a vector by a scalar value
31
+ - `negate(v: Vec4)`: Negates a vector
32
+ - `normalize(v: Vec4)`: Normalizes a vector
33
+ - `project(v: Vec4, w: Vec4)`: Projects one vector onto another
34
+ - `reflect(v: Vec4, normal: Vec4)`: Reflects a vector across a normal vector
35
+ - `lerp(v: Vec4, w: Vec4, t: number)`: Performs linear interpolation between vectors
36
+
37
+ ### Distance Calculations
38
+
39
+ - `distance(v: Vec4, w: Vec4)`: Calculates Euclidean distance between vectors
40
+ - `distanceSq(v: Vec4, w: Vec4)`: Calculates squared Euclidean distance
41
+ - `distanceChebyshev(v: Vec4, w: Vec4)`: Calculates Chebyshev distance
42
+ - `distanceManhattan(v: Vec4, w: Vec4)`: Calculates Manhattan distance
43
+ - `distanceMinkowski(v: Vec4, w: Vec4, p: number)`: Calculates Minkowski distance
44
+
45
+ ### Comparison and State
46
+
47
+ - `angleBetween(v: Vec4, w: Vec4)`: Calculates angle between vectors
48
+ - `equals(v: Vec4, w: Vec4, epsilon?: number)`: Compares vectors with optional epsilon
49
+ - `isInfinite(v: Vec4)`: Checks if vector has infinite components
50
+ - `isNaN(v: Vec4)`: Checks if vector has NaN components
51
+ - `isZero(v: Vec4)`: Checks if vector is zero
52
+ - `satisfyEquality(v: Vec4, w: Vec4)`: Checks if vectors are equal
53
+ - `satisfyOpposition(v: Vec4, w: Vec4)`: Checks if vectors are opposite
54
+
55
+ ## Instance Properties
56
+
57
+ ### Getters and Setters
58
+
59
+ - `x`: Gets or sets the x-component
60
+ - `y`: Gets or sets the y-component
61
+ - `z`: Gets or sets the z-component
62
+ - `w`: Gets or sets the w-component
63
+ - `xyzw`: Gets or sets all components as an array
64
+ - `r`: Gets or sets the red component (alias for x)
65
+ - `g`: Gets or sets the green component (alias for y)
66
+ - `b`: Gets or sets the blue component (alias for z)
67
+ - `a`: Gets or sets the alpha component (alias for w)
68
+ - `rgba`: Gets or sets all color components as an array (alias for xyzw)
69
+ - `magnitude`: Gets or sets the vector's magnitude
70
+ - `magnitudeSq`: Gets the squared magnitude (read-only)
71
+ - `angleX`: Gets the angle with positive x-axis
72
+ - `angleY`: Gets the angle with positive y-axis
73
+ - `angleZ`: Gets the angle with positive z-axis
74
+ - `angleW`: Gets the angle with positive w-axis
75
+
76
+ ## Instance Methods
77
+
78
+ ### Vector Operations
79
+
80
+ - `add(v: Vec4)`: Adds another vector
81
+ - `subtract(v: Vec4)`: Subtracts another vector
82
+ - `multiply(v: Vec4)`: Multiplies with another vector
83
+ - `divide(v: Vec4)`: Divides by another vector
84
+ - `scale(c: number)`: Scales by a scalar value
85
+ - `normalize()`: Normalizes the vector
86
+ - `negate()`: Negates the vector
87
+ - `project(v: Vec4)`: Projects onto another vector
88
+ - `reflect(normal: Vec4)`: Reflects across a normal vector
89
+ - `zero()`: Sets to zero vector
90
+ - `random(random?: () => number)`: Sets to random direction
91
+
92
+ ### Distance Calculations
93
+
94
+ - `distance(v: Vec4)`: Calculates Euclidean distance to another vector
95
+ - `distanceSq(v: Vec4)`: Calculates squared Euclidean distance
96
+ - `distanceChebyshev(v: Vec4)`: Calculates Chebyshev distance
97
+ - `distanceManhattan(v: Vec4)`: Calculates Manhattan distance
98
+ - `distanceMinkowski(v: Vec4, p: number)`: Calculates Minkowski distance
99
+
100
+ ### Comparison and State
101
+
102
+ - `angleBetween(v: Vec4)`: Calculates angle to another vector
103
+ - `equals(v: Vec4, epsilon?: number)`: Compares with another vector
104
+ - `isInfinite()`: Checks for infinite components
105
+ - `isNaN()`: Checks for NaN components
106
+ - `isZero()`: Checks if zero vector
107
+ - `satisfyEquality(v: Vec4)`: Checks equality with another vector
108
+ - `satisfyOpposition(v: Vec4)`: Checks opposition with another vector
109
+
110
+ ### Magnitude Operations
111
+
112
+ - `clamp(min: number, max: number)`: Clamps magnitude between values
113
+ - `limitMax(max: number)`: Limits maximum magnitude
114
+ - `limitMin(min: number)`: Limits minimum magnitude
115
+
116
+ ### Utility Methods
117
+
118
+ - `clone()`: Creates a copy of the vector
119
+ - `copy(v: Vec4)`: Copies components from another vector
120
+ - `lookAt(v: Vec4)`: Points towards another vector
121
+ - `toString()`: Returns string representation
122
+ - `toObject()`: Converts to plain object
123
+ - `toJSON()`: Converts to JSON format
124
+
125
+ ## Iteration
126
+
127
+ Vec4 implements the iterator protocol, allowing it to be used with for...of loops and spread operators. The iterator yields the x, y, z, and w components in order.
128
+
129
+ ## Example Usage
130
+
131
+ ```typescript
132
+ // Create vectors
133
+ const v1 = new Vec4(1, 2, 3, 1); // Homogeneous coordinates
134
+ const v2 = new Vec4(0, 1, 0, 0); // Direction vector
135
+
136
+ // Basic operations
137
+ const sum = Vec4.add(v1, v2);
138
+ const dot = Vec4.dot(v1, v2);
139
+
140
+ // Method chaining
141
+ v1.normalize()
142
+ .scale(2)
143
+ .limitMax(5);
144
+
145
+ // Get properties
146
+ console.log(v1.magnitude);
147
+ console.log(v1.angleX);
148
+
149
+ // Convert to array
150
+ const [x, y, z, w] = v1;
151
+
152
+ // RGBA color with transparency
153
+ const color = new Vec4(1.0, 0.5, 0.2, 0.8); // RGBA color
154
+ color.r = 0.8; // Modify red channel
155
+ color.g *= 0.9; // Darken green channel
156
+ color.a = 1.0; // Make fully opaque
157
+
158
+ // Access as RGBA array
159
+ const [red, green, blue, alpha] = color.rgba;
160
+ color.rgba = [0.2, 0.7, 0.9, 0.6]; // Set new RGBA values
161
+ ```
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./vec2.js"), exports);
18
+ __exportStar(require("./vec3.js"), exports);
19
+ __exportStar(require("./vec4.js"), exports);
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}