Skip to content

Agent skill for creative 3D visualization: turn an idea into a Three.js/Blender scene worth exploring. Claude Code + Codex plugin, 223 recipes, 440 knowledge records, 22 proved kits, 37 runnable studies.

1.9 KB
Raw Blame
import test from 'node:test';import assert from 'node:assert/strict';
import {svdMatrix,svdPoint,mul3,fourierValue,phasorChain,mobius,mobiusNormal,torus,trefoil,sphereFromComplex,complexFromSphere,reciprocal,covariance,cholesky,gaussianSamples,sampleCovariance} from './math-models.js';
const near=(a,b,e=1e-8)=>assert.ok(Math.abs(a-b)<e,`${a} != ${b}`);const vec=(a,b,e)=>a.forEach((x,i)=>near(x,b[i],e));
test('SVD staged transform equals U Sigma Vt and rank drop is exact',()=>{const p=[.3,-.7,.9],s=[2,1,0];vec(svdPoint(p,3,s),mul3(svdMatrix(s),p));const nullVector=[Math.sin(-.5),0,Math.cos(-.5)];near(svdPoint(nullVector,3,s).reduce((q,x)=>q+x*x,0),0);});
test('finite odd Fourier chain matches sum and square-wave symmetries',()=>{for(const t of [.2,1.1]){near(phasorChain(8,t).at(-1)[1],fourierValue(8,t));near(fourierValue(8,t+Math.PI),-fourierValue(8,t));}near(fourierValue(9,0),0);});
test('Mobius seam identifies opposite width and reverses frame orientation',()=>{vec(mobius(0,.3),mobius(2*Math.PI,-.3),1e-6);const n0=mobiusNormal(0,.3),n1=mobiusNormal(2*Math.PI,-.3);near(Math.abs(n0.reduce((s,x,i)=>s+x*n1[i],0)),1,1e-5);vec(torus(0,.7),torus(2*Math.PI,.7),1e-8);vec(trefoil(0),trefoil(2*Math.PI),1e-8);});
test('stereographic projection round trips and reciprocal handles pole',()=>{for(const z of [[.3,-.8],[2,1]]){const q=complexFromSphere(sphereFromComplex(...z));vec([q.x,q.y],z);}assert.equal(reciprocal(0,0).infinity,true);const a=reciprocal(.4,-.7),b=reciprocal(a.x,a.y);vec([b.x,b.y],[.4,-.7]);near(sphereFromComplex(1,0)[2],0);});
test('seeded Gaussian is reproducible and approaches declared covariance',()=>{const a=gaussianSamples(40000,17,1.2,.8,.5,.35),b=gaussianSamples(3,17,1.2,.8,.5,.35);assert.deepEqual(a.slice(0,3),b);const s=sampleCovariance(a),c=covariance(1.2,.8,.5,.35);for(let i=0;i<3;i++)for(let j=0;j<3;j++)near(s[i][j],c[i][j],.025);const L=cholesky(1.2,.8,.5,.35);near(L[1][0]**2+L[1][1]**2,.8**2);});