"""
Servo HOLDER as ONE wrapping shell (build123d) — a rectangular collar around the servo
BODY with printing clearance, open at the ±Y output faces. Boolean: outer box minus
(body + clearance). STEP servo frame; body bbox X[-35.6,9.6] Z[-12.4,12.4], output on ±Y.
The collar lives in the middle-Y region so it never collides with the yoke (which caps the
±Y faces) or the yoke spine (out at x=-44).
"""
from build123d import Box, Pos, export_stl

CLEAR = 0.4     # printing clearance to the body
WALL = 2.6      # shell wall thickness
BX0, BX1 = -35.6, 9.6     # body X extent
BZ0, BZ1 = -12.4, 12.4    # body Z extent
Y0, Y1 = -25.0, 6.0       # collar span along the output axis (clear of the output bosses)


def make_holder_wrap():
    ix0, ix1 = BX0 - CLEAR, BX1 + CLEAR
    iz0, iz1 = BZ0 - CLEAR, BZ1 + CLEAR
    ox0, ox1 = ix0 - WALL, ix1 + WALL
    oz0, oz1 = iz0 - WALL, iz1 + WALL
    outer = Pos((ox0 + ox1) / 2, (Y0 + Y1) / 2, (oz0 + oz1) / 2) * Box(ox1 - ox0, Y1 - Y0, oz1 - oz0)
    inner = Pos((ix0 + ix1) / 2, (Y0 + Y1) / 2, (iz0 + iz1) / 2) * Box(ix1 - ix0, (Y1 - Y0) + 8, iz1 - iz0)
    return outer - inner


if __name__ == "__main__":
    export_stl(make_holder_wrap(), "holder_wrap.stl", tolerance=0.1, ascii_format=False)
    print("holder_wrap ok")
