main
John Lauer
Verified thermal vias with ground continuity; device protocol and host interoperability tests; no thermal or fabricatio…
8082416
"""Propose vias inside actual two-face LOAD_POS fill, excluding pads/drills.
Candidate only; native refill/DRC and ground connectivity acceptance required.
"""
from pathlib import Path
import sys,json,math
from shapely.geometry import Polygon,Point,box
from shapely.ops import unary_union,polylabel
from shapely.affinity import rotate,translate
import sexp
p=Path(__file__).resolve().parents[1];b=sexp.parse((p/'kicad/adom-custom-electronic-load.kicad_pcb').read_text());polys={'F.Cu':[],'B.Cu':[]}
for z in sexp.find(b,'zone'):
if sexp.first(z,'net')[-1]!='LOAD_POS':continue
for f in sexp.find(z,'filled_polygon'):
polys[sexp.first(f,'layer')[-1]].append(Polygon([tuple(map(float,t[1:]))for t in sexp.first(f,'pts')[1:]]).buffer(0))
area=unary_union(polys['F.Cu']).intersection(unary_union(polys['B.Cu'])).buffer(-.31).intersection(Point(110.6,91).buffer(3))
for fp in sexp.find(b,'footprint'):
at=sexp.first(fp,'at');x,y=map(float,at[1:3]);rot=float(at[3])if len(at)>3 else 0
for pad in sexp.find(fp,'pad'):
a=sexp.first(pad,'at');px,py=map(float,a[1:3]);sz=sexp.first(pad,'size');sx,sy=map(float,sz[1:3]);angle=(float(a[3])if len(a)>3 else rot)-rot
g=rotate(box(-sx/2,-sy/2,sx/2,sy/2),-angle,origin=(0,0));g=translate(g,px,py);g=rotate(g,-rot,origin=(0,0));g=translate(g,x,y);area=area.difference(g.buffer(.5))
for v in sexp.find(b,'via'):
x,y=map(float,sexp.first(v,'at')[1:3]);dr=float(sexp.first(v,'drill')[1]);area=area.difference(Point(x,y).buffer(dr/2+.15+.4))
selected=[]
for _ in range(6):
shapes=list(area.geoms)if hasattr(area,'geoms')else[area];shapes=[g for g in shapes if g.geom_type=='Polygon'and g.area>.005]
if not shapes:break
pts=[polylabel(g,tolerance=.01)for g in shapes];i=max(range(len(pts)),key=lambda i:pts[i].distance(shapes[i].boundary));pt=pts[i];selected.append([round(pt.x,3),round(pt.y,3)]);area=area.difference(pt.buffer(.75))
r={'net':'LOAD_POS','viaSize':.6,'viaDrill':.3,'points':selected,'candidateOnly':True,'method':'Native filled two-face overlap; conservative pad bounds; 0.4 mm nominal hole gap; within 3 mm of D1 LOAD_POS pad center'};(p/'checkpoints/thermal-r13/diode-via-candidates.json').write_text(json.dumps(r,indent=2));print(json.dumps(r))