SOURCE / PINNED RELEASE
Made of little things.
Body Journal
- Release
- e8049f8da4e2…
- Author-recorded commit
- 61c04bf0e8aa…
- License
- LICENSE
- Author’s source reference
- nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-6c4554844c7
Archive hash verified: 4369d778da046a8b…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
function asset(file){const raw=readFileSync(file),start=12+raw.readUInt32LE(8);return {raw,start,...JSON.parse(raw.subarray(12,start))};}
const a=asset('assets/anatomy/muscles.bin'),fixtures=JSON.parse(readFileSync('tests/fixtures/anatomy-fit.json'));
const array=(a,p,key,type,n)=>new type(a.raw.buffer,a.raw.byteOffset+a.start+p[key],n);
for(const p of a.parts.filter(p=>fixtures[p.id]))test(`${p.label}: fitting does not spike or fold the source surface`,()=>{
const src=fixtures[p.id].positions,pos=array(a,p,'positions',Float32Array,p.vertices*3),idx=array(a,p,'indices',Uint16Array,p.triangles*3),ratios=[];
for(let t=0;t<idx.length;t+=3)for(const [u,v] of [[0,1],[1,2],[0,2]]){
const i=idx[t+u]*3,j=idx[t+v]*3,dist=x=>Math.hypot(x[i]-x[j],x[i+1]-x[j+1],x[i+2]-x[j+2]);
if(dist(src)>.0001)ratios.push(dist(pos)/dist(src));
}
assert.ok(Math.max(...ratios)<3,`Worst edge stretch ${Math.max(...ratios).toFixed(2)}x`);
const ix=array(a,p,'skinIndices',Uint16Array,p.vertices*4),w=array(a,p,'skinWeights',Float32Array,p.vertices*4);
assert.ok(ix.every((b,i)=>!w[i]||b<5||b>42), 'Abdominal/hip/thigh surfaces must not follow the arms');
});
const sk=asset('assets/skeleton/skeleton.bin');
for(const side of ['Left','Right'])test(`${side} palm retains separated metacarpal bases`,()=>{
const roots=[];
for(const digit of ['second','third','fourth','fifth']){
const p=sk.parts.find(p=>p.label===`${side} ${digit} metacarpal bone`),pos=array(sk,p,'positions',Float32Array,p.vertices*3);
// All four are children of the same hand bone. Their proximal 20% must
// describe a palm arch, not four shafts collapsed into one wrist point.
const maxY=Math.max(...Array.from({length:p.vertices},(_,i)=>pos[i*3+1])),minY=Math.min(...Array.from({length:p.vertices},(_,i)=>pos[i*3+1]));
const points=Array.from({length:p.vertices},(_,i)=>Array.from(pos.slice(i*3,i*3+3))).filter(v=>v[1]>maxY-(maxY-minY)*.2);
roots.push(points.reduce((s,v)=>s.map((n,k)=>n+v[k]/points.length),[0,0,0]));
}
const span=Math.hypot(...roots[0].map((v,k)=>v-roots[3][k]));
assert.ok(span>.018,`Index-to-little metacarpal base span is ${(span*1000).toFixed(1)} mm`);
});
const skin=asset('assets/skin/body-skin.bin'),headInfo=skin.arrays.heads4,heads=new Float32Array(skin.raw.buffer,skin.raw.byteOffset+skin.start+headInfo.offset,headInfo.length);
for(const side of ['Left','Right'])test(`${side} distal radius meets the wrist's carpal plane`,()=>{
const points=p=>{const pos=array(sk,p,'positions',Float32Array,p.vertices*3);return Array.from({length:p.vertices},(_,i)=>[0,1,2].map(k=>pos[i*3+k]+heads[p.bone*3+k]));};
const radius=points(sk.parts.find(p=>p.label===`${side} radius`));
const carpals=sk.parts.filter(p=>p.label.startsWith(side+' ')&&/scaphoid|lunate/.test(p.label)).flatMap(points);
let distance=Infinity;for(const a of radius)for(const b of carpals)distance=Math.min(distance,Math.hypot(...a.map((v,k)=>v-b[k])));
assert.ok(distance<.006,`Wrist gap is ${(distance*1000).toFixed(1)} mm`);
});
