// Independent binary reader: no import of generator, mesh collector or application analyzer. import assert from 'node:assert/strict'; import {readFileSync,writeFileSync} from 'node:fs'; import {createHash} from 'node:crypto'; const p=JSON.parse(readFileSync(new URL('./parameters.json',import.meta.url),'utf8')); const manifest=JSON.parse(readFileSync(new URL('./manifest.json',import.meta.url),'utf8')); const results=[]; const near=(a,b,tolerance=0.00001)=>assert.ok(Math.abs(a-b)<=tolerance,`${a} != ${b}`); for(const item of manifest.files){ const bytes=readFileSync(new URL('./stl/'+item.file,import.meta.url)),n=bytes.readUInt32LE(80),edges=new Map(),vertices=new Map();let volume=0,degenerate=0; assert.equal(bytes.length,84+50*n);assert.equal(createHash('sha256').update(bytes).digest('hex'),item.sha256); const key=v=>v.join(','); for(let face=0;faceArray.from({length:3},(_,j)=>bytes.readFloatLE(84+50*face+12+12*i+4*j))); for(const vertex of v){assert.ok(vertex.every(Number.isFinite));vertices.set(key(vertex),vertex);} const [a,b,c]=v,ux=b[0]-a[0],uy=b[1]-a[1],uz=b[2]-a[2],vx=c[0]-a[0],vy=c[1]-a[1],vz=c[2]-a[2]; const area2=Math.hypot(uy*vz-uz*vy,uz*vx-ux*vz,ux*vy-uy*vx);if(area2<1e-10)degenerate++; volume+=(a[0]*(b[1]*c[2]-b[2]*c[1])-a[1]*(b[0]*c[2]-b[2]*c[0])+a[2]*(b[0]*c[1]-b[1]*c[0]))/6; for(let i=0;i<3;i++){const from=key(v[i]),to=key(v[(i+1)%3]),pair=[from,to].sort(),id=pair.join('|'),edge=edges.get(id)||{count:0,balance:0};edge.count++;edge.balance+=from===pair[0]?1:-1;edges.set(id,edge);} } assert.equal(degenerate,0);assert.ok([...edges.values()].every(e=>e.count===2&&e.balance===0),'Each edge must have two opposite uses'); const all=[...vertices.values()],low=[0,1,2].map(axis=>Math.min(...all.map(v=>v[axis]))),high=[0,1,2].map(axis=>Math.max(...all.map(v=>v[axis]))),size=high.map((value,i)=>value-low[i]); const k=p.segments/2*Math.sin(2*Math.PI/p.segments);let expectedVolume,measuredRadii,minimumApothem; if(item.id==='shaft'){ [p.flangeDiameter,p.flangeDiameter,p.flangeHeight+p.shaftLength].forEach((value,i)=>near(size[i],value)); expectedVolume=k*((p.flangeDiameter/2)**2*p.flangeHeight+(p.shaftDiameter/2)**2*p.shaftLength); measuredRadii=all.filter(v=>v[2]===p.flangeHeight+p.shaftLength&&Math.hypot(v[0],v[1])>0).map(v=>Math.hypot(v[0],v[1])); measuredRadii.forEach(radius=>near(radius,p.shaftDiameter/2)); }else{ [p.couponWidth,p.couponDepth,p.engagementLength].forEach((value,i)=>near(size[i],value)); const radius=item.holeDiameter/2;expectedVolume=(p.couponWidth*p.couponDepth-k*radius**2)*p.engagementLength; const circle=all.filter(v=>v[2]===0&&Math.hypot(v[0],v[1])Math.atan2(a[1],a[0])-Math.atan2(b[1],b[0])); assert.equal(circle.length,p.segments);measuredRadii=circle.map(v=>Math.hypot(v[0],v[1]));measuredRadii.forEach(r=>near(r,radius)); minimumApothem=Math.min(...circle.map((a,i)=>{const b=circle[(i+1)%circle.length];return Math.abs(a[0]*b[1]-a[1]*b[0])/Math.hypot(b[0]-a[0],b[1]-a[1]);})); near(minimumApothem,radius*Math.cos(Math.PI/p.segments)); assert.ok(2*minimumApothem-p.shaftDiameter>item.clearance-0.004); } near(volume,expectedVolume,0.001);assert.ok(volume>0); results.push({file:item.file,triangles:n,bytes:bytes.length,sizeMm:size,closedOppositeEdgeIncidence:true,degenerateTriangles:degenerate,signedVolumeMm3:volume,expectedPolygonVolumeMm3:expectedVolume,radiusRangeMm:[Math.min(...measuredRadii),Math.max(...measuredRadii)],minimumHoleDiameterAcrossFlatsMm:minimumApothem?minimumApothem*2:null}); } const report={version:p.version,scope:'Independent binary coordinates, opposite edge incidence, nondegenerate faces, signed polygon volume, dimensions and hole apothems. No physical print, slicer or general self-intersection certificate.',absoluteCoordinateToleranceMm:0.00001,absoluteVolumeToleranceMm3:0.001,results}; writeFileSync(new URL('./verification.json',import.meta.url),JSON.stringify(report,null,2)+'\n');console.log(JSON.stringify(report,null,2));