main
John Lauer Astra ESC routing: independent planner, exact replay and narration handoff 2cc6a9e 23d ago
from planner import *
import planner as m
st=json.load(open('evidence/state-first.json'))
for s in st['segments']:m.copper.append(dict(net=s['net_name'],zs=[0 if s['layer']=='F.Cu' else 1],g=LineString([(s['start']['x'],s['start']['y']),(s['end']['x'],s['end']['y'])]).buffer(s['width']/2)))
for v in st['vias']:m.copper.append(dict(net=v['net_name'],zs=[0,1],g=Point(v['position']['x'],v['position']['y']).buffer(v['size']/2)))
plans=[]
for net in ['+VBAT','GND_OUT','/DRV_SHA','/DRV_SHB','/DRV_SHC']:
 a=masks(net,1.0);paths=[];ids=[]
 for s in st['segments']:
  if s['net_name']!=net:continue
  p=(s['start']['x'],s['start']['y']);q=(s['end']['x'],s['end']['y']);length=math.dist(p,q)
  if length<.6:continue
  z=0 if s['layer']=='F.Cu' else 1;ok=True
  for t in np.linspace(0,1,math.ceil(length/.025)+1):
   i,j=ij(p[0]+t*(q[0]-p[0]),p[1]+t*(q[1]-p[1]))
   if a[z,j,i]:ok=False;break
  if ok:paths.append([dict(x=p[0],y=p[1],layer=s['layer']),list(q)]);ids.append(s['uuid'])
 plans.append(dict(net=net,width=1.0,paths=paths,replaceIds=ids));print(net,len(paths),flush=True)
Path('widen-plan.json').write_text(json.dumps(plans,indent=2))