main
John Lauer
Save native two-sided contact artwork and recorded GLB material correction; qualification remains open
57e2489
#!/usr/bin/env python3
"""Build and independently check complete bottom text, tags and association lines."""
import json,hashlib,math
from pathlib import Path
from shapely.geometry import box,LineString,Point
from shapely.ops import unary_union
P=Path(__file__).resolve().parents[1]/'design/silkscreen-review'
s=json.loads((P/'bottom-candidates.json').read_text());l=json.loads((P/'bottom-layout.json').read_text());assert not l['unresolved']
texts=[c for g in l['placements'] for c in g['children']]+json.loads((P/'bottom-identity.json').read_text())['texts']
physical=[(o['id'],box(*o['box'])) for o in s['obstacles'] if o['kind'] not in ['association-target','contact-frame']]
textshapes=[box(*t['box']) for t in texts];findings=[]
for i,(t,b) in enumerate(zip(texts,textshapes)):
if not box(*s['bounds']).covers(b):findings.append(dict(kind='text-outside',text=t['text']))
for name,o in physical:
if b.distance(o)<.119:findings.append(dict(kind='text-physical',text=t['text'],obstacle=name,distance=b.distance(o)))
for j in range(i):
if b.distance(textshapes[j])<.119:findings.append(dict(kind='text-pair',texts=[t['text'],texts[j]['text']],distance=b.distance(textshapes[j])))
obstacles=unary_union([p for _,p in physical]+textshapes);graphics=[];framechecks=[]
for f in json.loads((P/'bottom-contact-tags.json').read_text())['frames']+json.loads((P/'bottom-corner-tags.json').read_text())['frames']:
if f['kind']=='rect':
(x,y),(X,Y)=f['points'];pts=[[x,y],[X,y],[X,Y],[x,Y],[x,y]]
else:pts=f['points']
original=LineString(pts);clipped=original.difference(obstacles.buffer(.121));lines=list(clipped.geoms) if hasattr(clipped,'geoms') else [clipped];kept=sum(a.length for a in lines);ratio=kept/original.length
framechecks.append(dict(reference=f['reference'],retainedFraction=ratio,originalLengthMm=original.length))
if ratio<.7:findings.append(dict(kind='frame-too-broken',reference=f['reference'],retainedFraction=ratio))
area=__import__('shapely.geometry',fromlist=['Polygon']).Polygon(pts)
for o in s['obstacles']:
if o['kind']=='pad-mask-or-hole' and o.get('reference')!=f['reference'] and area.contains(box(*o['box']).representative_point()):findings.append(dict(kind='frame-encloses-other-pad',reference=f['reference'],obstacle=o['id']))
for line in lines:
coords=list(line.coords)
for a,b in zip(coords,coords[1:]):
if math.dist(a,b)>.02:graphics.append(dict(kind='line',layer='B.SilkS',points=[list(a),list(b)],stroke=.12,reference=f['reference'],role='frame'))
leaders=json.loads((P/'bottom-leaders.json').read_text());assert not leaders['unresolved'];assert leaders['layoutSha256']==hashlib.sha256((P/'bottom-layout.json').read_bytes()).hexdigest()
for lead in leaders['leaders']:
# Preserve the audited orthogonal paths here. Rounded alternatives are a separate refinement.
for a,b in zip(lead['points'],lead['points'][1:]):graphics.append(dict(kind='line',layer='B.SilkS',points=[a,b],stroke=.12,reference=lead['reference'],role='leader'))
for g in graphics:
line=LineString(g['points']);distance=line.distance(obstacles)
if distance<.119:findings.append(dict(kind='graphic-obstacle',reference=g['reference'],distance=distance))
result=dict(status='candidate-only',boardSha256=s['boardSha256'],nativeRevision=s['nativeRevision'],texts=texts,graphics=graphics,frameChecks=framechecks,findings=findings,limits=['Native DRC and render review still required.','Association leaders point to projections of front-side components, not exposed bottom pads.'])
(P/'bottom-artwork.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(dict(texts=len(texts),graphics=len(graphics),findings=findings,frames=framechecks),indent=2));raise SystemExit(2 if findings else 0)