From d8ab964341f3ba988a31ab5b7acf85b7ff4131b7 Mon Sep 17 00:00:00 2001 From: Eric Van Albert Date: Sun, 18 Jun 2017 03:12:07 -0400 Subject: [PATCH] add incomplete schlage primus, and string split function --- Makefile | 1 + scad/keygen.scad | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 3ed30cf..05064db 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ JSON_DIR = build SVG_SRC = $(wildcard $(SVG_DIR)/*.svg) SCAD_SRC = $(SCAD_DIR)/schlage_classic.scad \ $(SCAD_DIR)/kwikset.scad \ + $(SCAD_DIR)/best.scad \ # Generated polygon files POLY_OBJ = $(patsubst $(SVG_DIR)/%.svg,$(POLY_DIR)/%.gen.scad,$(SVG_SRC)) diff --git a/scad/keygen.scad b/scad/keygen.scad index 1f2fce3..26697b0 100644 --- a/scad/keygen.scad +++ b/scad/keygen.scad @@ -135,7 +135,7 @@ module key_blank(outline_points, } } -function key_code_to_heights(code, depth_table) = [for(i=key_enum(code)) depth_table[search(code[i], "0123456789")[0]]]; +function key_code_to_heights(code, depth_table) = [for(i=_enum(code)) depth_table[search(code[i], "0123456789")[0]]]; module key_bitting_cutter(flat, angle, tool_height) { polygon([[-0.5 * flat, 0], @@ -155,7 +155,7 @@ module key_bitting(heights, // Union together a handful of trapezoids // that comprise the cuts union() { - for(i=key_enum(heights)) { + for(i=_enum(heights)) { // Move to the proper location and height translate([locations[i], heights[i]]) linear_extrude(height=cutter_width, center=true) @@ -166,4 +166,16 @@ module key_bitting(heights, function key_lkup(ks, vs, k) = vs[search([k], [for(ki=ks) [ki]])[0]]; -function key_enum(l) = len(l) > 0 ? [for(i=[0:len(l)-1]) i] : []; \ No newline at end of file +function _enum(l) = len(l) > 0 ? [for(i=[0:len(l)-1]) i] : []; + +function _strcat(v, i, car, s) = (i==s ? v[i] : str(_strcat(v, i-1, car, s), str(car,v[i]) )); // from https://www.thingiverse.com/thing:202724 + +function _strslice(l, start, stop) = + stop > start + ? _strcat([for(i=[start:stop]) l[i]], stop-start, "", 0) + : ""; + +function key_split_on_dash(s) = [ + for(i=[0:len(search("-", s, 0)[0])]) + _strslice(s, search("-", str("-", s), 0)[0][i], search("-", str(s, "-"), 0)[0][i]-1) +];