main
John Lauer
Land verified board 17 current-path review and update fan feedback evidence
a330ddf
"""Compare native saved track/via multisets and per-net/layer filled copper unions.
This does not establish netlist, clearance, thermal or assembly qualification.
"""
import argparse,collections,hashlib,json
from pathlib import Path
import sexp
from shapely.geometry import Polygon
from shapely.ops import unary_union
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('candidate',type=Path);p.add_argument('saved',type=Path)
p.add_argument('--out',type=Path,required=True);a=p.parse_args()
def read(path):
b=sexp.parse(path.read_text());c=[];z=collections.defaultdict(list)
for t in sexp.find(b,'segment'):
ends=sorted(tuple(round(float(v),6)for v in sexp.first(t,k)[1:3])for k in ['start','end'])
c.append(('track',sexp.first(t,'net')[-1],sexp.first(t,'layer')[-1],float(sexp.first(t,'width')[-1]),tuple(ends)))
for v in sexp.find(b,'via'):
c.append(('via',sexp.first(v,'net')[-1],tuple(float(x)for x in sexp.first(v,'at')[1:3]),float(sexp.first(v,'size')[-1]),float(sexp.first(v,'drill')[-1])))
for zone in sexp.find(b,'zone'):
for f in sexp.find(zone,'filled_polygon'):
pts=[tuple(map(float,x[1:3]))for x in sexp.find(sexp.first(f,'pts'),'xy')]
if len(pts)>2:z[(sexp.first(zone,'net')[-1],sexp.first(f,'layer')[-1])].append(Polygon(pts).buffer(0))
return collections.Counter(c),{k:unary_union(v)for k,v in z.items()}
ac,az=read(a.candidate);bc,bz=read(a.saved)
r={'candidateSha256':hashlib.sha256(a.candidate.read_bytes()).hexdigest(),
'savedSha256':hashlib.sha256(a.saved.read_bytes()).hexdigest(),
'copperMultisetEqual':ac==bc,'missing':list((ac-bc).items()),'extra':list((bc-ac).items()),
'zoneSymmetricDifferenceMm2':{str(k):az[k].symmetric_difference(bz[k]).area for k in az if k in bz},
'zoneKeysEqual':set(az)==set(bz)}
a.out.write_text(json.dumps(r,indent=2)+'\n');print(json.dumps(r))
assert r['copperMultisetEqual'] and r['zoneKeysEqual'] and max(r['zoneSymmetricDifferenceMm2'].values(),default=0)<.0001