From 6f83b7d5888f4c210cade37f840d73f4a52c956d Mon Sep 17 00:00:00 2001
From: Adrian Mariano <avm4@cornell.edu>
Date: Thu, 25 Aug 2022 22:08:56 -0400
Subject: [PATCH] fix generic torx depths

---
 screw_drive.scad | 62 +++++++++++++++++++++++++-----------------------
 screws.scad      | 13 +++++++---
 2 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/screw_drive.scad b/screw_drive.scad
index f94bf3f..75adfb1 100644
--- a/screw_drive.scad
+++ b/screw_drive.scad
@@ -9,6 +9,8 @@
 //////////////////////////////////////////////////////////////////////
 
 
+include <structs.scad>
+
 // Section: Phillips Drive
 
 // Module: phillips_mask()
@@ -210,38 +212,38 @@ module torx_mask2d(size) {
 // Arguments:
 //   size = Torx size.
 function torx_info(size) =
-    let(
-        info_arr = [
-            //T#     OD     ID     H     Re     Ri
-            [  1, [  0.90,  0.65,  1.19, 0.059, 0.201]],
-            [  2, [  1.00,  0.73,  1.70, 0.069, 0.224]],
-            [  3, [  1.20,  0.87,  1.70, 0.081, 0.266]],
-            [  4, [  1.35,  0.98,  1.70, 0.090, 0.308]],
-            [  5, [  1.48,  1.08,  1.70, 0.109, 0.330]],
-            [  6, [  1.75,  1.27,  1.87, 0.132, 0.383]],
-            [  7, [  2.08,  1.50,  3.10, 0.161, 0.446]],
-            [  8, [  2.40,  1.75,  3.10, 0.190, 0.510]],
-            [  9, [  2.58,  1.87,  3.35, 0.207, 0.554]],
-            [ 10, [  2.80,  2.05,  3.61, 0.229, 0.598]],
-            [ 15, [  3.35,  2.40,  3.86, 0.267, 0.716]],
-            [ 20, [  3.95,  2.85,  4.12, 0.305, 0.859]],
-            [ 25, [  4.50,  3.25,  4.50, 0.375, 0.920]],
-            [ 27, [  5.07,  3.65,  4.75, 0.390, 1.108]],
-            [ 30, [  5.60,  4.05,  5.00, 0.451, 1.194]],
-            [ 40, [  6.75,  4.85,  5.64, 0.546, 1.428]],
-            [ 45, [  7.93,  5.64,  6.27, 0.574, 1.796]],
-            [ 50, [  8.95,  6.45,  6.53, 0.775, 1.816]],
-            [ 55, [ 11.35,  8.05,  6.78, 0.867, 2.667]],
-            [ 60, [ 13.45,  9.60,  8.22, 1.067, 2.883]],
-            [ 70, [ 15.70, 11.20,  9.01, 1.194, 3.477]],
-            [ 80, [ 17.75, 12.80,  9.95, 1.526, 3.627]],
-            [ 90, [ 20.20, 14.40, 10.61, 1.530, 4.468]],
-            [100, [ 22.40, 16.00, 11.40, 1.720, 4.925]],
+    let( f=echo(size=size),
+        info_arr = [      // Depth is from metric socket head screws, ISO 14583
+            //T#     OD     ID     H        Re     Ri
+            [  1, [  0.90,  0.65,  0.40,  0.059, 0.201]],  // depth interpolated
+            [  2, [  1.00,  0.73,  0.44,  0.069, 0.224]],  // depth interpolated
+            [  3, [  1.20,  0.87,  0.53,  0.081, 0.266]],  // depth interpolated
+            [  4, [  1.35,  0.98,  0.59,  0.090, 0.308]],  // depth interpolated
+            [  5, [  1.48,  1.08,  0.65,  0.109, 0.330]],  // depth interpolated
+            [  6, [  1.75,  1.27,  0.775, 0.132, 0.383]],
+            [  7, [  2.08,  1.50,  0.886, 0.161, 0.446]],  // depth interpolated
+            [  8, [  2.40,  1.75,  1.0,   0.190, 0.510]],
+            [  9, [  2.58,  1.87,  1.078, 0.207, 0.554]],  // depth interpolated
+            [ 10, [  2.80,  2.05,  1.142, 0.229, 0.598]],
+            [ 15, [  3.35,  2.40,  1.2,   0.267, 0.716]],  // depth interpolated
+            [ 20, [  3.95,  2.85,  1.4,   0.305, 0.859]],  // depth interpolated
+            [ 25, [  4.50,  3.25,  1.61,  0.375, 0.920]],  
+            [ 27, [  5.07,  3.65,  1.84,  0.390, 1.108]],
+            [ 30, [  5.60,  4.05,  2.22,  0.451, 1.194]],
+            [ 40, [  6.75,  4.85,  2.63,  0.546, 1.428]],
+            [ 45, [  7.93,  5.64,  3.115, 0.574, 1.796]],
+            [ 50, [  8.95,  6.45,  3.82,  0.775, 1.816]],
+            [ 55, [ 11.35,  8.05,  5.015, 0.867, 2.667]],
+            [ 60, [ 13.45,  9.60,  5.805, 1.067, 2.883]],
+            [ 70, [ 15.70, 11.20,  6.815, 1.194, 3.477]],
+            [ 80, [ 17.75, 12.80,  7.75,  1.526, 3.627]],
+            [ 90, [ 20.20, 14.40,  8.945, 1.530, 4.468]],
+            [100, [ 22.40, 16.00, 10.79,  1.720, 4.925]],
         ],
-        found = [for(info=info_arr) if(info[0]==size) info[1]]
+        found = struct_val(info_arr,size)
     )
-    assert(found, "Unsupported Torx size.")
-    found[0];
+    assert(found, str("Unsupported Torx size, ",size))
+    found;
 
 
 // Function: torx_diam()
diff --git a/screws.scad b/screws.scad
index 9d170d6..39bf4a6 100644
--- a/screws.scad
+++ b/screws.scad
@@ -12,9 +12,9 @@
 // FileSummary: ISO (metric) and UTS screws and nuts.
 //////////////////////////////////////////////////////////////////////
 
-include <BOSL2/structs.scad>
-include <BOSL2/threading.scad>
-include <BOSL2/screw_drive.scad>
+include <structs.scad>
+include <threading.scad>
+include <screw_drive.scad>
 
 // Section: Screw Parameters
 //    This modules in this file create standard ISO (metric) and UTS (English) threaded screws.
@@ -1613,5 +1613,12 @@ m4-m6: +0.22
 m8-m12: +0.27
 m14-m20: +0.33
 
+intersection() {
+    cyl(h=2, d=10, anchor=BOT)
+        attach(TOP) cyl(h=5, d=10, anchor=BOT, texture="trunc_ribs", tex_counts=[31,1], tex_scale=-0.2);
+    cyl(h=6,d=10, chamfer2=0.5, anchor=BOT);
+}
+
+
 */