main
John Lauer Save native two-sided contact artwork and recorded GLB material correction; qualification remains open 57e2489
import json,math
s=json.load(open('design/silkscreen-review/bottom-candidates.json'));l=json.load(open('design/silkscreen-review/bottom-layout.json'));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])
for g in s['labels']:
 if g['id'] not in l['unresolved']:continue
 feasible=[];physical=[]
 if g['id']=='J6':
  import copy
  c=copy.deepcopy(g['candidates'][0]);c['position'][0]-=.6;c['box'][0]-=.6;c['box'][2]-=.6
  for b in c['boxes']:b[0]-=.6;b[2]-=.6
  for child in c['children']:child['x']-=.6;child['box'][0]-=.6;child['box'][2]-=.6
  g['candidates'].append(c)
 for c in g['candidates']:
  hits=[o['id'] for o in s['obstacles'] if any(overlap(b,o['box']) for b in c['boxes'])]
  if hits:
   if len(g['candidates'])==1:print(g['id'],'physicalhits',hits)
   continue
  physical.append(c)
  hits=[h['id'] for h in l['placements'] if not h.get('unresolved') and any(overlap(b,z) for b in c['boxes'] for z in h['boxes'])]
  if not hits:feasible.append(c)
 feasible.sort(key=lambda c:math.dist(c['position'],g['anchor']))
 print(g['id'],'physicalclear',len(physical),'fullclear',len(feasible),'best',feasible[0]['position'] if feasible else None)
 if feasible:
  row=dict(feasible[0],id=g['id']);l['placements']=[row if c['id']==g['id'] else c for c in l['placements']];l['unresolved'].remove(g['id'])
json.dump(l,open('design/silkscreen-review/bottom-layout-completion-candidate.json','w'),indent=2)

assert not l['unresolved'],l['unresolved']
l['method']+='; complete-set collision-checked insertion of candidates omitted by the bounded MILP subset'
json.dump(l,open('design/silkscreen-review/bottom-layout.json','w'),indent=2)