def __init__(
self,
cap_lid_hole_radius: float,
cap_height: float,
cap_outer_thickness: float,
lid_shoulder: float,
lid_sliders: int,
):
"""
Creates a subtractable piece, creating a hole for sliding lids.
"""
lid_hole = Solid.make_cylinder(cap_lid_hole_radius, cap_height)
shoulder_radius = cap_lid_hole_radius + lid_shoulder
shoulder = (
Location((0, 0, -cap_height + cap_outer_thickness)) *
Solid.make_cylinder(shoulder_radius, cap_height)
) # fmt: off
bottom = Location((0, 0, cap_height)) * Solid.make_cylinder(shoulder_radius, cap_height / 2)
solid = lid_hole + shoulder + bottom
edges = list(filter(lambda e: e.radius == cap_lid_hole_radius, solid.edges().filter_by(GeomType.CIRCLE)))
solid = chamfer(edges, lid_shoulder - 0.01)
lock_entry_a = 360 / lid_sliders / 3
lock_entry_h = lid_shoulder * 1.5 + cap_outer_thickness
lock_entry = Solid.make_cylinder(
radius=cap_lid_hole_radius + lid_shoulder, height=lock_entry_h + lid_shoulder, angle=lock_entry_a
)
slide_h = lid_shoulder * 2
slide = Location((0, 0, lock_entry_h - slide_h / 2)) * Solid.make_cylinder(
radius=cap_lid_hole_radius + lid_shoulder, height=slide_h, angle=lock_entry_a * 2
)
edges = slide.edges().filter_by(GeomType.CIRCLE).sort_by(SortBy.LENGTH)[-1]
slide_chamfer_size = slide_h / 2 - 0.01
slide = chamfer(edges, slide_chamfer_size)
lock = lock_entry + slide
edges = lock.edges().filter_by(GeomType.CIRCLE).sort_by(SortBy.LENGTH)[-1]
lock = chamfer(edges, slide_chamfer_size)
for i in range(lid_sliders):
solid += lock.moved(Rotation(Z=i * 360 / lid_sliders))
super().__init__(part=solid)