@vib3code/sdk 2.0.1 → 2.0.3-canary.6f35b4c

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.
Files changed (96) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/DOCS/AGENT_HARNESS_ARCHITECTURE.md +243 -0
  3. package/DOCS/CLI_ONBOARDING.md +1 -1
  4. package/DOCS/CROSS_SITE_DESIGN_PATTERNS.md +117 -0
  5. package/DOCS/EPIC_SCROLL_EVENTS.md +773 -0
  6. package/DOCS/HANDOFF_LANDING_PAGE.md +154 -0
  7. package/DOCS/HANDOFF_SDK_DEVELOPMENT.md +493 -0
  8. package/DOCS/MULTIVIZ_CHOREOGRAPHY_PATTERNS.md +937 -0
  9. package/DOCS/PRODUCT_STRATEGY.md +63 -0
  10. package/DOCS/README.md +103 -0
  11. package/DOCS/REFERENCE_SCROLL_ANALYSIS.md +97 -0
  12. package/DOCS/ROADMAP.md +111 -0
  13. package/DOCS/SCROLL_TIMELINE_v3.md +269 -0
  14. package/DOCS/SITE_REFACTOR_PLAN.md +100 -0
  15. package/DOCS/STATUS.md +24 -0
  16. package/DOCS/SYSTEM_INVENTORY.md +33 -30
  17. package/DOCS/VISUAL_ANALYSIS_CLICKERSS.md +85 -0
  18. package/DOCS/VISUAL_ANALYSIS_FACETAD.md +133 -0
  19. package/DOCS/VISUAL_ANALYSIS_SIMONE.md +95 -0
  20. package/DOCS/VISUAL_ANALYSIS_TABLESIDE.md +86 -0
  21. package/DOCS/{BLUEPRINT_EXECUTION_PLAN_2026-01-07.md → archive/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md} +1 -1
  22. package/DOCS/{DEV_TRACK_ANALYSIS.md → archive/DEV_TRACK_ANALYSIS.md} +3 -0
  23. package/DOCS/{SYSTEM_AUDIT_2026-01-30.md → archive/SYSTEM_AUDIT_2026-01-30.md} +3 -0
  24. package/DOCS/{DEV_TRACK_SESSION_2026-01-31.md → dev-tracks/DEV_TRACK_SESSION_2026-01-31.md} +1 -1
  25. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-06.md +231 -0
  26. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-13.md +127 -0
  27. package/DOCS/dev-tracks/README.md +10 -0
  28. package/README.md +26 -13
  29. package/cpp/CMakeLists.txt +236 -0
  30. package/cpp/bindings/embind.cpp +269 -0
  31. package/cpp/build.sh +129 -0
  32. package/cpp/geometry/Crystal.cpp +103 -0
  33. package/cpp/geometry/Fractal.cpp +136 -0
  34. package/cpp/geometry/GeometryGenerator.cpp +262 -0
  35. package/cpp/geometry/KleinBottle.cpp +71 -0
  36. package/cpp/geometry/Sphere.cpp +134 -0
  37. package/cpp/geometry/Tesseract.cpp +94 -0
  38. package/cpp/geometry/Tetrahedron.cpp +83 -0
  39. package/cpp/geometry/Torus.cpp +65 -0
  40. package/cpp/geometry/WarpFunctions.cpp +238 -0
  41. package/cpp/geometry/Wave.cpp +85 -0
  42. package/cpp/include/vib3_ffi.h +238 -0
  43. package/cpp/math/Mat4x4.cpp +409 -0
  44. package/cpp/math/Mat4x4.hpp +209 -0
  45. package/cpp/math/Projection.cpp +142 -0
  46. package/cpp/math/Projection.hpp +148 -0
  47. package/cpp/math/Rotor4D.cpp +322 -0
  48. package/cpp/math/Rotor4D.hpp +204 -0
  49. package/cpp/math/Vec4.cpp +303 -0
  50. package/cpp/math/Vec4.hpp +225 -0
  51. package/cpp/src/vib3_ffi.cpp +607 -0
  52. package/cpp/tests/Geometry_test.cpp +213 -0
  53. package/cpp/tests/Mat4x4_test.cpp +494 -0
  54. package/cpp/tests/Projection_test.cpp +298 -0
  55. package/cpp/tests/Rotor4D_test.cpp +423 -0
  56. package/cpp/tests/Vec4_test.cpp +489 -0
  57. package/package.json +31 -27
  58. package/src/agent/mcp/MCPServer.js +722 -0
  59. package/src/agent/mcp/stdio-server.js +264 -0
  60. package/src/agent/mcp/tools.js +367 -0
  61. package/src/cli/index.js +0 -0
  62. package/src/core/CanvasManager.js +97 -204
  63. package/src/core/ErrorReporter.js +1 -1
  64. package/src/core/Parameters.js +1 -1
  65. package/src/core/VIB3Engine.js +38 -1
  66. package/src/core/VitalitySystem.js +53 -0
  67. package/src/core/renderers/HolographicRendererAdapter.js +2 -2
  68. package/src/creative/AestheticMapper.js +628 -0
  69. package/src/creative/ChoreographyPlayer.js +481 -0
  70. package/src/export/TradingCardManager.js +3 -4
  71. package/src/faceted/FacetedSystem.js +237 -388
  72. package/src/holograms/HolographicVisualizer.js +29 -12
  73. package/src/holograms/RealHolographicSystem.js +68 -12
  74. package/src/polychora/PolychoraSystem.js +77 -0
  75. package/src/quantum/QuantumEngine.js +103 -66
  76. package/src/quantum/QuantumVisualizer.js +7 -2
  77. package/src/render/UnifiedRenderBridge.js +3 -0
  78. package/src/shaders/faceted/faceted.frag.glsl +220 -80
  79. package/src/shaders/faceted/faceted.frag.wgsl +138 -97
  80. package/src/shaders/holographic/holographic.frag.glsl +28 -9
  81. package/src/shaders/holographic/holographic.frag.wgsl +107 -38
  82. package/src/shaders/quantum/quantum.frag.glsl +1 -0
  83. package/src/shaders/quantum/quantum.frag.wgsl +1 -1
  84. package/src/viewer/index.js +1 -1
  85. package/tools/headless-renderer.js +258 -0
  86. package/tools/shader-sync-verify.js +8 -4
  87. package/tools/site-analysis/all-reports.json +32 -0
  88. package/tools/site-analysis/combined-analysis.md +50 -0
  89. package/tools/site-analyzer.mjs +779 -0
  90. package/tools/visual-catalog/capture.js +276 -0
  91. package/tools/visual-catalog/composite.js +138 -0
  92. /package/DOCS/{DEV_TRACK_PLAN_2026-01-07.md → archive/DEV_TRACK_PLAN_2026-01-07.md} +0 -0
  93. /package/DOCS/{SESSION_014_PLAN.md → archive/SESSION_014_PLAN.md} +0 -0
  94. /package/DOCS/{SESSION_LOG_2026-01-07.md → archive/SESSION_LOG_2026-01-07.md} +0 -0
  95. /package/DOCS/{STRATEGIC_BLUEPRINT_2026-01-07.md → archive/STRATEGIC_BLUEPRINT_2026-01-07.md} +0 -0
  96. /package/src/viewer/{ReactivityManager.js → ViewerInputHandler.js} +0 -0
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Crystal.cpp - Octahedral / Crystalline Structure in 4D
3
+ *
4
+ * Generates vertices and edge geometry for crystalline structures
5
+ * in 4D: the regular octahedron (cross-polytope) and its dual,
6
+ * extended with 4D vertices along the W axis.
7
+ *
8
+ * The 4D cross-polytope (hyperoctahedron / 16-cell) has 8 vertices
9
+ * at the 4 axis-aligned unit positions and their negations.
10
+ */
11
+
12
+ #include "math/Vec4.hpp"
13
+ #include <vector>
14
+ #include <cmath>
15
+ #include <numbers>
16
+
17
+ namespace vib3 {
18
+
19
+ /**
20
+ * Generate the 8 vertices of a 4D cross-polytope (hyperoctahedron / 16-cell).
21
+ *
22
+ * Vertices lie at (+-1, 0, 0, 0), (0, +-1, 0, 0), (0, 0, +-1, 0), (0, 0, 0, +-1).
23
+ */
24
+ std::vector<Vec4> generateCrossPolytopeVertices() noexcept {
25
+ std::vector<Vec4> vertices;
26
+ vertices.reserve(8);
27
+
28
+ vertices.emplace_back( 1.0f, 0.0f, 0.0f, 0.0f);
29
+ vertices.emplace_back(-1.0f, 0.0f, 0.0f, 0.0f);
30
+ vertices.emplace_back( 0.0f, 1.0f, 0.0f, 0.0f);
31
+ vertices.emplace_back( 0.0f, -1.0f, 0.0f, 0.0f);
32
+ vertices.emplace_back( 0.0f, 0.0f, 1.0f, 0.0f);
33
+ vertices.emplace_back( 0.0f, 0.0f, -1.0f, 0.0f);
34
+ vertices.emplace_back( 0.0f, 0.0f, 0.0f, 1.0f);
35
+ vertices.emplace_back( 0.0f, 0.0f, 0.0f, -1.0f);
36
+
37
+ return vertices;
38
+ }
39
+
40
+ /**
41
+ * Generate crystalline geometry with edge interpolation.
42
+ *
43
+ * The 4D cross-polytope has 24 edges: every pair of non-antipodal vertices
44
+ * is connected (i.e., vertices i and j are connected unless they lie on
45
+ * the same axis). Each edge is subdivided into `resolution` segments.
46
+ *
47
+ * Additionally generates midpoint vertices for a dual-lattice structure
48
+ * (the 4D hypercube formed by the dual vertices at the edge midpoints).
49
+ *
50
+ * @param resolution Number of subdivisions per edge (minimum 2)
51
+ * @return Vector of 4D points forming the crystal wireframe
52
+ */
53
+ std::vector<Vec4> generateCrystal(int resolution) noexcept {
54
+ if (resolution < 2) resolution = 2;
55
+
56
+ auto baseVertices = generateCrossPolytopeVertices();
57
+
58
+ // Edges of the 16-cell: connect every pair of vertices that are
59
+ // NOT antipodal (not on the same axis).
60
+ // 8 vertices, 24 edges total.
61
+ struct Edge { int a, b; };
62
+ std::vector<Edge> edges;
63
+ edges.reserve(24);
64
+
65
+ for (int i = 0; i < 8; ++i) {
66
+ for (int j = i + 1; j < 8; ++j) {
67
+ // Antipodal pairs: (0,1), (2,3), (4,5), (6,7)
68
+ // Skip if on same axis (differ by 1 and i is even)
69
+ if ((i ^ j) == 1 && (i % 2 == 0)) {
70
+ continue;
71
+ }
72
+ edges.push_back({i, j});
73
+ }
74
+ }
75
+
76
+ std::vector<Vec4> vertices;
77
+ vertices.reserve(edges.size() * static_cast<size_t>(resolution) + 16);
78
+
79
+ // Edge wireframe
80
+ for (const auto& edge : edges) {
81
+ const Vec4& a = baseVertices[static_cast<size_t>(edge.a)];
82
+ const Vec4& b = baseVertices[static_cast<size_t>(edge.b)];
83
+
84
+ for (int i = 0; i < resolution; ++i) {
85
+ float t = static_cast<float>(i) / static_cast<float>(resolution - 1);
86
+ vertices.push_back(a.lerp(b, t));
87
+ }
88
+ }
89
+
90
+ // Dual vertices (tesseract / hypercube dual): midpoints of faces
91
+ // These are the 16 vertices of the dual polytope at (+-0.5, +-0.5, +-0.5, +-0.5)
92
+ for (int i = 0; i < 16; ++i) {
93
+ float x = (i & 1) ? 0.5f : -0.5f;
94
+ float y = (i & 2) ? 0.5f : -0.5f;
95
+ float z = (i & 4) ? 0.5f : -0.5f;
96
+ float w = (i & 8) ? 0.5f : -0.5f;
97
+ vertices.emplace_back(x, y, z, w);
98
+ }
99
+
100
+ return vertices;
101
+ }
102
+
103
+ } // namespace vib3
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Fractal.cpp - 4D Iterated Function System Fractal
3
+ *
4
+ * Generates recursive subdivision geometry in 4D using an IFS approach.
5
+ * Starts from an initial set of points and iteratively applies affine
6
+ * contractions toward attractor vertices, building a self-similar
7
+ * fractal structure (a 4D analogue of the Sierpinski tetrahedron).
8
+ */
9
+
10
+ #include "math/Vec4.hpp"
11
+ #include <vector>
12
+ #include <cmath>
13
+ #include <numbers>
14
+ #include <cstdint>
15
+
16
+ namespace vib3 {
17
+
18
+ namespace {
19
+
20
+ /**
21
+ * 4D Sierpinski-style attractor vertices.
22
+ *
23
+ * Five vertices of a regular 5-cell (pentatope) provide a natural
24
+ * set of contraction centers for a 4D IFS.
25
+ */
26
+ constexpr int kNumAttractors = 5;
27
+
28
+ Vec4 getAttractorVertex(int index) noexcept {
29
+ // Regular pentatope vertices (5-cell), embedded in R4
30
+ // These are the vertices of a regular simplex in 4D.
31
+ switch (index) {
32
+ case 0: return Vec4( 1.0f, 1.0f, 1.0f, -1.0f / std::numbers::sqrt2_v<float>);
33
+ case 1: return Vec4( 1.0f, -1.0f, -1.0f, -1.0f / std::numbers::sqrt2_v<float>);
34
+ case 2: return Vec4(-1.0f, 1.0f, -1.0f, -1.0f / std::numbers::sqrt2_v<float>);
35
+ case 3: return Vec4(-1.0f, -1.0f, 1.0f, -1.0f / std::numbers::sqrt2_v<float>);
36
+ case 4: return Vec4( 0.0f, 0.0f, 0.0f, 4.0f / std::numbers::sqrt2_v<float>);
37
+ default: return Vec4::zero();
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Simple deterministic hash for reproducible pseudo-random attractor selection.
43
+ */
44
+ constexpr uint32_t hashStep(uint32_t seed) noexcept {
45
+ seed ^= seed << 13;
46
+ seed ^= seed >> 17;
47
+ seed ^= seed << 5;
48
+ return seed;
49
+ }
50
+
51
+ } // anonymous namespace
52
+
53
+ /**
54
+ * Generate a 4D IFS fractal via the chaos game.
55
+ *
56
+ * Uses the classic chaos game algorithm: starting from a seed point,
57
+ * repeatedly pick a random attractor and move halfway toward it.
58
+ * After a warm-up period, the trajectory traces out the fractal.
59
+ *
60
+ * @param resolution Controls the number of output points (resolution^2 points)
61
+ * @return Vector of 4D fractal points
62
+ */
63
+ std::vector<Vec4> generateFractal(int resolution) noexcept {
64
+ if (resolution < 4) resolution = 4;
65
+
66
+ int numPoints = resolution * resolution;
67
+ constexpr int warmUp = 64;
68
+ constexpr float contractionFactor = 0.5f;
69
+
70
+ std::vector<Vec4> vertices;
71
+ vertices.reserve(static_cast<size_t>(numPoints));
72
+
73
+ // Start at the origin
74
+ Vec4 current = Vec4::zero();
75
+ uint32_t seed = 0xDEADBEEF;
76
+
77
+ // Warm-up iterations (discard to converge onto attractor)
78
+ for (int i = 0; i < warmUp; ++i) {
79
+ seed = hashStep(seed);
80
+ int attIdx = static_cast<int>(seed % kNumAttractors);
81
+ Vec4 target = getAttractorVertex(attIdx);
82
+ current = current.lerp(target, contractionFactor);
83
+ }
84
+
85
+ // Generate fractal points
86
+ for (int i = 0; i < numPoints; ++i) {
87
+ seed = hashStep(seed);
88
+ int attIdx = static_cast<int>(seed % kNumAttractors);
89
+ Vec4 target = getAttractorVertex(attIdx);
90
+ current = current.lerp(target, contractionFactor);
91
+ vertices.push_back(current);
92
+ }
93
+
94
+ return vertices;
95
+ }
96
+
97
+ /**
98
+ * Generate a 4D IFS fractal via recursive subdivision.
99
+ *
100
+ * Starts from attractor vertices and recursively subdivides midpoints
101
+ * to a given depth, producing a deterministic point set.
102
+ *
103
+ * @param depth Recursion depth (0 = just vertices, each level multiplies points by 5)
104
+ * @return Vector of 4D fractal points
105
+ */
106
+ std::vector<Vec4> generateFractalSubdivision(int depth) noexcept {
107
+ if (depth < 0) depth = 0;
108
+ if (depth > 6) depth = 6; // Cap to avoid excessive memory
109
+
110
+ std::vector<Vec4> current;
111
+ current.reserve(static_cast<size_t>(kNumAttractors));
112
+
113
+ // Seed with attractor vertices
114
+ for (int i = 0; i < kNumAttractors; ++i) {
115
+ current.push_back(getAttractorVertex(i));
116
+ }
117
+
118
+ // Recursive subdivision
119
+ for (int d = 0; d < depth; ++d) {
120
+ std::vector<Vec4> next;
121
+ next.reserve(current.size() * static_cast<size_t>(kNumAttractors));
122
+
123
+ for (const auto& point : current) {
124
+ for (int a = 0; a < kNumAttractors; ++a) {
125
+ Vec4 target = getAttractorVertex(a);
126
+ next.push_back(point.lerp(target, 0.5f));
127
+ }
128
+ }
129
+
130
+ current = std::move(next);
131
+ }
132
+
133
+ return current;
134
+ }
135
+
136
+ } // namespace vib3
@@ -0,0 +1,262 @@
1
+ /**
2
+ * GeometryGenerator.cpp - Main Geometry Factory
3
+ *
4
+ * Dispatches to individual geometry generators based on geometry index.
5
+ * Uses the VIB3+ encoding: index = coreType * 8 + baseGeometry
6
+ *
7
+ * Core types:
8
+ * 0 = Base (index 0-7) - Pure base geometry
9
+ * 1 = Hypersphere (index 8-15) - Projected onto 3-sphere
10
+ * 2 = Hypertetrahedron (index 16-23) - Warped toward pentatope
11
+ *
12
+ * Base geometries (0-7):
13
+ * 0 = Tetrahedron 4 = Klein Bottle
14
+ * 1 = Hypercube 5 = Fractal
15
+ * 2 = Sphere 6 = Wave
16
+ * 3 = Torus 7 = Crystal
17
+ */
18
+
19
+ #include "math/Vec4.hpp"
20
+ #include <vector>
21
+ #include <algorithm>
22
+
23
+ namespace vib3 {
24
+
25
+ // ---- Forward declarations of individual generators ----
26
+
27
+ // geometry/Tetrahedron.cpp
28
+ std::vector<Vec4> generateTetrahedron(int resolution) noexcept;
29
+
30
+ // geometry/Tesseract.cpp
31
+ std::vector<Vec4> generateTesseract(int resolution) noexcept;
32
+
33
+ // geometry/Sphere.cpp
34
+ std::vector<Vec4> generateSphere(int resolution) noexcept;
35
+
36
+ // geometry/Torus.cpp
37
+ std::vector<Vec4> generateTorus(int resolution) noexcept;
38
+
39
+ // geometry/KleinBottle.cpp
40
+ std::vector<Vec4> generateKleinBottle(int resolution) noexcept;
41
+
42
+ // geometry/Fractal.cpp
43
+ std::vector<Vec4> generateFractal(int resolution) noexcept;
44
+
45
+ // geometry/Wave.cpp
46
+ std::vector<Vec4> generateWave(int resolution) noexcept;
47
+
48
+ // geometry/Crystal.cpp
49
+ std::vector<Vec4> generateCrystal(int resolution) noexcept;
50
+
51
+ // geometry/WarpFunctions.cpp
52
+ Vec4 warpHypersphere(Vec4 point, float radius) noexcept;
53
+ std::vector<Vec4> warpHypersphereBatch(const std::vector<Vec4>& points, float radius) noexcept;
54
+ Vec4 warpHypertetra(Vec4 point) noexcept;
55
+ std::vector<Vec4> warpHypertetraBatch(const std::vector<Vec4>& points) noexcept;
56
+
57
+ // ---- Geometry index encoding ----
58
+
59
+ /**
60
+ * Maximum valid geometry index (3 core types x 8 base geometries - 1).
61
+ */
62
+ constexpr int kMaxGeometryIndex = 23;
63
+
64
+ /**
65
+ * Number of base geometry types.
66
+ */
67
+ constexpr int kBaseGeometryCount = 8;
68
+
69
+ /**
70
+ * Decompose a geometry index into core type and base geometry.
71
+ *
72
+ * @param geometryIndex Combined index (0-23)
73
+ * @param coreType Output: 0=Base, 1=Hypersphere, 2=Hypertetrahedron
74
+ * @param baseGeometry Output: 0-7 base geometry type
75
+ */
76
+ constexpr void decodeGeometryIndex(int geometryIndex,
77
+ int& coreType,
78
+ int& baseGeometry) noexcept {
79
+ coreType = geometryIndex / kBaseGeometryCount;
80
+ baseGeometry = geometryIndex % kBaseGeometryCount;
81
+ }
82
+
83
+ /**
84
+ * Encode core type and base geometry into a geometry index.
85
+ *
86
+ * @param coreType 0=Base, 1=Hypersphere, 2=Hypertetrahedron
87
+ * @param baseGeometry 0-7 base geometry type
88
+ * @return Combined geometry index (0-23)
89
+ */
90
+ constexpr int encodeGeometryIndex(int coreType, int baseGeometry) noexcept {
91
+ return coreType * kBaseGeometryCount + baseGeometry;
92
+ }
93
+
94
+ // ---- Internal dispatch ----
95
+
96
+ namespace {
97
+
98
+ /**
99
+ * Generate base geometry vertices for a given base type.
100
+ */
101
+ std::vector<Vec4> generateBaseGeometry(int baseGeometry, int resolution) noexcept {
102
+ switch (baseGeometry) {
103
+ case 0: return generateTetrahedron(resolution);
104
+ case 1: return generateTesseract(resolution);
105
+ case 2: return generateSphere(resolution);
106
+ case 3: return generateTorus(resolution);
107
+ case 4: return generateKleinBottle(resolution);
108
+ case 5: return generateFractal(resolution);
109
+ case 6: return generateWave(resolution);
110
+ case 7: return generateCrystal(resolution);
111
+ default:
112
+ // Unknown base geometry, return empty
113
+ return {};
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Apply core type warp to a set of base vertices.
119
+ */
120
+ std::vector<Vec4> applyWarp(int coreType, std::vector<Vec4> vertices) noexcept {
121
+ switch (coreType) {
122
+ case 0:
123
+ // Base: no warp
124
+ return vertices;
125
+
126
+ case 1:
127
+ // Hypersphere: project all vertices onto S3
128
+ return warpHypersphereBatch(vertices, 1.0f);
129
+
130
+ case 2:
131
+ // Hypertetrahedron: warp toward pentatope vertices
132
+ return warpHypertetraBatch(vertices);
133
+
134
+ default:
135
+ // Unknown core type, return unmodified
136
+ return vertices;
137
+ }
138
+ }
139
+
140
+ } // anonymous namespace
141
+
142
+ // ---- Public API ----
143
+
144
+ /**
145
+ * Generate 4D geometry for a given geometry index.
146
+ *
147
+ * This is the main entry point for the geometry library. It decodes the
148
+ * geometry index into a base geometry type and core type warp, generates
149
+ * the base geometry, and then applies the appropriate warp transformation.
150
+ *
151
+ * @param geometryIndex Combined geometry index (0-23)
152
+ * - 0-7: Base geometries (no warp)
153
+ * - 8-15: Hypersphere-warped geometries
154
+ * - 16-23: Hypertetrahedron-warped geometries
155
+ *
156
+ * @param resolution Controls the level of detail. Higher values produce
157
+ * more vertices. The exact meaning varies by geometry type but generally
158
+ * represents subdivisions per dimension. Typical range: 4-100.
159
+ *
160
+ * @return Vector of 4D vertices. Empty if geometryIndex is out of range.
161
+ */
162
+ std::vector<Vec4> generateGeometry(int geometryIndex, int resolution) noexcept {
163
+ // Clamp to valid range
164
+ if (geometryIndex < 0 || geometryIndex > kMaxGeometryIndex) {
165
+ return {};
166
+ }
167
+
168
+ if (resolution < 2) resolution = 2;
169
+ if (resolution > 256) resolution = 256;
170
+
171
+ int coreType = 0;
172
+ int baseGeometry = 0;
173
+ decodeGeometryIndex(geometryIndex, coreType, baseGeometry);
174
+
175
+ // Generate base geometry
176
+ std::vector<Vec4> vertices = generateBaseGeometry(baseGeometry, resolution);
177
+
178
+ // Apply core type warp
179
+ return applyWarp(coreType, std::move(vertices));
180
+ }
181
+
182
+ /**
183
+ * Get the name string for a base geometry type.
184
+ *
185
+ * @param baseGeometry Base geometry index (0-7)
186
+ * @return Human-readable name, or "Unknown" if out of range
187
+ */
188
+ const char* getBaseGeometryName(int baseGeometry) noexcept {
189
+ switch (baseGeometry) {
190
+ case 0: return "Tetrahedron";
191
+ case 1: return "Hypercube";
192
+ case 2: return "Sphere";
193
+ case 3: return "Torus";
194
+ case 4: return "Klein Bottle";
195
+ case 5: return "Fractal";
196
+ case 6: return "Wave";
197
+ case 7: return "Crystal";
198
+ default: return "Unknown";
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Get the name string for a core type.
204
+ *
205
+ * @param coreType Core type index (0-2)
206
+ * @return Human-readable name, or "Unknown" if out of range
207
+ */
208
+ const char* getCoreTypeName(int coreType) noexcept {
209
+ switch (coreType) {
210
+ case 0: return "Base";
211
+ case 1: return "Hypersphere";
212
+ case 2: return "Hypertetrahedron";
213
+ default: return "Unknown";
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Get a full descriptive name for a geometry index.
219
+ *
220
+ * Combines core type and base geometry names, e.g.
221
+ * "Hypersphere Torus" for index 11.
222
+ *
223
+ * @param geometryIndex Combined index (0-23)
224
+ * @param buffer Output buffer (must be at least 64 chars)
225
+ * @param bufferSize Size of the output buffer
226
+ * @return Number of characters written (excluding null terminator)
227
+ */
228
+ int getGeometryName(int geometryIndex, char* buffer, int bufferSize) noexcept {
229
+ if (!buffer || bufferSize <= 0) return 0;
230
+
231
+ int coreType = 0;
232
+ int baseGeometry = 0;
233
+ decodeGeometryIndex(geometryIndex, coreType, baseGeometry);
234
+
235
+ const char* coreName = getCoreTypeName(coreType);
236
+ const char* baseName = getBaseGeometryName(baseGeometry);
237
+
238
+ int written = 0;
239
+
240
+ if (coreType == 0) {
241
+ // Base type: just use geometry name
242
+ for (int i = 0; baseName[i] != '\0' && written < bufferSize - 1; ++i) {
243
+ buffer[written++] = baseName[i];
244
+ }
245
+ } else {
246
+ // Compound name: "CoreType BaseGeometry"
247
+ for (int i = 0; coreName[i] != '\0' && written < bufferSize - 1; ++i) {
248
+ buffer[written++] = coreName[i];
249
+ }
250
+ if (written < bufferSize - 1) {
251
+ buffer[written++] = ' ';
252
+ }
253
+ for (int i = 0; baseName[i] != '\0' && written < bufferSize - 1; ++i) {
254
+ buffer[written++] = baseName[i];
255
+ }
256
+ }
257
+
258
+ buffer[written] = '\0';
259
+ return written;
260
+ }
261
+
262
+ } // namespace vib3
@@ -0,0 +1,71 @@
1
+ /**
2
+ * KleinBottle.cpp - Non-Orientable Surface in 4D
3
+ *
4
+ * Generates points on the Klein bottle immersed in R4.
5
+ *
6
+ * The Klein bottle cannot be embedded in R3 without self-intersection,
7
+ * but it can be properly embedded in R4. We use the standard
8
+ * figure-eight parametrization lifted into the 4th dimension:
9
+ *
10
+ * x = (a + b*cos(v)) * cos(u)
11
+ * y = (a + b*cos(v)) * sin(u)
12
+ * z = b * sin(v) * cos(u/2)
13
+ * w = b * sin(v) * sin(u/2)
14
+ *
15
+ * where u in [0, 2*pi), v in [0, 2*pi), and a > b > 0.
16
+ */
17
+
18
+ #include "math/Vec4.hpp"
19
+ #include <vector>
20
+ #include <cmath>
21
+ #include <numbers>
22
+
23
+ namespace vib3 {
24
+
25
+ /**
26
+ * Generate Klein bottle surface points in 4D.
27
+ *
28
+ * Uses the figure-eight immersion lifted to R4, which avoids
29
+ * the self-intersection that occurs in R3.
30
+ *
31
+ * @param resolution Number of subdivisions for each parameter (total points = resolution^2)
32
+ * @return Vector of 4D points on the Klein bottle surface
33
+ */
34
+ std::vector<Vec4> generateKleinBottle(int resolution) noexcept {
35
+ if (resolution < 4) resolution = 4;
36
+
37
+ constexpr float twoPi = 2.0f * std::numbers::pi_v<float>;
38
+ constexpr float a = 2.0f; // Major radius
39
+ constexpr float b = 1.0f; // Minor radius
40
+
41
+ std::vector<Vec4> vertices;
42
+ vertices.reserve(static_cast<size_t>(resolution) * static_cast<size_t>(resolution));
43
+
44
+ for (int iu = 0; iu < resolution; ++iu) {
45
+ float u = twoPi * static_cast<float>(iu) / static_cast<float>(resolution);
46
+ float cosU = std::cos(u);
47
+ float sinU = std::sin(u);
48
+ float halfU = u * 0.5f;
49
+ float cosHalfU = std::cos(halfU);
50
+ float sinHalfU = std::sin(halfU);
51
+
52
+ for (int iv = 0; iv < resolution; ++iv) {
53
+ float v = twoPi * static_cast<float>(iv) / static_cast<float>(resolution);
54
+ float cosV = std::cos(v);
55
+ float sinV = std::sin(v);
56
+
57
+ float r = a + b * cosV;
58
+
59
+ vertices.emplace_back(
60
+ r * cosU,
61
+ r * sinU,
62
+ b * sinV * cosHalfU,
63
+ b * sinV * sinHalfU
64
+ );
65
+ }
66
+ }
67
+
68
+ return vertices;
69
+ }
70
+
71
+ } // namespace vib3
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Sphere.cpp - 3-Sphere (S3) Surface Points
3
+ *
4
+ * Generates points on the 3-sphere (hypersphere) in 4D using
5
+ * Hopf coordinates (psi, theta, phi) parametrization.
6
+ */
7
+
8
+ #include "math/Vec4.hpp"
9
+ #include <vector>
10
+ #include <cmath>
11
+ #include <numbers>
12
+
13
+ namespace vib3 {
14
+
15
+ /**
16
+ * Generate points on S3 using Hopf coordinate parametrization.
17
+ *
18
+ * The 3-sphere is parametrized by three angles:
19
+ * x = cos(psi) * cos(theta)
20
+ * y = cos(psi) * sin(theta)
21
+ * z = sin(psi) * cos(phi)
22
+ * w = sin(psi) * sin(phi)
23
+ *
24
+ * where psi in [0, pi/2], theta in [0, 2pi), phi in [0, 2pi).
25
+ *
26
+ * @param resolution Controls sampling density. Total points = resolution^2 * resolution/2
27
+ * @return Vector of 4D points on the unit 3-sphere
28
+ */
29
+ std::vector<Vec4> generateSphere(int resolution) noexcept {
30
+ if (resolution < 4) resolution = 4;
31
+
32
+ constexpr float pi = std::numbers::pi_v<float>;
33
+ constexpr float twoPi = 2.0f * std::numbers::pi_v<float>;
34
+ constexpr float halfPi = std::numbers::pi_v<float> / 2.0f;
35
+
36
+ // Number of steps for each angle
37
+ int psiSteps = resolution / 2;
38
+ int thetaSteps = resolution;
39
+ int phiSteps = resolution;
40
+
41
+ if (psiSteps < 2) psiSteps = 2;
42
+
43
+ std::vector<Vec4> vertices;
44
+ vertices.reserve(static_cast<size_t>(psiSteps) *
45
+ static_cast<size_t>(thetaSteps) *
46
+ static_cast<size_t>(phiSteps));
47
+
48
+ for (int ip = 0; ip < psiSteps; ++ip) {
49
+ float psi = halfPi * static_cast<float>(ip) / static_cast<float>(psiSteps - 1);
50
+ float cosPsi = std::cos(psi);
51
+ float sinPsi = std::sin(psi);
52
+
53
+ for (int it = 0; it < thetaSteps; ++it) {
54
+ float theta = twoPi * static_cast<float>(it) / static_cast<float>(thetaSteps);
55
+ float cosTheta = std::cos(theta);
56
+ float sinTheta = std::sin(theta);
57
+
58
+ for (int iphi = 0; iphi < phiSteps; ++iphi) {
59
+ float phi = twoPi * static_cast<float>(iphi) / static_cast<float>(phiSteps);
60
+ float cosPhi = std::cos(phi);
61
+ float sinPhi = std::sin(phi);
62
+
63
+ vertices.emplace_back(
64
+ cosPsi * cosTheta,
65
+ cosPsi * sinTheta,
66
+ sinPsi * cosPhi,
67
+ sinPsi * sinPhi
68
+ );
69
+ }
70
+ }
71
+ }
72
+
73
+ return vertices;
74
+ }
75
+
76
+ /**
77
+ * Generate points on S3 using the Hopf fibration structure.
78
+ *
79
+ * The Hopf fibration maps S3 -> S2, with each fiber being a great circle.
80
+ * This produces points organized along Hopf fibers, useful for
81
+ * visualizing the fibration structure.
82
+ *
83
+ * @param numFibers Number of base points on S2
84
+ * @param pointsPerFiber Number of points along each Hopf circle
85
+ * @return Vector of 4D points on the unit 3-sphere
86
+ */
87
+ std::vector<Vec4> generateHopfFibration(int numFibers, int pointsPerFiber) noexcept {
88
+ if (numFibers < 4) numFibers = 4;
89
+ if (pointsPerFiber < 8) pointsPerFiber = 8;
90
+
91
+ constexpr float pi = std::numbers::pi_v<float>;
92
+ constexpr float twoPi = 2.0f * std::numbers::pi_v<float>;
93
+
94
+ // Distribute base points on S2 using a spiral
95
+ int sqrtFibers = static_cast<int>(std::sqrt(static_cast<float>(numFibers)));
96
+ if (sqrtFibers < 2) sqrtFibers = 2;
97
+
98
+ std::vector<Vec4> vertices;
99
+ vertices.reserve(static_cast<size_t>(numFibers) * static_cast<size_t>(pointsPerFiber));
100
+
101
+ for (int fi = 0; fi < sqrtFibers; ++fi) {
102
+ float baseTheta = pi * static_cast<float>(fi) / static_cast<float>(sqrtFibers - 1);
103
+
104
+ for (int fj = 0; fj < sqrtFibers; ++fj) {
105
+ float basePhi = twoPi * static_cast<float>(fj) / static_cast<float>(sqrtFibers);
106
+
107
+ // Base point on S2
108
+ float halfTheta = baseTheta * 0.5f;
109
+ float cosHalf = std::cos(halfTheta);
110
+ float sinHalf = std::sin(halfTheta);
111
+
112
+ // Trace the Hopf fiber (great circle in S3) for this base point
113
+ for (int p = 0; p < pointsPerFiber; ++p) {
114
+ float t = twoPi * static_cast<float>(p) / static_cast<float>(pointsPerFiber);
115
+
116
+ float cosT = std::cos(t);
117
+ float sinT = std::sin(t);
118
+ float cosBP = std::cos(basePhi + t);
119
+ float sinBP = std::sin(basePhi + t);
120
+
121
+ vertices.emplace_back(
122
+ cosHalf * cosT,
123
+ cosHalf * sinT,
124
+ sinHalf * cosBP,
125
+ sinHalf * sinBP
126
+ );
127
+ }
128
+ }
129
+ }
130
+
131
+ return vertices;
132
+ }
133
+
134
+ } // namespace vib3