From 52b4e0b3294e276dc8800bcfb2548430c55f3f56 Mon Sep 17 00:00:00 2001
From: Leni Aniva <v@leni.sh>
Date: Tue, 3 Jun 2025 18:50:39 -0700
Subject: [PATCH] Add ears to the pipe joint

---
 nhf/touhou/yasaka_kanako/shimenawa.py | 36 ++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/nhf/touhou/yasaka_kanako/shimenawa.py b/nhf/touhou/yasaka_kanako/shimenawa.py
index 813316e..5b457c3 100644
--- a/nhf/touhou/yasaka_kanako/shimenawa.py
+++ b/nhf/touhou/yasaka_kanako/shimenawa.py
@@ -9,6 +9,14 @@ import math
 from dataclasses import dataclass, field
 import cadquery as Cq
 
+NUT_COMMON = HexNut(
+    # FIXME: weigh
+    mass=0.0,
+    diam_thread=6.0,
+    pitch=1.0,
+    thickness=5.0,
+    width=9.89,
+)
 BOLT_COMMON = FlatHeadBolt(
     # FIXME: weigh
     mass=0.0,
@@ -35,7 +43,7 @@ class Shimenawa(Model):
     pipe_fitting_angle_span: float = 6.0
 
     pipe_joint_length: float = 120.0
-    pipe_joint_outer_thickness: float = 8.0
+    pipe_joint_outer_thickness: float = 5.0
     pipe_joint_inner_thickness: float = 4.0
 
     pipe_joint_inner_angle_span: float = 120.0
@@ -44,7 +52,7 @@ class Shimenawa(Model):
 
     ear_dr: float = 6.0
     ear_hole_diam: float = 10.0
-    ear_radius: float = 12.0
+    ear_radius: float = 15.0
     ear_thickness: float = 10.0
 
     main_circumference: float = 3600.0
@@ -81,12 +89,16 @@ class Shimenawa(Model):
         ear_outer = Cq.Solid.makeCylinder(
             radius=self.ear_radius,
             height=self.ear_thickness,
+            pnt=(0,-self.ear_thickness/2,0),
+            dir=(0,1,0),
         )
         ear_hole = Cq.Solid.makeCylinder(
             radius=self.ear_hole_diam/2,
             height=self.ear_thickness,
+            pnt=(-self.ear_dr,-self.ear_thickness/2,0),
+            dir=(0,1,0),
         )
-        ear = (ear_outer - ear_hole).moved(self.main_radius - r_minor - self.ear_dr, 0, 0)
+        ear = (ear_outer - ear_hole).moved(self.main_radius - r_minor, 0, 0)
         result += ear - inner
         return result
     @target(name="pipe-joint-outer")
@@ -130,7 +142,18 @@ class Shimenawa(Model):
             - cut_hole.moved(0, 0, z)
             - cut_interior
         )
-        return result
+        ear_outer = Cq.Solid.makeCylinder(
+            radius=self.ear_radius,
+            height=self.ear_thickness,
+            pnt=(0, r1, -self.ear_thickness/2),
+        )
+        ear_hole = Cq.Solid.makeCylinder(
+            radius=self.ear_hole_diam/2,
+            height=self.ear_thickness,
+            pnt=(0,r1+self.ear_dr,-self.ear_thickness/2),
+        )
+        ear = ear_outer - ear_hole - cut_interior
+        return result + ear
 
     @target(name="pipe-joint-inner")
     def pipe_joint_inner(self) -> Cq.Workplane:
@@ -184,12 +207,17 @@ class Shimenawa(Model):
             dir=(r1, 0, 0),
         )
         z = self.hole_z
+        # avoid collisions
+        nut_x = r3 - self.hole_ext - NUT_COMMON.thickness
+        nut = NUT_COMMON.generate().val().rotate((0,0,0),(0,1,0),90)
         result = (
             result
             + add_hole.moved(0, 0, z)
             + add_hole.moved(0, 0, -z)
             - cut_hole.moved(0, 0, z)
             - cut_hole.moved(0, 0, -z)
+            - nut.moved(nut_x, 0, z)
+            - nut.moved(nut_x, 0, -z)
         )
         return result
     @assembly()