From 97a6e11667b82d47ff6b45c71e9f2a895c72e1c0 Mon Sep 17 00:00:00 2001
From: Adrian Schlatter <10478149+adrianschlatter@users.noreply.github.com>
Date: Thu, 10 Oct 2019 17:55:45 +0200
Subject: [PATCH] PCF-33P-1 thread +++++++++++++++++

Added external PCF-33P-1 thread based on proposal by dholth in #24 but

- changed order of points in profile
- flipped so that load-side of thread is on top
- changed pitch from 6.35 mm to 3.18 mm

Added internal PCF-33P-1 thread to sensibly match external thread
(spec defines only external thread, not internal thread).

Added unit tests checking slopes on load and non-load sides.
---
 Makefile              |  1 +
 THREAD_TABLE.scad     |  2 ++
 design/PCF_thread.awk |  4 ++++
 design/PCF_thread.csv |  3 +++
 tests/test_table.awk  | 40 ++++++++++++++++++++++++++++++++--------
 threadlib.scad        |  2 +-
 6 files changed, 43 insertions(+), 9 deletions(-)
 create mode 100644 design/PCF_thread.awk
 create mode 100644 design/PCF_thread.csv

diff --git a/Makefile b/Makefile
index 1b892b3..654692c 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ design: clean
 	cat design/BSPP_thread.csv | awk -f design/BSPP_thread.awk >> design/THREAD_TABLE.csv
 	cat design/metric_thread.csv | awk -f design/metric_thread.awk >> design/THREAD_TABLE.csv
 	cat design/PCO_thread.csv | awk -f design/PCO_thread.awk >> design/THREAD_TABLE.csv
+	cat design/PCF_thread.csv | awk -f design/PCF_thread.awk >> design/THREAD_TABLE.csv
 	cat design/THREAD_TABLE.csv | awk -f design/autogenerate.awk > THREAD_TABLE.scad
 
 .PHONY: test
diff --git a/THREAD_TABLE.scad b/THREAD_TABLE.scad
index f61ffa2..69ebf59 100644
--- a/THREAD_TABLE.scad
+++ b/THREAD_TABLE.scad
@@ -1045,4 +1045,6 @@ THREAD_TABLE = [["G1/16-ext", [0.907, 3.1631, 6.3625, [[0, -0.4252], [0, 0.4252]
 ["M600x6-int", [6, -300.6700, 600.6700, [[0, 2.9434], [0, -2.9434], [3.7150, -0.7985], [3.7150, 0.7985]]]],
 ["PCO-1881-ext", [2.7, 11.52381, 24.2, [[0, -0.987894698], [0, 0.987894698], [2.17619, 0.604173686], [2.17619, -0.195826314]]]],
 ["PCO-1881-int", [2.7, -14.406, 27.66, [[0, 1.212894698], [0, -0.762894698], [1.656, -0.470897218], [1.656, 0.610159990]]]],
+["PCF-33P-1-ext", [3.18, 14.74, 29.49, [[0, -0.76], [0, 0.76], [1.195, 0.549], [1.195, -0.07]]]],
+["PCF-33P-1-int", [3.18, -16.2, 32.2, [[0, 0.6], [0, -1.03], [1.3, -0.8], [1.3, -0.15]]]],
 ];
diff --git a/design/PCF_thread.awk b/design/PCF_thread.awk
new file mode 100644
index 0000000..3536b9d
--- /dev/null
+++ b/design/PCF_thread.awk
@@ -0,0 +1,4 @@
+/^[^#]/ {
+	print $0;
+}
+
diff --git a/design/PCF_thread.csv b/design/PCF_thread.csv
new file mode 100644
index 0000000..7332827
--- /dev/null
+++ b/design/PCF_thread.csv
@@ -0,0 +1,3 @@
+# Designator,Pitch,Rrot,Dsupport,r0,z0,r1,z1,r2,z2,r3,z3
+PCF-33P-1-ext,3.18,14.74,29.49,0,-0.76,0,0.76,1.195,0.549,1.195,-0.07
+PCF-33P-1-int,3.18,-16.2,32.2,0,0.6,0,-1.03,1.3,-0.8,1.3,-0.15
diff --git a/tests/test_table.awk b/tests/test_table.awk
index 3fe3eea..938b099 100644
--- a/tests/test_table.awk
+++ b/tests/test_table.awk
@@ -37,6 +37,7 @@ BEGIN	{
 	pi = atan2(0, -1);
 	deg = pi / 180;
 	dphi = 0.1;
+	dx = 0.001;
 
 	PASS = 1;
 	NR_OF_TESTS = 0;
@@ -60,6 +61,7 @@ BEGIN	{
 		PASS = 0;
 	}
 	NR_OF_TESTS += 2;
+	NR_OF_THREADS += 1;
 }
 
 /"[^,]+-int/ {
@@ -75,6 +77,7 @@ BEGIN	{
 		PASS = 0;
 	}
 	NR_OF_TESTS += 2;
+	NR_OF_THREADS += 1;
 }
 
 /M[0-9.x-]+-ext/ {
@@ -169,15 +172,36 @@ BEGIN	{
 	NR_OF_TESTS += 2;
 }
 
-/[^,]+-(int|ext)/ {
-	# final match-all (designators) rule: test wether all lines have been
-	# tested
-	if (tested == 0) {
-		parse();
-		print designator " FAIL: not tested";
+/PCF.+-ext/ { 
+	# PCF-33P-1 threads have slopes of -80 deg (on the load side) and 60 deg
+	# (on the other side) + horizontal crest / valley
+	parse();
+	m1 = slope(v0, v3) / deg;
+	m2 = slope(v2, v1) / deg;
+	if (m1 > 60 + dphi || m1 < 60 - dphi \
+	    || m2 < -80 - dphi || m2 > -80 + dphi) {
+		print designator " FAIL: " m1 ", " m2 " deg";
 		PASS = 0;
-	};
-	NR_OF_THREADS += 1;
+	}
+	test_horizontal();
+	tested = 1;
+	NR_OF_TESTS += 2;
+}
+
+/PCF.+-int/ { 
+	# PCF-33P-1 threads have slopes of 80 deg (on the load side) and -60 deg
+	# (on the other side) + horizontal crest / valley
+	parse();
+	m1 = slope(v3, v0) / deg;
+	m2 = slope(v1, v2) / deg;
+	if (m1 > -60 + dphi || m1 < -60 - dphi \
+	    || m2 < 80 - dphi || m2 > 80 + dphi) {
+		print designator " FAIL: " m1 ", " m2 " deg";
+		PASS = 0;
+	}
+	test_horizontal();
+	tested = 1;
+	NR_OF_TESTS += 2;
 }
 
 END {
diff --git a/threadlib.scad b/threadlib.scad
index be37935..62924ac 100644
--- a/threadlib.scad
+++ b/threadlib.scad
@@ -9,7 +9,7 @@ Create threads easily.
 :License: 3-Clause BSD. See LICENSE.
 */
 
-function __THREADLIB_VERSION() = 0.2;
+function __THREADLIB_VERSION() = "0.2-inRev";
 
 use <thread_profile.scad>
 include <THREAD_TABLE.scad>