@vib3code/sdk 2.0.3-canary.4e0dace → 2.0.3-canary.4fbf680

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.4e0dace",
3
+ "version": "2.0.3-canary.4fbf680",
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",
@@ -355,17 +355,21 @@ function projectPoints(points, rotor, dimension, width, height) {
355
355
  const centerY = height / 2;
356
356
  const scale = Math.min(width, height) * 0.4;
357
357
 
358
+ // Reuse vectors to minimize allocation
359
+ const rotatedBuffer = new Vec4();
360
+ const projectedBuffer = new Vec4();
361
+
358
362
  for (const point of points) {
359
363
  // Apply 4D rotation
360
- const rotated = rotor.rotate(point);
364
+ rotor.rotate(point, rotatedBuffer);
361
365
 
362
366
  // Project to 3D (perspective from W)
363
- const proj3d = rotated.projectPerspective(dimension);
367
+ rotatedBuffer.projectPerspective(dimension, projectedBuffer);
364
368
 
365
369
  // Project to 2D (simple orthographic for clean SVG)
366
- const x = centerX + proj3d.x * scale;
367
- const y = centerY - proj3d.y * scale; // Flip Y for SVG coordinates
368
- const depth = proj3d.z; // Keep depth for styling
370
+ const x = centerX + projectedBuffer.x * scale;
371
+ const y = centerY - projectedBuffer.y * scale; // Flip Y for SVG coordinates
372
+ const depth = projectedBuffer.z; // Keep depth for styling
369
373
 
370
374
  projected.push({ x, y, depth, original: point });
371
375
  }
@@ -354,12 +354,18 @@ export class Mat4x4 {
354
354
 
355
355
  /**
356
356
  * Transpose matrix
357
+ * @param {Mat4x4} [target=null] - Optional target matrix
357
358
  * @returns {Mat4x4} New transposed matrix
358
359
  */
359
- transpose() {
360
+ transpose(target = null) {
360
361
  const m = this.data;
361
- const out = new Mat4x4(Mat4x4.UNINITIALIZED);
362
+ const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
362
363
  const r = out.data;
364
+ // If target is same as source, use intermediate or careful swap
365
+ if (target === this) {
366
+ return this.transposeInPlace();
367
+ }
368
+
363
369
  r[0] = m[0]; r[4] = m[1]; r[8] = m[2]; r[12] = m[3];
364
370
  r[1] = m[4]; r[5] = m[5]; r[9] = m[6]; r[13] = m[7];
365
371
  r[2] = m[8]; r[6] = m[9]; r[10] = m[10]; r[14] = m[11];
@@ -415,62 +421,85 @@ export class Mat4x4 {
415
421
 
416
422
  /**
417
423
  * Calculate inverse matrix
424
+ * @param {Mat4x4} [target=null] - Optional target matrix
418
425
  * @returns {Mat4x4|null} Inverse matrix or null if singular
419
426
  */
420
- inverse() {
427
+ inverse(target = null) {
421
428
  const m = this.data;
422
- const out = new Mat4x4(Mat4x4.UNINITIALIZED);
429
+ const out = target || new Mat4x4(Mat4x4.UNINITIALIZED);
423
430
  const inv = out.data;
424
431
 
425
- inv[0] = m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15] +
426
- m[9] * m[7] * m[14] + m[13] * m[6] * m[11] - m[13] * m[7] * m[10];
432
+ // Note: For in-place inversion (target === this), we need to be careful.
433
+ // The standard algorithm uses input values for every output cell.
434
+ // We can check for aliasing or use local variables if we wanted full safety,
435
+ // but simplest is to compute to temp if aliased, or just computing to the array directly works
436
+ // IF we cache everything first. But here we are writing to `inv` index by index.
437
+ // If inv === m, writing inv[0] destroys m[0] which is needed for inv[5] etc.
438
+ // So aliasing is NOT safe with this direct write approach.
439
+
440
+ // Handle aliasing by cloning first if needed, or using temp array.
441
+ // Since we want performance, let's detect aliasing.
442
+ let sourceData = m;
443
+ if (target === this) {
444
+ // Copy source data to temp array so we can write to 'this.data' safely
445
+ // We can't avoid allocation entirely in this specific edge case easily without unrolling everything into locals,
446
+ // which is huge for 4x4 inverse.
447
+ // Using a static temp buffer would be unsafe for threading/recursion (not an issue in JS single thread usually but still).
448
+ // Let's just clone the source data for the calculation.
449
+ sourceData = new Float32Array(m);
450
+ }
451
+
452
+ const s = sourceData;
453
+
454
+ inv[0] = s[5] * s[10] * s[15] - s[5] * s[11] * s[14] - s[9] * s[6] * s[15] +
455
+ s[9] * s[7] * s[14] + s[13] * s[6] * s[11] - s[13] * s[7] * s[10];
427
456
 
428
- inv[4] = -m[4] * m[10] * m[15] + m[4] * m[11] * m[14] + m[8] * m[6] * m[15] -
429
- m[8] * m[7] * m[14] - m[12] * m[6] * m[11] + m[12] * m[7] * m[10];
457
+ inv[4] = -s[4] * s[10] * s[15] + s[4] * s[11] * s[14] + s[8] * s[6] * s[15] -
458
+ s[8] * s[7] * s[14] - s[12] * s[6] * s[11] + s[12] * s[7] * s[10];
430
459
 
431
- inv[8] = m[4] * m[9] * m[15] - m[4] * m[11] * m[13] - m[8] * m[5] * m[15] +
432
- m[8] * m[7] * m[13] + m[12] * m[5] * m[11] - m[12] * m[7] * m[9];
460
+ inv[8] = s[4] * s[9] * s[15] - s[4] * s[11] * s[13] - s[8] * s[5] * s[15] +
461
+ s[8] * s[7] * s[13] + s[12] * s[5] * s[11] - s[12] * s[7] * s[9];
433
462
 
434
- inv[12] = -m[4] * m[9] * m[14] + m[4] * m[10] * m[13] + m[8] * m[5] * m[14] -
435
- m[8] * m[6] * m[13] - m[12] * m[5] * m[10] + m[12] * m[6] * m[9];
463
+ inv[12] = -s[4] * s[9] * s[14] + s[4] * s[10] * s[13] + s[8] * s[5] * s[14] -
464
+ s[8] * s[6] * s[13] - s[12] * s[5] * s[10] + s[12] * s[6] * s[9];
436
465
 
437
- inv[1] = -m[1] * m[10] * m[15] + m[1] * m[11] * m[14] + m[9] * m[2] * m[15] -
438
- m[9] * m[3] * m[14] - m[13] * m[2] * m[11] + m[13] * m[3] * m[10];
466
+ inv[1] = -s[1] * s[10] * s[15] + s[1] * s[11] * s[14] + s[9] * s[2] * s[15] -
467
+ s[9] * s[3] * s[14] - s[13] * s[2] * s[11] + s[13] * s[3] * s[10];
439
468
 
440
- inv[5] = m[0] * m[10] * m[15] - m[0] * m[11] * m[14] - m[8] * m[2] * m[15] +
441
- m[8] * m[3] * m[14] + m[12] * m[2] * m[11] - m[12] * m[3] * m[10];
469
+ inv[5] = s[0] * s[10] * s[15] - s[0] * s[11] * s[14] - s[8] * s[2] * s[15] +
470
+ s[8] * s[3] * s[14] + s[12] * s[2] * s[11] - s[12] * s[3] * s[10];
442
471
 
443
- inv[9] = -m[0] * m[9] * m[15] + m[0] * m[11] * m[13] + m[8] * m[1] * m[15] -
444
- m[8] * m[3] * m[13] - m[12] * m[1] * m[11] + m[12] * m[3] * m[9];
472
+ inv[9] = -s[0] * s[9] * s[15] + s[0] * s[11] * s[13] + s[8] * s[1] * s[15] -
473
+ s[8] * s[3] * s[13] - s[12] * s[1] * s[11] + s[12] * s[3] * s[9];
445
474
 
446
- inv[13] = m[0] * m[9] * m[14] - m[0] * m[10] * m[13] - m[8] * m[1] * m[14] +
447
- m[8] * m[2] * m[13] + m[12] * m[1] * m[10] - m[12] * m[2] * m[9];
475
+ inv[13] = s[0] * s[9] * s[14] - s[0] * s[10] * s[13] - s[8] * s[1] * s[14] +
476
+ s[8] * s[2] * s[13] + s[12] * s[1] * s[10] - s[12] * s[2] * s[9];
448
477
 
449
- inv[2] = m[1] * m[6] * m[15] - m[1] * m[7] * m[14] - m[5] * m[2] * m[15] +
450
- m[5] * m[3] * m[14] + m[13] * m[2] * m[7] - m[13] * m[3] * m[6];
478
+ inv[2] = s[1] * s[6] * s[15] - s[1] * s[7] * s[14] - s[5] * s[2] * s[15] +
479
+ s[5] * s[3] * s[14] + s[13] * s[2] * s[7] - s[13] * s[3] * s[6];
451
480
 
452
- inv[6] = -m[0] * m[6] * m[15] + m[0] * m[7] * m[14] + m[4] * m[2] * m[15] -
453
- m[4] * m[3] * m[14] - m[12] * m[2] * m[7] + m[12] * m[3] * m[6];
481
+ inv[6] = -s[0] * s[6] * s[15] + s[0] * s[7] * s[14] + s[4] * s[2] * s[15] -
482
+ s[4] * s[3] * s[14] - s[12] * s[2] * s[7] + s[12] * s[3] * s[6];
454
483
 
455
- inv[10] = m[0] * m[5] * m[15] - m[0] * m[7] * m[13] - m[4] * m[1] * m[15] +
456
- m[4] * m[3] * m[13] + m[12] * m[1] * m[7] - m[12] * m[3] * m[5];
484
+ inv[10] = s[0] * s[5] * s[15] - s[0] * s[7] * s[13] - s[4] * s[1] * s[15] +
485
+ s[4] * s[3] * s[13] + s[12] * s[1] * s[7] - s[12] * s[3] * s[5];
457
486
 
458
- inv[14] = -m[0] * m[5] * m[14] + m[0] * m[6] * m[13] + m[4] * m[1] * m[14] -
459
- m[4] * m[2] * m[13] - m[12] * m[1] * m[6] + m[12] * m[2] * m[5];
487
+ inv[14] = -s[0] * s[5] * s[14] + s[0] * s[6] * s[13] + s[4] * s[1] * s[14] -
488
+ s[4] * s[2] * s[13] - s[12] * s[1] * s[6] + s[12] * s[2] * s[5];
460
489
 
461
- inv[3] = -m[1] * m[6] * m[11] + m[1] * m[7] * m[10] + m[5] * m[2] * m[11] -
462
- m[5] * m[3] * m[10] - m[9] * m[2] * m[7] + m[9] * m[3] * m[6];
490
+ inv[3] = -s[1] * s[6] * s[11] + s[1] * s[7] * s[10] + s[5] * s[2] * s[11] -
491
+ s[5] * s[3] * s[10] - s[9] * s[2] * s[7] + s[9] * s[3] * s[6];
463
492
 
464
- inv[7] = m[0] * m[6] * m[11] - m[0] * m[7] * m[10] - m[4] * m[2] * m[11] +
465
- m[4] * m[3] * m[10] + m[8] * m[2] * m[7] - m[8] * m[3] * m[6];
493
+ inv[7] = s[0] * s[6] * s[11] - s[0] * s[7] * s[10] - s[4] * s[2] * s[11] +
494
+ s[4] * s[3] * s[10] + s[8] * s[2] * s[7] - s[8] * s[3] * s[6];
466
495
 
467
- inv[11] = -m[0] * m[5] * m[11] + m[0] * m[7] * m[9] + m[4] * m[1] * m[11] -
468
- m[4] * m[3] * m[9] - m[8] * m[1] * m[7] + m[8] * m[3] * m[5];
496
+ inv[11] = -s[0] * s[5] * s[11] + s[0] * s[7] * s[9] + s[4] * s[1] * s[11] -
497
+ s[4] * s[3] * s[9] - s[8] * s[1] * s[7] + s[8] * s[3] * s[5];
469
498
 
470
- inv[15] = m[0] * m[5] * m[10] - m[0] * m[6] * m[9] - m[4] * m[1] * m[10] +
471
- m[4] * m[2] * m[9] + m[8] * m[1] * m[6] - m[8] * m[2] * m[5];
499
+ inv[15] = s[0] * s[5] * s[10] - s[0] * s[6] * s[9] - s[4] * s[1] * s[10] +
500
+ s[4] * s[2] * s[9] + s[8] * s[1] * s[6] - s[8] * s[2] * s[5];
472
501
 
473
- const det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
502
+ const det = s[0] * inv[0] + s[1] * inv[4] + s[2] * inv[8] + s[3] * inv[12];
474
503
 
475
504
  if (Math.abs(det) < 1e-10) {
476
505
  return null; // Singular matrix
@@ -72,12 +72,23 @@ export class Projection {
72
72
  * The projection point is at (0, 0, 0, 1) - the "north pole"
73
73
  *
74
74
  * @param {Vec4} v - 4D point (ideally on unit hypersphere)
75
+ * @param {object|Vec4} [options] - Projection options or target vector
76
+ * @param {Vec4} [target] - Optional target vector to write result to
75
77
  * @returns {Vec4} Projected point (w=0)
76
78
  */
77
- static stereographic(v, options = {}) {
78
- const epsilon = options.epsilon ?? DEFAULT_EPSILON;
79
+ static stereographic(v, options = {}, target = null) {
80
+ if (options instanceof Vec4) {
81
+ target = options;
82
+ options = {};
83
+ }
84
+
85
+ const epsilon = (options && options.epsilon) ?? DEFAULT_EPSILON;
79
86
  const denom = clampDenominator(1 - v.w, epsilon);
80
87
  const scale = 1 / denom;
88
+
89
+ if (target) {
90
+ return target.set(v.x * scale, v.y * scale, v.z * scale, 0);
91
+ }
81
92
  return new Vec4(v.x * scale, v.y * scale, v.z * scale, 0);
82
93
  }
83
94
 
@@ -107,9 +118,13 @@ export class Projection {
107
118
  * Parallel projection - no perspective distortion.
108
119
  *
109
120
  * @param {Vec4} v - 4D point
121
+ * @param {Vec4} [target] - Optional target vector to write result to
110
122
  * @returns {Vec4} Projected point (w=0)
111
123
  */
112
- static orthographic(v) {
124
+ static orthographic(v, target = null) {
125
+ if (target) {
126
+ return target.set(v.x, v.y, v.z, 0);
127
+ }
113
128
  return new Vec4(v.x, v.y, v.z, 0);
114
129
  }
115
130
 
@@ -276,48 +276,54 @@ export class Rotor4D {
276
276
  * The result applies this rotation, then r's rotation
277
277
  *
278
278
  * @param {Rotor4D} r - Right operand
279
+ * @param {Rotor4D} [target=null] - Optional target rotor to write result into
279
280
  * @returns {Rotor4D} Composed rotor
280
281
  */
281
- multiply(r) {
282
+ multiply(r, target = null) {
282
283
  // Full geometric product of two rotors in 4D
283
284
  // This is derived from the geometric algebra product rules
284
285
 
285
286
  const a = this;
286
287
  const b = r;
287
288
 
288
- return new Rotor4D(
289
- // Scalar component
290
- a.s * b.s - a.xy * b.xy - a.xz * b.xz - a.yz * b.yz -
291
- a.xw * b.xw - a.yw * b.yw - a.zw * b.zw - a.xyzw * b.xyzw,
289
+ // Compute all components first to ensure safety if target aliases a or b
290
+ const s = a.s * b.s - a.xy * b.xy - a.xz * b.xz - a.yz * b.yz -
291
+ a.xw * b.xw - a.yw * b.yw - a.zw * b.zw - a.xyzw * b.xyzw;
292
292
 
293
- // XY bivector
294
- a.s * b.xy + a.xy * b.s + a.xz * b.yz - a.yz * b.xz +
295
- a.xw * b.yw - a.yw * b.xw - a.zw * b.xyzw - a.xyzw * b.zw,
293
+ const xy = a.s * b.xy + a.xy * b.s + a.xz * b.yz - a.yz * b.xz +
294
+ a.xw * b.yw - a.yw * b.xw - a.zw * b.xyzw - a.xyzw * b.zw;
296
295
 
297
- // XZ bivector
298
- a.s * b.xz + a.xz * b.s - a.xy * b.yz + a.yz * b.xy +
299
- a.xw * b.zw + a.yw * b.xyzw - a.zw * b.xw + a.xyzw * b.yw,
296
+ const xz = a.s * b.xz + a.xz * b.s - a.xy * b.yz + a.yz * b.xy +
297
+ a.xw * b.zw + a.yw * b.xyzw - a.zw * b.xw + a.xyzw * b.yw;
300
298
 
301
- // YZ bivector
302
- a.s * b.yz + a.yz * b.s + a.xy * b.xz - a.xz * b.xy -
303
- a.xw * b.xyzw + a.yw * b.zw - a.zw * b.yw - a.xyzw * b.xw,
299
+ const yz = a.s * b.yz + a.yz * b.s + a.xy * b.xz - a.xz * b.xy -
300
+ a.xw * b.xyzw + a.yw * b.zw - a.zw * b.yw - a.xyzw * b.xw;
304
301
 
305
- // XW bivector
306
- a.s * b.xw + a.xw * b.s - a.xy * b.yw + a.xz * b.zw +
307
- a.yz * b.xyzw + a.yw * b.xy - a.zw * b.xz + a.xyzw * b.yz,
302
+ const xw = a.s * b.xw + a.xw * b.s - a.xy * b.yw + a.xz * b.zw +
303
+ a.yz * b.xyzw + a.yw * b.xy - a.zw * b.xz + a.xyzw * b.yz;
308
304
 
309
- // YW bivector
310
- a.s * b.yw + a.yw * b.s + a.xy * b.xw - a.xz * b.xyzw -
311
- a.yz * b.zw - a.xw * b.xy + a.zw * b.yz - a.xyzw * b.xz,
305
+ const yw = a.s * b.yw + a.yw * b.s + a.xy * b.xw - a.xz * b.xyzw -
306
+ a.yz * b.zw - a.xw * b.xy + a.zw * b.yz - a.xyzw * b.xz;
312
307
 
313
- // ZW bivector
314
- a.s * b.zw + a.zw * b.s + a.xy * b.xyzw + a.xz * b.xw +
315
- a.yz * b.yw - a.xw * b.xz - a.yw * b.yz + a.xyzw * b.xy,
308
+ const zw = a.s * b.zw + a.zw * b.s + a.xy * b.xyzw + a.xz * b.xw +
309
+ a.yz * b.yw - a.xw * b.xz - a.yw * b.yz + a.xyzw * b.xy;
316
310
 
317
- // Pseudoscalar XYZW
318
- a.s * b.xyzw + a.xyzw * b.s + a.xy * b.zw - a.xz * b.yw +
319
- a.yz * b.xw + a.xw * b.yz - a.yw * b.xz + a.zw * b.xy
320
- );
311
+ const xyzw = a.s * b.xyzw + a.xyzw * b.s + a.xy * b.zw - a.xz * b.yw +
312
+ a.yz * b.xw + a.xw * b.yz - a.yw * b.xz + a.zw * b.xy;
313
+
314
+ if (target) {
315
+ target.s = s;
316
+ target.xy = xy;
317
+ target.xz = xz;
318
+ target.yz = yz;
319
+ target.xw = xw;
320
+ target.yw = yw;
321
+ target.zw = zw;
322
+ target.xyzw = xyzw;
323
+ return target;
324
+ }
325
+
326
+ return new Rotor4D(s, xy, xz, yz, xw, yw, zw, xyzw);
321
327
  }
322
328
 
323
329
  /**
package/src/math/Vec4.js CHANGED
@@ -313,7 +313,11 @@ export class Vec4 {
313
313
  * @returns {number}
314
314
  */
315
315
  distanceTo(v) {
316
- return this.sub(v).length();
316
+ const dx = this._x - v._x;
317
+ const dy = this._y - v._y;
318
+ const dz = this._z - v._z;
319
+ const dw = this._w - v._w;
320
+ return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
317
321
  }
318
322
 
319
323
  /**
@@ -322,7 +326,11 @@ export class Vec4 {
322
326
  * @returns {number}
323
327
  */
324
328
  distanceToSquared(v) {
325
- return this.sub(v).lengthSquared();
329
+ const dx = this._x - v._x;
330
+ const dy = this._y - v._y;
331
+ const dz = this._z - v._z;
332
+ const dw = this._w - v._w;
333
+ return dx * dx + dy * dy + dz * dz + dw * dw;
326
334
  }
327
335
 
328
336
  /**
@@ -408,42 +416,91 @@ export class Vec4 {
408
416
  /**
409
417
  * Project 4D point to 3D using perspective projection
410
418
  * Projects from 4D to 3D by dividing by (d - w)
411
- * @param {number} d - Distance parameter (usually 2-5)
412
- * @param {object} [options] - Projection options (epsilon, distance)
419
+ * @param {number|object} d - Distance parameter (usually 2-5) or options object
420
+ * @param {object|Vec4} [options] - Projection options or target vector
421
+ * @param {Vec4} [target] - Target vector to store result
413
422
  * @returns {Vec4} Projected point (w component is 0)
414
423
  */
415
- projectPerspective(d = 2, options = {}) {
424
+ projectPerspective(d = 2, options = {}, target = null) {
416
425
  if (typeof d === 'object') {
426
+ // usage: projectPerspective({ distance: 2, ... }, target?)
427
+ if (options instanceof Vec4) {
428
+ target = options;
429
+ }
417
430
  options = d;
418
431
  d = options.distance ?? options.d ?? 2;
432
+ } else {
433
+ // usage: projectPerspective(d, options?, target?)
434
+ // usage: projectPerspective(d, target?)
435
+ if (options instanceof Vec4) {
436
+ target = options;
437
+ options = {};
438
+ }
419
439
  }
440
+
441
+ options = options || {};
442
+
420
443
  const epsilon = options.epsilon ?? 1e-5;
421
444
  const denom = d - this._w;
422
445
  const clamped = Math.abs(denom) < epsilon ? (denom >= 0 ? epsilon : -epsilon) : denom;
423
446
  const scale = 1 / clamped;
447
+
448
+ if (target) {
449
+ target._x = this._x * scale;
450
+ target._y = this._y * scale;
451
+ target._z = this._z * scale;
452
+ target._w = 0;
453
+ return target;
454
+ }
455
+
424
456
  return new Vec4(this._x * scale, this._y * scale, this._z * scale, 0);
425
457
  }
426
458
 
427
459
  /**
428
460
  * Project 4D point to 3D using stereographic projection
429
461
  * Maps 4D hypersphere to 3D space
430
- * @param {object} [options] - Projection options (epsilon)
462
+ * @param {object|Vec4} [options] - Projection options or target vector
463
+ * @param {Vec4} [target] - Target vector to store result
431
464
  * @returns {Vec4} Projected point (w component is 0)
432
465
  */
433
- projectStereographic(options = {}) {
466
+ projectStereographic(options = {}, target = null) {
467
+ if (options instanceof Vec4) {
468
+ target = options;
469
+ options = {};
470
+ }
471
+
472
+ options = options || {};
473
+
434
474
  const epsilon = options.epsilon ?? 1e-5;
435
475
  const denom = 1 - this._w;
436
476
  const clamped = Math.abs(denom) < epsilon ? (denom >= 0 ? epsilon : -epsilon) : denom;
437
477
  const scale = 1 / clamped;
478
+
479
+ if (target) {
480
+ target._x = this._x * scale;
481
+ target._y = this._y * scale;
482
+ target._z = this._z * scale;
483
+ target._w = 0;
484
+ return target;
485
+ }
486
+
438
487
  return new Vec4(this._x * scale, this._y * scale, this._z * scale, 0);
439
488
  }
440
489
 
441
490
  /**
442
491
  * Project 4D point to 3D using orthographic projection
443
492
  * Simply drops the W component
493
+ * @param {Vec4} [target=null] - Optional target vector
444
494
  * @returns {Vec4} Projected point (w component is 0)
445
495
  */
446
- projectOrthographic() {
496
+ projectOrthographic(target = null) {
497
+ if (target) {
498
+ target._x = this._x;
499
+ target._y = this._y;
500
+ target._z = this._z;
501
+ target._w = 0;
502
+ return target;
503
+ }
447
504
  return new Vec4(this._x, this._y, this._z, 0);
448
505
  }
449
506