@vib3code/sdk 2.0.3-canary.89c05e0 → 2.0.3-canary.d0c4221

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vib3code/sdk",
3
- "version": "2.0.3-canary.89c05e0",
3
+ "version": "2.0.3-canary.d0c4221",
4
4
  "description": "VIB3+ 4D Visualization SDK - Unified engine with 6D rotation, MCP agentic integration, and cross-platform support",
5
5
  "type": "module",
6
6
  "main": "src/core/VIB3Engine.js",
@@ -61,8 +61,8 @@ export function generate24CellVertices(size = 1) {
61
61
  ];
62
62
  for (const [s1, s2] of signs) {
63
63
  const v = new Vec4(0, 0, 0, 0);
64
- v.setComponent(i, s1 * s);
65
- v.setComponent(j, s2 * s);
64
+ v.data[i] = s1 * s;
65
+ v.data[j] = s2 * s;
66
66
  vertices.push(v);
67
67
  }
68
68
  }
@@ -547,122 +547,6 @@ export class Mat4x4 {
547
547
  return new Mat4x4(json.data);
548
548
  }
549
549
 
550
- // ========== IN-PLACE ROTATIONS ==========
551
-
552
- /**
553
- * Rotate in XY plane in place
554
- * @param {number} angle
555
- * @returns {Mat4x4} this
556
- */
557
- rotateXY(angle) {
558
- const c = Math.cos(angle);
559
- const s = Math.sin(angle);
560
- const m = this.data;
561
-
562
- for (let i = 0; i < 4; i++) {
563
- const a0 = m[i]; // Col 0
564
- const a1 = m[i + 4]; // Col 1
565
- m[i] = a0 * c + a1 * s;
566
- m[i + 4] = -a0 * s + a1 * c;
567
- }
568
- return this;
569
- }
570
-
571
- /**
572
- * Rotate in XZ plane in place
573
- * @param {number} angle
574
- * @returns {Mat4x4} this
575
- */
576
- rotateXZ(angle) {
577
- const c = Math.cos(angle);
578
- const s = Math.sin(angle);
579
- const m = this.data;
580
-
581
- for (let i = 0; i < 4; i++) {
582
- const a0 = m[i]; // Col 0
583
- const a2 = m[i + 8]; // Col 2
584
- m[i] = a0 * c - a2 * s;
585
- m[i + 8] = a0 * s + a2 * c;
586
- }
587
- return this;
588
- }
589
-
590
- /**
591
- * Rotate in YZ plane in place
592
- * @param {number} angle
593
- * @returns {Mat4x4} this
594
- */
595
- rotateYZ(angle) {
596
- const c = Math.cos(angle);
597
- const s = Math.sin(angle);
598
- const m = this.data;
599
-
600
- for (let i = 0; i < 4; i++) {
601
- const a1 = m[i + 4]; // Col 1
602
- const a2 = m[i + 8]; // Col 2
603
- m[i + 4] = a1 * c + a2 * s;
604
- m[i + 8] = -a1 * s + a2 * c;
605
- }
606
- return this;
607
- }
608
-
609
- /**
610
- * Rotate in XW plane in place
611
- * @param {number} angle
612
- * @returns {Mat4x4} this
613
- */
614
- rotateXW(angle) {
615
- const c = Math.cos(angle);
616
- const s = Math.sin(angle);
617
- const m = this.data;
618
-
619
- for (let i = 0; i < 4; i++) {
620
- const a0 = m[i]; // Col 0
621
- const a3 = m[i + 12]; // Col 3
622
- m[i] = a0 * c + a3 * s;
623
- m[i + 12] = -a0 * s + a3 * c;
624
- }
625
- return this;
626
- }
627
-
628
- /**
629
- * Rotate in YW plane in place
630
- * @param {number} angle
631
- * @returns {Mat4x4} this
632
- */
633
- rotateYW(angle) {
634
- const c = Math.cos(angle);
635
- const s = Math.sin(angle);
636
- const m = this.data;
637
-
638
- for (let i = 0; i < 4; i++) {
639
- const a1 = m[i + 4]; // Col 1
640
- const a3 = m[i + 12]; // Col 3
641
- m[i + 4] = a1 * c + a3 * s;
642
- m[i + 12] = -a1 * s + a3 * c;
643
- }
644
- return this;
645
- }
646
-
647
- /**
648
- * Rotate in ZW plane in place
649
- * @param {number} angle
650
- * @returns {Mat4x4} this
651
- */
652
- rotateZW(angle) {
653
- const c = Math.cos(angle);
654
- const s = Math.sin(angle);
655
- const m = this.data;
656
-
657
- for (let i = 0; i < 4; i++) {
658
- const a2 = m[i + 8]; // Col 2
659
- const a3 = m[i + 12]; // Col 3
660
- m[i + 8] = a2 * c + a3 * s;
661
- m[i + 12] = -a2 * s + a3 * c;
662
- }
663
- return this;
664
- }
665
-
666
550
  // ========== ROTATION MATRICES FOR ALL 6 PLANES ==========
