@fimbul-works/vec 1.0.3 → 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/VEC3.md CHANGED
@@ -63,6 +63,10 @@ A 3D vector implementation with comprehensive mathematical operations and utilit
63
63
  - `y`: Gets or sets the y-component
64
64
  - `z`: Gets or sets the z-component
65
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)
66
70
  - `magnitude`: Gets or sets the vector's magnitude
67
71
  - `magnitudeSq`: Gets the squared magnitude (read-only)
68
72
  - `angleX`: Gets the angle with positive x-axis
@@ -156,4 +160,13 @@ const [x, y, z] = v1;
156
160
  // Create from special coordinates
157
161
  const cylindrical = Vec3.fromCylindricalCoords(2, Math.PI/4, 5);
158
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
159
172
  ```
package/VEC4.md CHANGED
@@ -61,6 +61,11 @@ A 4D vector implementation with comprehensive mathematical operations and utilit
61
61
  - `z`: Gets or sets the z-component
62
62
  - `w`: Gets or sets the w-component
63
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)
64
69
  - `magnitude`: Gets or sets the vector's magnitude
65
70
  - `magnitudeSq`: Gets the squared magnitude (read-only)
66
71
  - `angleX`: Gets the angle with positive x-axis
@@ -143,4 +148,14 @@ console.log(v1.angleX);
143
148
 
144
149
  // Convert to array
145
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
146
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"}