"""Fillet the yoke (build123d): a BOLD round on the arm/link (a free beam) + a gentle round on the rest.
Flat clamp faces + bolt holes/bores stay intact (fit unchanged). -> yoke_fillet.stl"""
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)   # arm long edges (||X)
y = fillet(arm, R_ARM)
try:
    y = fillet(y.edges().filter_by(GeomType.LINE), R_REST)                  # soften the 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")