667
551
 
668
552
  /**
@@ -797,12 +681,12 @@ export class Mat4x4 {
797
681
  static rotationFromAngles(angles) {
798
682
  let result = Mat4x4.identity();
799
683
 
800
- if (angles.xy) result.rotateXY(angles.xy);
801
- if (angles.xz) result.rotateXZ(angles.xz);
802
- if (angles.yz) result.rotateYZ(angles.yz);
803
- if (angles.xw) result.rotateXW(angles.xw);
804
- if (angles.yw) result.rotateYW(angles.yw);
805
- if (angles.zw) result.rotateZW(angles.zw);
684
+ if (angles.xy) result = result.multiply(Mat4x4.rotationXY(angles.xy));
685
+ if (angles.xz) result = result.multiply(Mat4x4.rotationXZ(angles.xz));
686
+ if (angles.yz) result = result.multiply(Mat4x4.rotationYZ(angles.yz));
687
+ if (angles.xw) result = result.multiply(Mat4x4.rotationXW(angles.xw));
688
+ if (angles.yw) result = result.multiply(Mat4x4.rotationYW(angles.yw));
689
+ if (angles.zw) result = result.multiply(Mat4x4.rotationZW(angles.zw));
806
690
 
807
691
  return result;
808
692
  }
@@ -323,17 +323,14 @@ export class Rotor4D {
323
323
  /**
324
324
  * Rotate a 4D vector using sandwich product: v' = R v R†
325
325
  *
326
- * Matrix math is inlined to avoid allocating a temporary Float32Array(16).
327
- * Pass an optional target Vec4 to eliminate all allocations.
328
- *
329
326
  * @param {Vec4} v - Vector to rotate
330
- * @param {Vec4} [target] - Optional pre-allocated Vec4 to write result into
331
- * @returns {Vec4} Rotated vector (target if provided, otherwise new Vec4)
327
+ * @param {Vec4} [target] - Optional target vector to write result to
328
+ * @returns {Vec4} Rotated vector
332
329
  */
