main
John Lauer Improve 48 reference labels with preserved copper and native DRC; document saved-file fallback and review clips a4a06ac
#!/usr/bin/env python3
"""Local translation candidates for existing labels; no edits or gate claims."""
import json, math
from pathlib import Path

ROOT=Path(__file__).resolve().parents[1]
OUT=ROOT/'design/silkscreen-review'
geometry=json.loads((OUT/'geometry.json').read_text())
for face in ('F','B'):
    labels=[]
    for mark in geometry['marks']:
        if mark['layer']!=face+'.SilkS': continue
        p=mark['nativeInput']; candidates=[]
        radius=3 if mark['text'] in ('R20','R38','R8') else 2
        for i in range(-int(radius*5),int(radius*5)+1):
            for j in range(-int(radius*5),int(radius*5)+1):
                dx,dy=i*.2,j*.2
                if math.hypot(dx,dy)>radius:continue
                candidates.append(dict(position=[p['x']+dx,p['y']+dy],box=[v+(dx if k%2==0 else dy) for k,v in enumerate(mark['box'])],font=p['height']))
                if mark['text']=='R38' and (OUT/'R38-smaller-native.json').exists():
                    small=json.loads((OUT/'R38-smaller-native.json').read_text())['texts'][0]['box']
                    candidates.append(dict(position=[p['x']+dx,p['y']+dy],box=[v+(dx if k%2==0 else dy) for k,v in enumerate(small)],font=.7))
                if mark['text']=='R38' and (OUT/'R38-vertical-native.json').exists():
                    vertical=json.loads((OUT/'R38-vertical-native.json').read_text())['texts'][0]['box']
                    candidates.append(dict(position=[p['x']+dx,p['y']+dy],box=[v+(dx if k%2==0 else dy) for k,v in enumerate(vertical)],font=.8,rotation=90))
        labels.append(dict(id=mark['id'],text=mark['text'],anchor=[p['x'],p['y']],previous=[p['x'],p['y']],maxDistance=radius,candidates=candidates))
    data=dict(bounds=[98.3,30.3,161.7,101.7],boundsSource='v85 saved outline; rectangular screen excludes rounded-corner proof',labels=labels,obstacles=[o for o in geometry['obstacles'] if o['layer']==face+'.SilkS'],clearance=.12,solver='milp',solverSeconds=45,milpPerFont=64,candidatesPerLabel=2000)
    (OUT/f'candidates-{face}.json').write_text(json.dumps(data)+'\n')
print('Existing-label candidates written; missing passive values and assembled occlusion remain separate.')