From e17a01bc0d50364f204edb3231b860bf15393208 Mon Sep 17 00:00:00 2001
From: s3lph <s3lph@kabelsalat.ch>
Date: Mon, 31 Mar 2025 00:03:48 +0200
Subject: [PATCH] fix: lots of tolerance issues

---
 case.scad       |  2 +-
 key_dial.scad   |  2 +-
 lockpuzzle.scad |  6 +++---
 plug.scad       |  2 +-
 ring.scad       | 18 ++++++++----------
 5 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/case.scad b/case.scad
index 4d9aefa..3a97d0c 100644
--- a/case.scad
+++ b/case.scad
@@ -19,7 +19,7 @@ module case(n=5, diameter=50, tolerance=0.2, $fn=60) {
               rotate([0,0,120*j]) {
                 for (i = [0:n]) {  
                   translate([0,diameter/4,10*i+3]) {
-                    cube([5, diameter/2, 3], center=true);
+                    cube([4+2*tolerance, diameter/2, 2+2*tolerance], center=true);
                   }
                 }
               }
diff --git a/key_dial.scad b/key_dial.scad
index 7ca8937..2259a5c 100644
--- a/key_dial.scad
+++ b/key_dial.scad
@@ -11,7 +11,7 @@ module key_dial(alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ", key="C", width=7, dia=50,
       }
       // inner ring
       rotate([0,90,0]) {
-        cylinder($fn=$fn, h=width+2, d=dia-thick*2, center=true);
+        cylinder($fn=$fn, h=width+2, d=dia-thick*2+2*tolerance, center=true);
       }
       // key
       rotate([45+((0.5+key_index)/len(alphabet)) * 360,0,0]) {
diff --git a/lockpuzzle.scad b/lockpuzzle.scad
index 2ee5afe..7a367d2 100644
--- a/lockpuzzle.scad
+++ b/lockpuzzle.scad
@@ -13,7 +13,7 @@ module lock(alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ", password="CHAOS", diameter=50
   for (i = [0:n-1]) {
     rotate([-key_indices[i]/len(alphabet)*360,0,0]) {
       translate([i*10,0,0]) {
-        key_dial(alphabet, key=password[i], dia=diameter);
+        key_dial(alphabet, key=password[i], dia=diameter, font_size=7);
       }
     }
   }
@@ -22,13 +22,13 @@ module lock(alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ", password="CHAOS", diameter=50
     translate([-5+10*i,0,0]) {
       rotate([0,0,180]) {
         rotate([0,90,0]) {
-          ring(dia=diameter-2, clicker=i>0);
+          ring(dia=diameter-2, clicker=i>0, alphabet_length=len(alphabet));
         }
       }
     }
   }
 
-  
+
   rotate([45,0,0]) {
     case(n, diameter=diameter);
     plug(n, diameter=diameter);
diff --git a/plug.scad b/plug.scad
index a40f0ef..99cb09a 100644
--- a/plug.scad
+++ b/plug.scad
@@ -17,7 +17,7 @@ module plug(n=5, diameter=50, tolerance=0.2, $fn=60) {
       rotate([0,90,0]) {
         // inner cylinder
         difference() {
-          cylinder(h=10*n+5, d=diameter-18);
+          cylinder(h=10*n+5, d=diameter-17-2*tolerance);
           translate([0,0,-1]) {
             cylinder(h=10*n+7, d=diameter-20);
           }
diff --git a/ring.scad b/ring.scad
index 2c36cd8..34d73d1 100644
--- a/ring.scad
+++ b/ring.scad
@@ -1,6 +1,6 @@
 
 
-module ring(alphabet_length=26, dia=48, width=3, thick=2, spoke_depth=4.5, spoke_width=7, key_depth=3, key_length=4, tolerance = 0.2, indicator=false, clicker=false, $fn=60) {
+module ring(alphabet_length=26, dia=48, width=3, thick=2, spoke_depth=4.5, spoke_width=9, key_depth=3, key_length=4, tolerance = 0.2, indicator=false, clicker=false, $fn=60) {
   
   difference() {  // halfing
     union() {
@@ -23,7 +23,7 @@ module ring(alphabet_length=26, dia=48, width=3, thick=2, spoke_depth=4.5, spoke
             }
           }
         }
-        cylinder(d=dia-2*spoke_depth+2*tolerance, h=width+1, center=true);
+        cylinder(d=dia-2*spoke_depth+tolerance, h=width+1, center=true);
       }
       // keys
       for (i = [0:2]) {
@@ -35,10 +35,11 @@ module ring(alphabet_length=26, dia=48, width=3, thick=2, spoke_depth=4.5, spoke
       }
       // indicator
         translate([-dia/2,0,0]) {
-          cube([1.5, width, width-4*tolerance], center=true);
+          cube([2, width, width-4*tolerance], center=true);
         }
       // clicker
       if (clicker) {
+        echo(floor(alphabet_length/3)*360/alphabet_length-45);
         rotate([0,0,floor(alphabet_length/3)*360/alphabet_length-45]) {
           translate([-dia/2+3,0,0]) {
             cube([3, 4, width-4*tolerance], center=true);
@@ -54,14 +55,11 @@ module ring(alphabet_length=26, dia=48, width=3, thick=2, spoke_depth=4.5, spoke
       }
     }
     // Ring cut
-    translate([-dia/2+thick-0.5, -0.25, -width/2]) {
-      cube([spoke_depth+key_depth,0.5, width]);
+    translate([-dia/2-0.2, -0.25, -width/2]) {
+      cube([spoke_depth+key_depth+thick,0.25, width]);
     }
-    translate([-dia/2, width/2, -width/2]) {
-      cube([thick,0.5, width]);
-    }
-    translate([-dia/2+thick-0.5, 0, -width/2]) {
-      cube([0.5, width/2, width]);
+    translate([-dia/2-0.2, 0, -width/2]) {
+      #cube([0.25, width/2, width]);
     }
   }
 }