@vib3code/sdk 2.0.3-canary.bd4d4a5 → 2.0.3-canary.e86d5a7

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.bd4d4a5",
3
+ "version": "2.0.3-canary.e86d5a7",
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",
@@ -9,7 +9,9 @@
9
9
  "vib3": "./src/cli/index.js",
10
10
  "vib3-mcp": "./src/agent/mcp/stdio-server.js"
11
11
  },
12
- "sideEffects": false,
12
+ "sideEffects": [
13
+ "./src/geometry/builders/*.js"
14
+ ],
13
15
  "exports": {
14
16
  ".": {
15
17
  "types": "./types/adaptive-sdk.d.ts",
@@ -16,14 +16,13 @@ import { Vec4 } from '../../math/Vec4.js';
16
16
  * @param {number} radius - Hypersphere radius
17
17
  * @returns {Vec4} Point on hypersphere
18
18
  */
19
- export function projectToHypersphere(point, radius = 1, target = null) {
19
+ export function projectToHypersphere(point, radius = 1) {
20
20
  const len = point.length();
21
21
  if (len < 0.0001) {
22
22
  // Handle origin - project to north pole
23
- if (target) return target.set(0, 0, 0, radius);
24
23
  return new Vec4(0, 0, 0, radius);
25
24
  }
26
- return point.scale(radius / len, target);
25
+ return point.scale(radius / len);
27
26
  }
28
27
 
29
28
  /**
@@ -31,10 +30,9 @@ export function projectToHypersphere(point, radius = 1, target = null) {
31
30
  * Maps all of 3D space onto the 4D hypersphere
32
31
  * @param {Vec4} point - Input point (uses x, y, z)
33
32
  * @param {number} radius - Hypersphere radius
34
- * @param {Vec4} [target=null] - Optional target vector
35
33
  * @returns {Vec4} Point on hypersphere
36
34
  */
37
- export function stereographicToHypersphere(point, radius = 1, target = null) {
35
+ export function stereographicToHypersphere(point, radius = 1) {
38
36
  const x = point.x;
39
37
  const y = point.y;
40
38
  const z = point.z;
@@ -42,15 +40,6 @@ export function stereographicToHypersphere(point, radius = 1, target = null) {
42
40
  const sumSq = x * x + y * y + z * z;
43
41
  const denom = sumSq + 1;
44
42
 
45
- if (target) {
46
- return target.set(
47
- (2 * x) / denom * radius,
48
- (2 * y) / denom * radius,
49
- (2 * z) / denom * radius,
50
- (sumSq - 1) / denom * radius
51
- );
52
- }
53
-
54
43
  return new Vec4(
55
44
  (2 * x) / denom * radius,
56
45
  (2 * y) / denom * radius,
@@ -67,22 +56,12 @@ export function stereographicToHypersphere(point, radius = 1, target = null) {
67
56
  * @param {number} phi - Azimuth on base S² (0 to 2π)
68
57
  * @param {number} psi - Fiber angle (0 to 2π)
69
58
  * @param {number} radius - Hypersphere radius
70
- * @param {Vec4} [target=null] - Optional target vector
71
59
  * @returns {Vec4} Point on hypersphere
72
60
  */
73
- export function hopfFibration(theta, phi, psi, radius = 1, target = null) {
61
+ export function hopfFibration(theta, phi, psi, radius = 1) {
74
62
  const cosTheta2 = Math.cos(theta / 2);
75
63
  const sinTheta2 = Math.sin(theta / 2);
76
64
 
77
- if (target) {
78
- return target.set(
79
- cosTheta2 * Math.cos((phi + psi) / 2) * radius,
80
- cosTheta2 * Math.sin((phi + psi) / 2) * radius,
81
- sinTheta2 * Math.cos((phi - psi) / 2) * radius,
82
- sinTheta2 * Math.sin((phi - psi) / 2) * radius
83
- );
84
- }
85
-
86
65
  return new Vec4(
87
66
  cosTheta2 * Math.cos((phi + psi) / 2) * radius,
88
67
  cosTheta2 * Math.sin((phi + psi) / 2) * radius,
@@ -99,9 +78,8 @@ export function hopfFibration(theta, phi, psi, radius = 1, target = null) {
99
78
  * @returns {Vec4[]} Warped vertices
100
79
  */
101
80
  export function warpRadial(vertices, radius = 1, blendFactor = 1) {
102
- const onSphere = new Vec4();
103
81
  return vertices.map(v => {
104
- projectToHypersphere(v, radius, onSphere);
82
+ const onSphere = projectToHypersphere(v, radius);
105
83
  return v.lerp(onSphere, blendFactor);
106
84
  });
107
85
  }
@@ -115,9 +93,8 @@ export function warpRadial(vertices, radius = 1, blendFactor = 1) {
115
93
  * @returns {Vec4[]} Warped vertices
116
94
  */
117
95
  export function warpStereographic(vertices, radius = 1, scale = 1) {
118
- const scaled = new Vec4();
119
96
  return vertices.map(v => {
120
- v.scale(scale, scaled);
97
+ const scaled = v.scale(scale);
121
98
  return stereographicToHypersphere(scaled, radius);
122
99
  });
123
100
  }
@@ -169,31 +146,25 @@ export function warpHypersphereCore(geometry, options = {}) {
169
146
  twist = 1
170
147
  } = options;
171
148
 
172
- const temp = new Vec4();
173
- const warpedVertices = geometry.vertices.map(v => {
174
- // Combined scaling and warping to minimize allocations
175
- const result = v.scale(scale);
176
-
177
- if (method === 'stereographic') {
178
- stereographicToHypersphere(result, radius, result);
179
- } else if (method === 'hopf') {
180
- const r = result.length();
181
- if (r < 0.0001) {
182
- result.set(0, 0, 0, radius);
183
- } else {
184
- const theta = Math.acos(result.z / r);
185
- const phi = Math.atan2(result.y, result.x);
186
- const psi = result.w * twist + phi * 0.5;
187
- hopfFibration(theta, phi, psi, radius, result);
188
- }
189
- } else {
190
- // Radial (default)
191
- projectToHypersphere(result, radius, temp);
192
- result.lerp(temp, blend, result);
193
- }
149
+ let warpedVertices;
194
150
 
195
- return result;
196
- });
151
+ // Pre-scale vertices
152
+ const scaledVertices = geometry.vertices.map(v => v.scale(scale));
153
+
154
+ switch (method) {
155
+ case 'stereographic':
156
+ warpedVertices = warpStereographic(scaledVertices, radius, 1);
157
+ break;
158
+
159
+ case 'hopf':
160
+ warpedVertices = warpHopf(scaledVertices, radius, twist);
161
+ break;
162
+
163
+ case 'radial':
164
+ default:
165
+ warpedVertices = warpRadial(scaledVertices, radius, blend);
166
+ break;
167
+ }
197
168
 
198
169
  return {
199
170
  ...geometry,