discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] Some useful functions (maybe?)

A
adrian
Sun, Jan 25, 2015 8:52 AM

Sorry, but I had changed the name of the functions mid-stream and forgot to
update them all.  The actual functions with matching comments are:
// FUNCTION: is_string(x)//  Returns true if x is a string, false
otherwise.function is_string(x) = x == undef || len(x) == undef ? false //
if undef, a boolean or a number : len(str(x,x)) == len(x)*2; // if an
array, this is false// FUNCTION: is_array(x)//  Returns true if x is an
array, false otherwise.function is_array(x) = is_string(x) ? false : len(x)
!= undef;// FUNCTION: is_bool(x)//  Returns true if x is a boolean, false
otherwise.function is_bool(x) = is_string(x) ? false : str(x) == "true" ||
str(x) == "false";// FUNCTION: is_number(x)//  Returns true if x is a
number, false otherwise.function is_number(x) = x != undef && len(x) ==
undef && !is_bool(x);// FUNCTION: dim(x)//  Returns the number of
dimensions  that x has.  If scalar (number, boolean//  or string), it has 0
dimentions. Will search down 0th element in array //  till no more arrays
are found.function dim_impl(v,d=0) = is_string(v) ? d : is_array(v) ?
dim_impl(v[0],d+1) : d;function dim(v) = dim_impl(v);
Sorry for the inconvenience.
A

--
View this message in context: http://forum.openscad.org/Some-useful-functions-maybe-tp11198p11225.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Sorry, but I had changed the name of the functions mid-stream and forgot to update them all. The actual functions with matching comments are: // FUNCTION: is_string(x)// Returns true if x is a string, false otherwise.function is_string(x) = x == undef || len(x) == undef ? false // if undef, a boolean or a number : len(str(x,x)) == len(x)*2; // if an array, this is false// FUNCTION: is_array(x)// Returns true if x is an array, false otherwise.function is_array(x) = is_string(x) ? false : len(x) != undef;// FUNCTION: is_bool(x)// Returns true if x is a boolean, false otherwise.function is_bool(x) = is_string(x) ? false : str(x) == "true" || str(x) == "false";// FUNCTION: is_number(x)// Returns true if x is a number, false otherwise.function is_number(x) = x != undef && len(x) == undef && !is_bool(x);// FUNCTION: dim(x)// Returns the number of dimensions that x has. If scalar (number, boolean// or string), it has 0 dimentions. Will search down 0th element in array // till no more arrays are found.function dim_impl(v,d=0) = is_string(v) ? d : is_array(v) ? dim_impl(v[0],d+1) : d;function dim(v) = dim_impl(v); Sorry for the inconvenience. A -- View this message in context: http://forum.openscad.org/Some-useful-functions-maybe-tp11198p11225.html Sent from the OpenSCAD mailing list archive at Nabble.com.