main
John Lauer Save native two-sided contact artwork and recorded GLB material correction; qualification remains open 57e2489
#!/usr/bin/env python3
"""Resolve one known cross-component association against the full proposal."""
import json,math,hashlib
from pathlib import Path
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());gap=s['clearance']
def overlap(a,b):return not(a[2]+gap<=b[0] or b[2]+gap<=a[0] or a[3]+gap<=b[1] or b[3]+gap<=a[1])
g=next(g for g in s['labels'] if g['id']=='R9');target=[120.6,75.2,121,75.6];options=[]
for c in g['candidates']:
 if any(overlap(b,o['box']) for b in c['boxes'] for o in s['obstacles']):continue
 if any(overlap(b,target) for b in c['boxes']):continue
 if any(overlap(b,z) for b in c['boxes'] for h in l['placements'] if h['id']!='R9' for z in h['boxes']):continue
 options.append(c)
print('R9 alternatives preserving R10 endpoint:',len(options))
assert options,'Expand local association candidates before changing the board'
c=min(options,key=lambda c:math.dist(c['position'],g['anchor']));l['placements']=[dict(c,id='R9') if h['id']=='R9' else h for h in l['placements']];(P/'bottom-layout.json').write_text(json.dumps(l,indent=2)+'\n')
t=json.loads((P/'bottom-association-targets.json').read_text());t.append(dict(reference='R10',point=[120.8,75.4],bodyProjection=[120.55,74.92,121.05,75.92],reason='Keep R9 text clear of R10 projected body'));(P/'bottom-association-targets.json').write_text(json.dumps(t,indent=2)+'\n');s['obstacles'].append(dict(id='target:R10',reference='R10',kind='association-target',layer='B.SilkS',box=target));(P/'bottom-candidates.json').write_text(json.dumps(s)+'\n');print('R9 moved to',c['position'])