35 include <constants.scad>;
96 function is_defined( v ) = (v == undef) ?
false :
true;
105 function not_defined( v ) = (v == undef) ?
true :
false;
114 function is_empty( v ) = (len(v) == 0);
137 function is_scalar( v ) = (len(v) == undef);
191 : (str(v) ==
"true") ?
true
192 : (str(v) ==
"false") ?
true
263 function is_nan( v ) = ( v != v );
325 : (
first(v) != cv) ?
false
346 : (
first(v) == cv) ?
true
483 : (len(
first(v)) != l) ?
false
511 all_numbers([v1, v2]) ? ( (abs(v1-v2) * pow(10, p)) < 1 )
582 (v2_nd || v2_in) ? -1
595 (v2_nd || v2_in || v2_is) ? -1
598 ((v1 == true) && (v2 == false)) ? -1
599 : ((v1 == false) && (v2 == true)) ? +1
608 (v2_nd || v2_in || v2_is || v2_ib) ? -1
613 l1 = len(
smerge(v1, true)),
614 l2 = len(
smerge(v2, true))
618 : ((l1 == 0) && (l2 == 0)) ? 0
648 rv1 = [for (i=v1) i],
649 rv2 = [for (i=v2) i],
718 : [for (i=[0:1:l-1]) i];
749 : (len(v) == 1) ? str(
first(v))
778 s =
is_defined(i1) ? min(max(i1,0),len(v)-1) : 0,
779 i =
is_defined(i2) ? max(min(i2,len(v)-1),0) : len(v)-1
782 : v[i] +
sum(v, s, i-1);
868 : ((
not_defined(i) && (v[i1] == mv)) || (v[i1][i] == mv)) ?
871 : concat(i1,
find(mv, v, c-1, i, i1+1, i2))
873 :
find(mv, v, c, i, i1+1, i2);
895 len(
find(mv, v, 0, i))
896 : len(
smerge(search(mv, v, 0, i)));
951 ) = (len(v) > i) ? v[i] : d;
1014 : [for (i = [0 : min(n-1, len(v)-1)]) v[i]];
1033 : [for (i = [max(0, len(v)-n) : len(v)-1]) v[i]];
1052 : (n >= len(v)) ? empty_v
1053 : [for (i = [0 : min(len(v)-1, len(v)-1-n)]) v[i]];
1072 : (n >= len(v)) ? empty_v
1073 : [for (i = [max(0, n) : len(v)-1]) v[i]];
1092 :
is_number(i) && ((i<0) || (i>(len(v)-1))) ? undef
1093 :
is_vector(i) && ((min([for (y=i) y])<0) || (max([for (y=i) y])>(len(v)-1))) ? undef
1094 :
is_range(i) && ((min([for (y=i) y])<0) || (max([for (y=i) y])>(len(v)-1))) ? undef
1099 [for (j = [for (k=s) k]) v[j]];
1163 : (i > len(v)-1) ?
last(v)
1200 i =
first(search([mv], v, 1, 0))
1277 l = [for (i = v) len(i)]
1280 : (min(l) == 0) ? empty_v
1283 h = [for (i = v)
first(i)],
1284 t = [for (i = v)
ntail(i)]
1286 (j == true) ? concat([h],
pmerge(t, j))
1287 : concat(h,
pmerge(t, j));
1303 : [for (i = [len(v)-1 : -1 : 0]) v[i]];
1335 mp = v[floor(len(v)/2)],
1337 lt = [for (i = v) if (i < mp) i],
1338 eq = [for (i = v) if (i == mp) i],
1339 gt = [for (i = v) if (i > mp) i]
1342 (r == true) ? concat(
qsort(gt, r), eq,
qsort(lt, r))
1376 mp = v[floor(len(v)/2)],
1397 (r == true) ? concat(
qsort2(gt, d, r, s), eq,
qsort2(lt, d, r, s))
1398 : concat(
qsort2(lt, d, r, s), eq,
qsort2(gt, d, r, s));
1466 :
is_empty(v) ? ((j == true) ? [concat(nv)] : concat(nv))
1473 (j == true) ? (l == true) ? [concat(ce, nv)] : [ce]
1474 : (l == true) ? concat(ce, nv) : ce
1476 : (j == true) ? concat([concat(ce, nv)],
eappend(nv,
ntail(v), r, j, l))
1477 : concat(concat(ce, nv),
eappend(nv,
ntail(v), r, j, l));
1524 ) ? concat(nv) : undef
1525 : ((i<0) || (i>len(v))) ? undef
1531 find(mv, v, 0, si)[mi]
1532 :
smerge(search(mv, v, 0, si), false)[mi]
1536 h = (p>0) ? [for (j = [0 : p-1]) v[j]] : empty_v,
1537 t = (p>len(v)-1) ? empty_v : [for (j = [p : len(v)-1]) v[j]]
1539 all_equal([h, t], empty_v) ? undef : concat(h, nv, t);
1582 :
is_number(i) && ((i<0) || (i>(len(v)-1))) ? undef
1583 :
is_vector(i) && ((min([for (y=i) y])<0) || (max([for (y=i) y])>(len(v)-1))) ? undef
1584 :
is_range(i) && ((min([for (y=i) y])<0) || (max([for (y=i) y])>(len(v)-1))) ? undef
1591 :
smerge(search(mv, v, mc, si), false)
1599 for (j = [0 : len(v)-1])
function defined_or(v, d)
Return a defined or default value.
function pmerge(v, j=true)
Parallel-merge vectors of iterable values.
function qsort(v, r=false)
Sort the numeric or string elements of a vector using quick sort.
function all_scalars(v)
Test if all elements of a value are scalars.
function nlast(v, n=1)
Return a vector containing the last n elements of an iterable value.
function all_strings(v)
Test if all elements of a value are strings.
function all_len(v, l)
Test if all elements of a value have a given length.
function eappend(nv, v, r=true, j=true, l=true)
Append a value to each element of an iterable value.
function almost_equal(v1, v2, p=4)
Test if all elements of two values are approximately equal.
function is_nan(v)
Test if a numerical value is invalid.
function is_decimal(v)
Test if a value is a decimal.
function is_even(v)
Test if a numerical value is even.
function second(v)
Return the second element of an iterable value.
function first(v)
Return the first element of an iterable value.
function is_iterable(v)
Test if a value has multiple parts and is iterable.
function is_integer(v)
Test if a value is an integer.
function sum(v, i1, i2)
Compute the sum of a vector of numbers.
function not_defined(v)
Test if a value is not defined.
function is_empty(v)
Test if an iterable value is empty.
function smerge(v, r=false)
Serial-merge vectors of iterable values.
function unique(v)
Return the unique elements of an iterable value.
function cmvselect(v, mv)
Case-like select a value from a vector of identified options by match-value.
function eselect(v, f=true, l=false, i)
Select an element from each iterable value.
function any_equal(v, cv)
Test if any element of a value equals a comparison value.
function nhead(v, n=1)
Return a vector containing all but the last n elements of an iterable value.
function is_boolean(v)
Test if a value is a boolean constant.
empty_v
A vector with no content (the empty vector).
function is_inf(v)
Test if a numerical value is infinite.
function delete(v, i, mv, mc=1, s=true, si)
Delete elements from an iterable value.
function any_undefined(v)
Test if any element of a value is undefined.
function is_string(v)
Test if a value is a string.
empty_str
A string with no content (the empty string).
function count(mv, v, s=true, i)
Count all occurrences of a match value in an iterable value.
function all_vectors(v)
Test if all elements of a value are vectors.
function reverse(v)
Reverse the elements of an iterable value.
function strip(v, mv=empty_v)
Strip all matching values from an iterable value.
function rselect(v, i)
Select a range of elements from an iterable value.
function edefined_or(v, i, d)
Return a defined vector element or default value.
function is_scalar(v)
Test if a value is a single non-iterable value.
function last(v)
Return the last element of an iterable value.
function is_odd(v)
Test if a numerical value is odd.
function find(mv, v, c=1, i, i1=0, i2)
Find the occurrences of a match value in an iterable value.
function all_defined(v)
Test if no element of a value is undefined.
function all_equal(v, cv)
Test if all elements of a value equal a comparison value.
function is_defined(v)
Test if a value is defined.
function is_vector(v)
Test if a value is a vector.
function consts(l, v)
Create a vector of constant elements.
function insert(nv, v, i=0, mv, mi=0, s=true, si)
Insert a new value into an iterable value.
function compare(v1, v2, s=true)
Compare any two values (may be iterable and/or of different types).
function is_range(v)
Test if a value is a range definition.
number_max
The largest representable number in OpenSCAD scripts.
function nfirst(v, n=1)
Return a vector containing the first n elements of an iterable value.
function exists(mv, v, s=true, i)
Check the existence of a match value in an iterable value.
function qsort2(v, d=0, r=false, s=true)
Hierarchically sort all elements of a vector using quick sort.
function ntail(v, n=1)
Return a vector containing all but the first n elements of an iterable value.
function all_numbers(v)
Test if all elements of a value are numbers.
function is_number(v)
Test if a value is a number.
function ciselect(v, i)
Case-like select a value from a vector of ordered options by index.
function vstr(v)
Convert all vector elements to strings and concatenate.