"""Filleted yoke: bold round on the free arm (R_ARM, default 4mm) + gentle round everywhere else (R_REST,
default 0.8mm). Clamp faces + bolt holes/bores untouched (fit preserved). Matches the CURRENT yoke_exact.stl
arm length automatically. Usage: yoke_fillet.py [R_arm] [R_rest]. NOTE: current canonical link_len = 5mm."""
import sys, trimesh
from build123d import export_stl, fillet, GeomType, Axis
from yoke_exact import make_yoke_exact
cur = trimesh.load("yoke_exact.stl", force="mesh")
link_len = round(-48.0 - float(cur.bounds[0][0]))
R_ARM = float(sys.argv[1]) if len(sys.argv) > 1 else 4.0
R_REST = float(sys.argv[2]) if len(sys.argv) > 2 else 0.8
y = make_yoke_exact(link_len)
arm = y.edges().filter_by(Axis.X).filter_by_position(Axis.X, -1e4, -48.5)
y = fillet(arm, R_ARM)
try:
    y = fillet(y.edges().filter_by(GeomType.LINE), R_REST); which = "arm+rest"
except Exception as e:
    which = "arm-only (rest failed: %s)" % str(e)[:40]
export_stl(y, "yoke_fillet.stl", tolerance=0.1, ascii_format=False)
print(f"yoke_fillet link_len={link_len} R_arm={R_ARM} R_rest={R_REST} [{which}] OK")
