main
John Lauer Cooling clearance revision: native probe/fan relocation, checked copper cleanup, fitted-body screen and recorded review… 04019ce
"""Compare unique physical copper while reporting coincident duplicate counts."""
import sexp,json,collections
from pathlib import Path
p=Path(__file__).resolve().parents[1]
def items(path):
 b=sexp.parse(path.read_text());out=[]
 for t in sexp.find(b,'segment'):
  pts=sorted(tuple(round(float(n),6)for n in sexp.first(t,k)[1:3])for k in ['start','end']);out.append(('track',sexp.first(t,'net')[-1],sexp.first(t,'layer')[-1],float(sexp.first(t,'width')[-1]),tuple(pts)))
 for v in sexp.find(b,'via'):out.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])))
 return collections.Counter(out)
a=items(p/'checkpoints/cooling-clearance/run-v9/board-routed.kicad_pcb');b=items(p/'checkpoints/cooling-final/adom-custom-electronic-load.kicad_pcb')
report={'uniqueGeometryEqual':set(a)==set(b),'candidateItems':sum(a.values()),'liveItems':sum(b.values()),'candidateUnique':len(a),'liveUnique':len(b),'missingUnique':list(set(a)-set(b)),'extraUnique':list(set(b)-set(a)),'note':'Coincident duplicate segments do not add physical copper. Compare unique net/layer/width/endpoints and via properties; this does not replace native DRC.'}
(p/'design/cooling-live/copper-comparison.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report));raise SystemExit(not report['uniqueGeometryEqual'])