333
330
  rotate(v, target) {
334
- const x = v.x, y = v.y, z = v.z, w = v.w;
331
+ // Direct matrix multiplication without allocation
335
332
 
336
- // Normalize for numerical stability (same as toMatrix)
333
+ // Normalize components for stability (same as toMatrix)
337
334
  const n = this.norm();
338
335
  const invN = n > 1e-10 ? 1 / n : 1;
339
336
 
@@ -346,7 +343,7 @@ export class Rotor4D {
346
343
  const zw = this.zw * invN;
347
344
  const xyzw = this.xyzw * invN;
348
345
 
349
- // Squared terms
346
+ // Pre-compute products
350
347
  const s2 = s * s;
351
348
  const xy2 = xy * xy;
352
349
  const xz2 = xz * xz;
@@ -356,20 +353,22 @@ export class Rotor4D {
356
353
  const zw2 = zw * zw;
357
354
  const xyzw2 = xyzw * xyzw;
358
355
 
359
- // Cross terms (pre-multiplied by 2)
356
+ // Cross terms
360
357
  const sxy = 2 * s * xy;
361
358
  const sxz = 2 * s * xz;
362
359
  const syz = 2 * s * yz;
363
360
  const sxw = 2 * s * xw;
364
361
  const syw = 2 * s * yw;
365
362
  const szw = 2 * s * zw;
363
+ // const sxyzw = 2 * s * xyzw; // Unused in rotation matrix
366
364
 
367
- const xzyz = 2 * xz * yz;
368
- const xyyz = 2 * xy * yz;
369
365
  const xyxz = 2 * xy * xz;
366
+ const xyyz = 2 * xy * yz;
370
367
  const xyxw = 2 * xy * xw;
371
368
  const xyyw = 2 * xy * yw;
369
+ // const xyzw_c = 2 * xy * zw; // Unused in rotation matrix
372
370
 
371
+ const xzyz = 2 * xz * yz;
373
372
  const xzxw = 2 * xz * xw;
374
373
  const xzyw = 2 * xz * yw;
375
374
  const xzzw = 2 * xz * zw;
@@ -389,33 +388,40 @@ export class Rotor4D {
389
388
  const ywxyzw = 2 * yw * xyzw;
390
389
  const zwxyzw = 2 * zw * xyzw;
391
390
 
392
- // Column-major 4x4 rotation matrix entries (inlined from toMatrix)
393
- // Column 0
394
- const m0 = s2 - xy2 - xz2 + yz2 - xw2 + yw2 + zw2 - xyzw2;
395
- const m1 = sxy + xzyz + xwyw - zwxyzw;
396
- const m2 = sxz - xyyz + xwzw + ywxyzw;
397
- const m3 = sxw - xyyw - xzzw - yzxyzw;
398
- // Column 1
399
- const m4 = -sxy + xzyz + xwyw + zwxyzw;
400
- const m5 = s2 - xy2 + xz2 - yz2 + xw2 - yw2 + zw2 - xyzw2;
401
- const m6 = syz + xyxz + ywzw - xwxyzw;
402
- const m7 = syw + xyxw - yzzw + xzxyzw;
403
- // Column 2
404
- const m8 = -sxz - xyyz + xwzw - ywxyzw;
405
- const m9 = -syz + xyxz + ywzw + xwxyzw;
406
- const m10 = s2 + xy2 - xz2 - yz2 + xw2 + yw2 - zw2 - xyzw2;
407
- const m11 = szw + xzxw + yzyw - xyxyzw;
408
- // Column 3
409
- const m12 = -sxw - xyyw - xzzw + yzxyzw;
410
- const m13 = -syw + xyxw - yzzw - xzxyzw;
411
- const m14 = -szw + xzxw + yzyw + xyxyzw;
412
- const m15 = s2 + xy2 + xz2 + yz2 - xw2 - yw2 - zw2 - xyzw2;
413
-
414
- // Matrix-vector multiply
415
- const rx = m0 * x + m4 * y + m8 * z + m12 * w;
416
- const ry = m1 * x + m5 * y + m9 * z + m13 * w;
417
- const rz = m2 * x + m6 * y + m10 * z + m14 * w;
418
- const rw = m3 * x + m7 * y + m11 * z + m15 * w;
391
+ // Matrix elements
392
+ // Col 0
393
+ const m00 = s2 - xy2 - xz2 + yz2 - xw2 + yw2 + zw2 - xyzw2;
394
+ const m01 = sxy + xzyz + xwyw - zwxyzw;
395
+ const m02 = sxz - xyyz + xwzw + ywxyzw;
396
+ const m03 = sxw - xyyw - xzzw - yzxyzw;
397
+
398
+ // Col 1
399
+ const m10 = -sxy + xzyz + xwyw + zwxyzw;
400
+ const m11 = s2 - xy2 + xz2 - yz2 + xw2 - yw2 + zw2 - xyzw2;
401
+ const m12 = syz + xyxz + ywzw - xwxyzw;
402
+ const m13 = syw + xyxw - yzzw + xzxyzw;
403
+
404
+ // Col 2
405
+ const m20 = -sxz - xyyz + xwzw - ywxyzw;
406
+ const m21 = -syz + xyxz + ywzw + xwxyzw;
407
+ const m22 = s2 + xy2 - xz2 - yz2 + xw2 + yw2 - zw2 - xyzw2;
408
+ const m23 = szw + xzxw + yzyw - xyxyzw;
409
+
410
+ // Col 3
411
+ const m30 = -sxw - xyyw - xzzw + yzxyzw;
412
+ const m31 = -syw + xyxw - yzzw - xzxyzw;
413
+ const m32 = -szw + xzxw + yzyw + xyxyzw;
414
+ const m33 = s2 + xy2 + xz2 + yz2 - xw2 - yw2 - zw2 - xyzw2;
415
+
416
+ const x = v.x;
417
+ const y = v.y;
418
+ const z = v.z;
419
+ const w = v.w;
420
+
421
+ const rx = m00 * x + m10 * y + m20 * z + m30 * w;
422
+ const ry = m01 * x + m11 * y + m21 * z + m31 * w;
423
+ const rz = m02 * x + m12 * y + m22 * z + m32 * w;
424
+ const rw = m03 * x + m13 * y + m23 * z + m33 * w;
419
425
 
420
426
  if (target) {
421
427
  target.x = rx;
@@ -424,6 +430,7 @@ export class Rotor4D {
424
430
  target.w = rw;
425
431
  return target;
426
432
  }
433
+
427
434
  return new Vec4(rx, ry, rz, rw);
428
435
  }
429
436
 
package/src/math/Vec4.js CHANGED
@@ -2,8 +2,7 @@
2
2
  * Vec4 - 4D Vector Class
3
3
  *
4
4
  * Represents a point or direction in 4-dimensional space.
5
- * Uses plain numeric properties internally for minimal allocation overhead.
6
- * GPU-compatible Float32Array created on demand via toFloat32Array().
5
+ * Uses Float32Array for GPU compatibility and potential SIMD optimization.
7
6
  *
8
7
  * @example
9
8
  * const v = new Vec4(1, 2, 3, 0.5);
@@ -20,66 +19,26 @@ export class Vec4 {
20
19
  * @param {number} w - W component (4th dimension)
21
20
  */
22
21
  constructor(x = 0, y = 0, z = 0, w = 0) {
23
- this._x = x;
24
- this._y = y;
25
- this._z = z;
26
- this._w = w;
22
+ // Use Float32Array for GPU compatibility
23
+ this.data = new Float32Array(4);
24
+ this.data[0] = x;
25
+ this.data[1] = y;
26
+ this.data[2] = z;
27
+ this.data[3] = w;
27
28
  }
28
29
 
29
- // Property accessors
30
- get x() { return this._x; }
31
- set x(v) { this._x = v; }
30
+ // Property accessors for readability
31
+ get x() { return this.data[0]; }
32
+ set x(v) { this.data[0] = v; }
32
33
 
33
- get y() { return this._y; }
34
- set y(v) { this._y = v; }
34
+ get y() { return this.data[1]; }
35
+ set y(v) { this.data[1] = v; }
35
36
 
36
- get z() { return this._z; }
37
- set z(v) { this._z = v; }
37
+ get z() { return this.data[2]; }
38
+ set z(v) { this.data[2] = v; }
38
39
 
39
- get w() { return this._w; }
40
- set w(v) { this._w = v; }
41
-
42
- /**
43
- * Backward-compatible .data getter.
44
- * Returns a Float32Array snapshot of current values.
45
- * Note: writes to the returned array do NOT propagate back.
46
- * Use setComponent(index, value) for index-based mutation.
47
- * @returns {Float32Array}
48
- */
49
- get data() {
50
- return new Float32Array([this._x, this._y, this._z, this._w]);
51
- }
52
-
53
- /**
54
- * Set a component by index (0=x, 1=y, 2=z, 3=w)
55
- * @param {number} index - Component index (0-3)
56
- * @param {number} value - New value
57
- * @returns {Vec4} this
58
- */
59
- setComponent(index, value) {
60
- switch (index) {
61
- case 0: this._x = value; break;
62
- case 1: this._y = value; break;
63
- case 2: this._z = value; break;
64
- case 3: this._w = value; break;
65
- }
66
- return this;
67
- }
68
-
69
- /**
70
- * Get a component by index (0=x, 1=y, 2=z, 3=w)
71
- * @param {number} index - Component index (0-3)
72
- * @returns {number}
73
- */
74
- getComponent(index) {
75
- switch (index) {
76
- case 0: return this._x;
77
- case 1: return this._y;
78
- case 2: return this._z;
79
- case 3: return this._w;
80
- default: return 0;
81
- }
82
- }
40
+ get w() { return this.data[3]; }
41
+ set w(v) { this.data[3] = v; }
83
42
 
84
43
  /**
85
44
  * Create a Vec4 from an array
@@ -95,7 +54,7 @@ export class Vec4 {
95
54
  * @returns {Vec4}
96
55
  */
97
56
  clone() {
98
- return new Vec4(this._x, this._y, this._z, this._w);
57
+ return new Vec4(this.x, this.y, this.z, this.w);
99
58
  }
100
59
 
101
60
  /**
@@ -104,10 +63,10 @@ export class Vec4 {
104
63
  * @returns {Vec4} this (for chaining)
105
64
  */
106
65
  copy(v) {
107
- this._x = v._x;
108
- this._y = v._y;
109
- this._z = v._z;
110
- this._w = v._w;
66
+ this.data[0] = v.data[0];
67
+ this.data[1] = v.data[1];
68
+ this.data[2] = v.data[2];
69
+ this.data[3] = v.data[3];
111
70
  return this;
112
71
  }
113
72
 
@@ -120,10 +79,10 @@ export class Vec4 {
120
79
  * @returns {Vec4} this
121
80
  */
122
81
  set(x, y, z, w) {
123
- this._x = x;
124
- this._y = y;
125
- this._z = z;
126
- this._w = w;
82
+ this.data[0] = x;
83
+ this.data[1] = y;
84
+ this.data[2] = z;
85
+ this.data[3] = w;
127
86
  return this;
128
87
  }
129
88
 
@@ -134,10 +93,10 @@ export class Vec4 {
134
93
  */
135
94
  add(v) {
136
95
  return new Vec4(
137
- this._x + v._x,
138
- this._y + v._y,
139
- this._z + v._z,
140
- this._w + v._w
96
+ this.x + v.x,
97
+ this.y + v.y,
98
+ this.z + v.z,
99
+ this.w + v.w
141
100
  );
142
101
  }
143
102
 
@@ -147,10 +106,10 @@ export class Vec4 {
147
106
  * @returns {Vec4} this
148
107
  */
149
108
  addInPlace(v) {
150
- this._x += v._x;
151
- this._y += v._y;
152
- this._z += v._z;
153
- this._w += v._w;
109
+ this.data[0] += v.data[0];
110
+ this.data[1] += v.data[1];
111
+ this.data[2] += v.data[2];
112
+ this.data[3] += v.data[3];
154
113
  return this;
155
114
  }
156
115
 
@@ -161,10 +120,10 @@ export class Vec4 {
161
120
  */
162
121
  sub(v) {
163
122
  return new Vec4(
164
- this._x - v._x,
165
- this._y - v._y,
166
- this._z - v._z,
167
- this._w - v._w
123
+ this.x - v.x,
124
+ this.y - v.y,
125
+ this.z - v.z,
126
+ this.w - v.w
168
127
  );
169
128
  }
170
129
 
@@ -174,10 +133,10 @@ export class Vec4 {
174
133
  * @returns {Vec4} this
175
134
  */
176
135
  subInPlace(v) {
177
- this._x -= v._x;
178
- this._y -= v._y;
179
- this._z -= v._z;
180
- this._w -= v._w;
136
+ this.data[0] -= v.data[0];
137
+ this.data[1] -= v.data[1];
138
+ this.data[2] -= v.data[2];
139
+ this.data[3] -= v.data[3];
181
140
  return this;
182
141
  }
183
142
 
@@ -188,10 +147,10 @@ export class Vec4 {
188
147
  */
189
148
  scale(s) {
190
149
  return new Vec4(
191
- this._x * s,
192
- this._y * s,
193
- this._z * s,
194
- this._w * s
150
+ this.x * s,
151
+ this.y * s,
152
+ this.z * s,
153
+ this.w * s
195
154
  );
196
155
  }
197
156
 
@@ -201,10 +160,10 @@ export class Vec4 {
201
160
  * @returns {Vec4} this
202
161
  */
203
162
  scaleInPlace(s) {
204
- this._x *= s;
205
- this._y *= s;
206
- this._z *= s;
207
- this._w *= s;
163
+ this.data[0] *= s;
164
+ this.data[1] *= s;
165
+ this.data[2] *= s;
166
+ this.data[3] *= s;
208
167
  return this;
209
168
  }
210
169
 
@@ -215,10 +174,10 @@ export class Vec4 {
215
174
  */
216
175
  multiply(v) {
217
176
  return new Vec4(
218
- this._x * v._x,
219
- this._y * v._y,
220
- this._z * v._z,
221
- this._w * v._w
177
+ this.x * v.x,
178
+ this.y * v.y,
179
+ this.z * v.z,
180
+ this.w * v.w
222
181
  );
223
182
  }
224
183
 
@@ -227,7 +186,7 @@ export class Vec4 {
227
186
  * @returns {Vec4} New vector
228
187
  */
229
188
  negate() {
230
- return new Vec4(-this._x, -this._y, -this._z, -this._w);
189
+ return new Vec4(-this.x, -this.y, -this.z, -this.w);
231
190
  }
232
191
 
233
192
  /**
@@ -235,10 +194,10 @@ export class Vec4 {
235
194
  * @returns {Vec4} this
236
195
  */
237
196
  negateInPlace() {
238
- this._x = -this._x;
239
- this._y = -this._y;
240
- this._z = -this._z;
241
- this._w = -this._w;
197
+ this.data[0] = -this.data[0];
198
+ this.data[1] = -this.data[1];
199
+ this.data[2] = -this.data[2];
200
+ this.data[3] = -this.data[3];
242
201
  return this;
243
202
  }
244
203
 
@@ -248,7 +207,7 @@ export class Vec4 {
248
207
  * @returns {number}
249
208
  */
250
209
  dot(v) {
251
- return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
210
+ return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
252
211
  }
253
212
 
254
213
  /**
@@ -256,7 +215,7 @@ export class Vec4 {
256
215
  * @returns {number}
257
216
  */
258
217
  lengthSquared() {
259
- return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
218
+ return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
260
219
  }
261
220
 
262
221
  /**
@@ -318,10 +277,10 @@ export class Vec4 {
318
277
  */
319
278
  lerp(v, t) {
320
279
  return new Vec4(
321
- this._x + (v._x - this._x) * t,
322
- this._y + (v._y - this._y) * t,
323
- this._z + (v._z - this._z) * t,
324
- this._w + (v._w - this._w) * t
280
+ this.x + (v.x - this.x) * t,
281
+ this.y + (v.y - this.y) * t,
282
+ this.z + (v.z - this.z) * t,
283
+ this.w + (v.w - this.w) * t
325
284
  );
326
285
  }
327
286
 
@@ -333,10 +292,10 @@ export class Vec4 {
333
292
  */
334
293
  equals(v, epsilon = 1e-6) {
335
294
  return (
336
- Math.abs(this._x - v._x) < epsilon &&
337
- Math.abs(this._y - v._y) < epsilon &&
338
- Math.abs(this._z - v._z) < epsilon &&
339
- Math.abs(this._w - v._w) < epsilon
295
+ Math.abs(this.x - v.x) < epsilon &&
296
+ Math.abs(this.y - v.y) < epsilon &&
297
+ Math.abs(this.z - v.z) < epsilon &&
298
+ Math.abs(this.w - v.w) < epsilon
340
299
  );
341
300
  }
342
301
 
@@ -362,10 +321,10 @@ export class Vec4 {
362
321
  d = options.distance ?? options.d ?? 2;
363
322
  }
364
323
  const epsilon = options.epsilon ?? 1e-5;
365
- const denom = d - this._w;
324
+ const denom = d - this.w;
366
325
  const clamped = Math.abs(denom) < epsilon ? (denom >= 0 ? epsilon : -epsilon) : denom;
367
326
  const scale = 1 / clamped;
368
- return new Vec4(this._x * scale, this._y * scale, this._z * scale, 0);
327
+ return new Vec4(this.x * scale, this.y * scale, this.z * scale, 0);
369
328
  }
370
329
 
371
330
  /**
@@ -376,10 +335,10 @@ export class Vec4 {
376
335
  */
377
336
  projectStereographic(options = {}) {
378
337
  const epsilon = options.epsilon ?? 1e-5;
379
- const denom = 1 - this._w;
338
+ const denom = 1 - this.w;
380
339
  const clamped = Math.abs(denom) < epsilon ? (denom >= 0 ? epsilon : -epsilon) : denom;
381
340
  const scale = 1 / clamped;
382
- return new Vec4(this._x * scale, this._y * scale, this._z * scale, 0);
341
+ return new Vec4(this.x * scale, this.y * scale, this.z * scale, 0);
383
342
  }
384
343
 
385
344
  /**
@@ -388,7 +347,7 @@ export class Vec4 {
388
347
  * @returns {Vec4} Projected point (w component is 0)
389
348
  */
390
349
  projectOrthographic() {
391
- return new Vec4(this._x, this._y, this._z, 0);
350
+ return new Vec4(this.x, this.y, this.z, 0);
392
351
  }
393
352
 
394
353
  /**
@@ -396,7 +355,7 @@ export class Vec4 {
396
355
  * @returns {number[]}
397
356
  */
398
357
  toArray() {
399
- return [this._x, this._y, this._z, this._w];
358
+ return [this.x, this.y, this.z, this.w];
400
359
  }
401
360
 
402
361
  /**
@@ -404,7 +363,7 @@ export class Vec4 {
404
363
  * @returns {Float32Array}
405
364
  */
406
365
  toFloat32Array() {
407
- return new Float32Array([this._x, this._y, this._z, this._w]);
366
+ return new Float32Array(this.data);
408
367
  }
409
368
 
410
369
  /**
@@ -412,7 +371,7 @@ export class Vec4 {
412
371
  * @returns {number[]}
413
372
  */
414
373
  toArray3() {
415
- return [this._x, this._y, this._z];
374
+ return [this.x, this.y, this.z];
416
375
  }
417
376
 
418
377
  /**
@@ -421,7 +380,7 @@ export class Vec4 {
421
380
  * @returns {string}
422
381
  */
423
382
  toString(precision = 3) {
424
- return `Vec4(${this._x.toFixed(precision)}, ${this._y.toFixed(precision)}, ${this._z.toFixed(precision)}, ${this._w.toFixed(precision)})`;
383
+ return `Vec4(${this.x.toFixed(precision)}, ${this.y.toFixed(precision)}, ${this.z.toFixed(precision)}, ${this.w.toFixed(precision)})`;
425
384
  }
426
385
 
427
386
  /**
@@ -429,7 +388,7 @@ export class Vec4 {
429
388
  * @returns {object}
430
389
  */
431
390
  toJSON() {
432
- return { x: this._x, y: this._y, z: this._z, w: this._w };
391
+ return { x: this.x, y: this.y, z: this.z, w: this.w };
433
392
  }
434
393
 
435
394
  // Static factory methods for common vectors