main
John Lauer Schematic symbols U1/L1/D1: chip outlines drawn in the standard iso pose (pin 1 toward the viewer) so part numbers read… 11be571
#!/usr/bin/env python3
"""L1 outline: the Abracon STEP prints AMPLH5030S as raised geometry, so its HLR outline draws the
letters as double-line outlines. John's rule is one marking, as flat white text, where the 3D model
has it. So: take the service's plain outline of the Abracon STEP, drop the polylines of the raised
letters (every polyline lying wholly inside the top face, inset), and add the service's flat name
polylines (the extra polylines in the named outline, which lies on the same line and reads the same
way as the printed mark). Pure SVG bookkeeping; all geometry comes from the service.

2026-10-03 (John: the part number reads upright and left to right in the standard iso pose, pin 1 at
the front): the service's /outline camera looks at a KiCad-frame part from the pad-2 / pins-4-to-6 side,
so the STEP is first turned 180 deg about its vertical (Y in the Abracon Y-up frame; rotate_step_xcaf.py)
and the outline drawn with pad 1 toward the camera (L1-t-*). In that pose Abracon's raised print reads
upright, and the service's flat name at rot=270 lies on the same line, reading the same way."""
import re, sys, os
D = os.path.join(os.path.dirname(os.path.abspath(__file__)), "outlines", "L1")
TOP = [(36, 124), (168, 50), (292, 122), (164, 196)]   # top-face corners in the 320 x 320 view


def inside(p, poly, inset):
    # convex polygon, counter/clockwise agnostic: point must be >= inset px from every edge, same side
    sgn = None
    for i in range(len(poly)):
        (x0, y0), (x1, y1) = poly[i], poly[(i + 1) % len(poly)]
        ex, ey = x1 - x0, y1 - y0
        L = (ex * ex + ey * ey) ** 0.5
        d = (ex * (p[1] - y0) - ey * (p[0] - x0)) / L
        s = d > 0
        if sgn is None:
            sgn = s
        if s != sgn or abs(d) < inset:
            return False
    return True


def pts(el):
    return [tuple(map(float, q.split(","))) for q in re.search(r'points="([^"]+)"', el).group(1).split()]


for st in ("dark", "ink-heavy", "teal", "blueprint"):
    plain = open(os.path.join(D, f"L1-t-plain-{st}.svg")).read()
    named = open(os.path.join(D, f"L1-t-named270-{st}-named.svg")).read()
    pl = re.findall(r"<polyline[^>]*/>", plain)
    nl = re.findall(r"<polyline[^>]*/>", named)
    text = [e for e in pl if all(inside(p, TOP, 12) for p in pts(e))]
    flat = [e for e in nl if e not in set(pl)]
    keep = [e for e in pl if e not in set(text)] + flat
    head = plain[:plain.index("<polyline")]
    open(os.path.join(D, f"AMPLH5030S-150MT-3d-outline-{st}-named270.svg"), "w").write(head + "".join(keep) + "</svg>")
    print(st, "plain", len(pl), "raised-letter polylines dropped", len(text), "flat name added", len(flat))