seveibar/pd-dual-stepper-controller

Bottom-side PCB silkscreen artwork consisting of embedded mirrored TS Circuit SVG logos, with via-clearance-aware lower-board placement.

Version
0.1.0
License
unset
Stars
0

scripts/snap-fixed-route-vertices.py

"""Restore exact source coordinates after Specctra's 0.1 µm quantization.

Only vertices within 0.2 µm of an authoritative port, via or manual-path vertex
are snapped. Rebuild and run clearance checks afterward.
"""
import json,math,sys
from pathlib import Path
p=Path(sys.argv[1]);plan=json.loads(p.read_text());base=json.load(open('dist/dual/capture.json'));fixed=[]
for e in base:
 if e['type'] in ('pcb_port','pcb_via'):fixed.append((e['x'],e['y']))
 elif e['type']=='pcb_trace':fixed.extend((q['x'],q['y']) for q in e['route'] if 'x' in q)
fixed=list(dict.fromkeys(fixed));count=0
for t in plan['traces']:
 for q in t['route']:
  points=[q] if 'x' in q else [q['start'],q['end']] if q['route_type']=='through_pad' else []
  for a in points:
   hits=[(math.hypot(a['x']-x,a['y']-y),x,y) for x,y in fixed if abs(a['x']-x)<.0002 and abs(a['y']-y)<.0002]
   if hits:
    d,x,y=min(hits)
    if 0<d<.0002:a.update(x=x,y=y);count+=1
p.write_text(json.dumps(plan,indent=2)+'\n');print('Restored',count,'quantized source vertices')