"""Isolate the detachable-base pin joint as a small printable FIT-TEST coupon pair:
- pin_test_A.stl = Part A's shelf + 4 pins (cropped from base_holder_detach.stl)
- pin_test_B.stl = Part B's lap plate + clearance holes + step (cropped from fiducial_mount.stl)
They mate exactly like the real parts -> print these first to dial the pin clearance (CLEAR in gen_detach.py)
without printing the full 76cm3 base. Crop window excludes the mount block and the long tray/board."""
import trimesh
def crop(src, out):
    m = trimesh.load(src, force="mesh")
    box = trimesh.creation.box(extents=[80, 24, 27])
    box.apply_translation([40, -22, -34.5])          # x 0..80, y -34..-10, z -48..-21 (servo_0 frame mm)
    c = trimesh.boolean.intersection([m, box], engine="manifold")
    c.export(out)
    print(f"{out}: wt={c.is_watertight} bodies={len(c.split(only_watertight=False))} vol={c.volume/1000:.1f}cm3 bbox={[round(v,1) for v in c.extents]}mm")
    return c
crop("base_holder_detach.stl", "pin_test_A.stl")
crop("fiducial_mount.stl", "pin_test_B.stl")
