main
John Lauer Board34 R10 nominal cooling and probe-clearance verification; refreshed prototype assets and native export checks 5460526
"""Local R10 CAD audit. Regenerate separately, preserving the reviewed GLB."""
from pathlib import Path
import runpy,sys,json,hashlib,contextlib,io
import cadquery as cq
R=Path(__file__).resolve().parents[1];sys.path.insert(0,str(R/'tools'))
source=R/'tools/build_passive_r10_candidate.py';O=R/'mechanical/passive-side-fan-r10'
sys.argv=[str(source),'--board-glb','probing-flow/design-candidate/sidefan-r23-finished.glb','--board','probing-flow/design-candidate/sidefan-dft-r23.kicad_pcb','--out','mechanical/passive-side-fan-r10-audit','--rear-sink-support','--clear-board34-bodies']
with contextlib.redirect_stdout(io.StringIO()):g=runpy.run_path(str(source))
parts=g['parts'];hits=[];checked=0
for i,(an,a,ak) in enumerate(parts):
 if ak!='fastener':continue
 for j,(bn,b,bk) in enumerate(parts):
  if i==j or (bk=='fastener' and j<i) or bk not in ['fastener','structure','heatsink','interface']:continue
  checked+=1;v=a.intersect(b).Volume()
  if v>1e-5:hits.append({'a':an,'b':bn,'intersectionMm3':v})
audit=json.loads((R/'mechanical/side-fan-r5/board34-body-audit.json').read_text());body=[]
assert audit['boardSha256']==hashlib.sha256((R/'aiflow/run/board-34.kicad_pcb').read_bytes()).hexdigest()
for n,s,k in parts:
 a=s.BoundingBox();a=[a.xmin,a.ymin,a.zmin,a.xmax,a.ymax,a.zmax]
 for row in audit['rows']:
  if row['ref']=='Q1' or (row['ref']=='J9' and n.startswith('Fan.HarwinMate')):continue
  b=row['boundsMm'];b=[b[0]-100,100-b[4],b[2]+5.6,b[3]-100,100-b[1],b[5]+5.6]
  if not all(min(a[i+3],b[i+3])-max(a[i],b[i])>.001 for i in range(3)):continue
  q=cq.Workplane('XY').box(*[b[i+3]-b[i] for i in range(3)],centered=(False,False,False)).translate(tuple(b[:3])).val()
  v=s.intersect(q).Volume()
  if v>1e-5:body.append({'part':n,'reference':row['ref'],'intersectionMm3':v})
# Check every support against the heatsink, in addition to fastener pairs.
sink=next(s for n,s,k in parts if k=='heatsink');support=[]
for n,s,k in parts:
 if k=='structure':
  v=s.intersect(sink).Volume()
  if v>1e-5:support.append({'part':n,'intersectionMm3':v})
hashfile=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
report={'status':'nominal-local-study','fastenerPairsChecked':checked,'fastenerIntersections':hits,'unexpectedBodyIntersections':body,'supportSinkIntersections':support,'carrierSolidCount':len(g['carrier'].Solids()),'carrierValid':g['carrier'].isValid(),'generatorSha256':hashfile(source),'boardSha256':hashfile(R/'aiflow/run/board-34.kicad_pcb'),'assemblySha256':hashfile(O/'side-fan-assembly.glb'),'limits':'No tolerance, preload, machining or thermal qualification; Q1 interface remains nominal; supplier CAD derivative stays local.'}
(O/'geometry-audit.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report,indent=2));raise SystemExit(bool(hits or body or support))