main
John Lauer Publish 0.1.26 0b71841
import importlib.util
from pathlib import Path
from shapely.geometry import shape,box
sp=importlib.util.spec_from_file_location('mask',Path(__file__).with_name('silkscreen-kicad-mask.py'));m=importlib.util.module_from_spec(sp);sp.loader.exec_module(m)
# ESC regression: rotated MOSFET drain mask extends far beyond the 1 mm anchor.
s='''(kicad_pcb (setup (pad_to_mask_clearance 0.09))
(footprint X (at 154 107 180) (property "Reference" "Q1")
(pad "5" smd custom (at 1.05 0 180) (size 1 1) (layers "F.Cu" "F.Mask")
(options (anchor rect)) (primitives (gr_poly (pts (xy -2.375 -2.305) (xy 2.375 -2.305) (xy 2.375 2.305) (xy -2.375 2.305)) (width 0) (fill yes))))))'''
o=m.obstacles(m.parse(s));assert len(o)==1;g=shape(o[0]['polygon']);assert g.intersects(box(149.928,106.387,150.788,107.613));assert abs(g.bounds[0]-150.485)<1e-6
# Global mask margin is applied exactly once; footprint rotation transforms position.
s='''(kicad_pcb (setup (pad_to_mask_clearance 0.09)) (footprint X (at 127.7 85.2 90) (property "Reference" "C6") (pad "1" smd roundrect (at -0.48 0 90) (size 0.56 0.62) (roundrect_rratio 0.25) (layers "F.Cu" "F.Mask"))))'''
g=shape(m.obstacles(m.parse(s))[0]['polygon']);assert all(abs(a-b)<1e-6 for a,b in zip(g.bounds,[127.3,85.31,128.1,86.05]))
# An unknown primitive must not silently fall back to the anchor rectangle.
try:m.primitive(['gr_unknown'])
except ValueError:pass
else:raise AssertionError('unsupported geometry accepted')
print('PASS: complete custom mask, rotated coordinates, margin once, unsupported geometry refused')