gokul/cm4-media-carrier

A tscircuit package created by gokul.

Version
0.1.0
License
unset
Stars
0

tools/pair-audit.py

import json,math,sys
from pathlib import Path
from shapely.geometry import LineString
root=Path(sys.argv[1]);j=json.loads((root/'circuit.json').read_text());sources={e['source_trace_id']:e.get('name','') for e in j if e['type']=='source_trace'}
traces={sources.get(e.get('source_trace_id')):e for e in j if e['type']=='pcb_trace'}
reports=[]
for name in ['HDMI_D2','HDMI_D1','HDMI_D0','HDMI_CLK','USB_DATA']:
 p,n=[traces[name+suffix] for suffix in ['_P','_N']];pp=[(v['x'],v['y']) for v in p['route']];np=[(v['x'],v['y']) for v in n['route']]
 assert len(pp)==len(np)==7
 w=p['route'][0]['width'];gaps=[LineString(pp[i:i+2]).distance(LineString(np[i:i+2]))-w for i in [1,2,3]]
 uncoupled=[sum(math.dist(points[i],points[i+1]) for i in [0,4,5]) for points in [pp,np]]
 simple=all(LineString(points).is_simple for points in [pp,np]);passed=simple and all(abs(gap-.1501)<1e-6 for gap in gaps) and max(uncoupled)<2
 reports.append(dict(pair=name,straight_section_edge_gaps_mm=gaps,uncoupled_lengths_mm=uncoupled,self_intersections=not simple,passes=passed))
result=dict(passes=all(r['passes'] for r in reports),pairs=reports,scope='Routed copper geometry; electrical impedance still requires the specified manufacturer stackup.')
(root/'pair-coupling-audit.json').write_text(json.dumps(result,indent=2));print(json.dumps(result,indent=2));assert result['passes']