"""Auto-converted from polyholes.scad — cadbuildr.foundation port.""" from cadbuildr.foundation import ( Part, Sketch, Point, Square, Rectangle, Circle, RegularPolygon, RectangleRounded, Extrusion, Lathe, Hole, Cylinder, Box, Sphere, Cone, show, ) import math # === SCAD constants reproduced verbatim === def sides(r): return max(round(4 * r), 3) def corrected_radius(r, n): return 0.1 + r / math.cos(math.pi / n) def corrected_diameter(d): n = sides(d / 2) return 0.2 + d / math.cos(math.pi / n) # Default demo: poly_cylinder r=5, h=10 DEMO_R = 5 DEMO_H = 10 class Polyholes(Part): def __init__(self, r=DEMO_R, h=DEMO_H): super().__init__() sketch = self._sketch = Sketch(self.xy()) n = sides(r) cr = corrected_radius(r, n) # polyCylinder: cylinder with corrected radius self._add_cyl(0, 0, 0, cr, h) def _pt(self, x, y): return Point(self._sketch, x, y) def _add_box(self, x, y, z, w, d, h, cut=False): self.add_operation(Box(self._pt(x, y), w, d, h, cut=cut)) def _add_cyl(self, x, y, z, radius, height, cut=False): self.add_operation(Cylinder(self._pt(x, y), radius, height, cut=cut)) def _add_cone(self, x, y, z, r1, r2, height): self.add_operation(Cone(self._pt(x, y), r1, r2, height)) def _add_sphere(self, x, y, z, radius, cut=False): self.add_operation(Sphere(self._pt(x, y), radius, cut=cut)) def _add_extrusion(self, shape, end, start=0, cut=False): self.add_operation(Extrusion(shape, end=end, start=start, cut=cut)) part = Polyholes() show(part)