From e386ce792748bbc33ff191a41c392009f7a7af01 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Thu, 27 Jun 2019 11:10:37 +0100 Subject: [PATCH] Added more imperial and metric units as requested. --- printed/foot.scad | 1 - readme.md | 8 ++++++-- utils/core/global.scad | 8 +++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/printed/foot.scad b/printed/foot.scad index 2653662..5097f67 100644 --- a/printed/foot.scad +++ b/printed/foot.scad @@ -28,7 +28,6 @@ include <../vitamins/inserts.scad> foot = [25, 12, 3, 2, M4_cap_screw, 10]; insert_foot = [20, 10, 0, 2, M3_cap_screw, 10]; -function foot() = foot; //! Default foot used unless a list of parameters is passed function insert_foot() = insert_foot; //! Default foot with insert function foot_diameter(type = foot) = type[0]; //! Outside maximum diameter diff --git a/readme.md b/readme.md index c672a72..a609a38 100644 --- a/readme.md +++ b/readme.md @@ -3410,7 +3410,6 @@ inserts don't grip well in rubber. ### Functions | Function | Description | |:--- |:--- | -| ```foot()``` | Default foot used unless a list of parameters is passed | | ```insert_foot()``` | Default foot with insert | ### Modules @@ -4220,12 +4219,17 @@ Global constants, functions and modules. This file is used directly or indirectl | Function | Description | |:--- |:--- | | ```Len(x)``` | Returns the length of a list or 0 if ```x``` is not a list | +| ```cm(x)``` | cm to mm conversion | | ```echoit(x)``` | Echo expression and return it, useful for debugging | +| ```foot(x)``` | Foot to mm conversion | | ```in(list, x)``` | Returns true if ```x``` is an element in the ```list``` | -| ```inch(x)``` | Inch to mm conversion | +| ```inch(x)``` | Inch to mm conversion (For fractional inches, 'inch(1 + 7/8)' will work as expected.) | +| ```m(x)``` | m to mm conversion | +| ```mm(x)``` | Explicit mm specified | | ```r2sides(r)``` | Replicates the OpenSCAD logic to calculate the number of sides from the radius | | ```r2sides4n(r)``` | Round up the number of sides to a multiple of 4 to ensure points land on all axes | | ```sqr(x)``` | Returns the square of ```x``` | +| ```yard(x)``` | Yard to mm conversion | ### Modules | Module | Description | diff --git a/utils/core/global.scad b/utils/core/global.scad index 2783c0c..13e3a39 100644 --- a/utils/core/global.scad +++ b/utils/core/global.scad @@ -22,8 +22,14 @@ // include <../../global_defs.scad> +function inch(x) = x * 25.4; //! Inch to mm conversion (For fractional inches, 'inch(1 + 7/8)' will work as expected.) +function foot(x) = x * 25.4 * 12; //! Foot to mm conversion +function yard(x) = x * 25.4 * 12 * 3; //! Yard to mm conversion +function mm(x) = x; //! Explicit mm specified +function cm(x) = x * 10.0; //! cm to mm conversion +function m(x) = x * 1000.0; //! m to mm conversion + function sqr(x) = x * x; //! Returns the square of ```x``` -function inch(x) = x * 25.4; //! Inch to mm conversion function echoit(x) = echo(x) x; //! Echo expression and return it, useful for debugging function in(list, x) = !!len([for(v = list) if(v == x) true]); //! Returns true if ```x``` is an element in the ```list``` function Len(x) = is_list(x) ? len(x) : 0; //! Returns the length of a list or 0 if ```x``` is not a list