Eliminating tabs

This commit is contained in:
RonaldoCMP 2020-07-24 13:30:19 +01:00
parent f61e30add2
commit 464c65ce8c
4 changed files with 91 additions and 91 deletions

View file

@ -396,12 +396,12 @@ function deduplicate_indexed(list, indices, closed=false, eps=EPSILON) =
function repeat_entries(list, N, exact = true) = function repeat_entries(list, N, exact = true) =
assert(is_list(list) && len(list)>0, "The list cannot be void.") assert(is_list(list) && len(list)>0, "The list cannot be void.")
assert((is_finite(N) && N>0) || is_vector(N,len(list)), assert((is_finite(N) && N>0) || is_vector(N,len(list)),
"Parameter N must be a number greater than zero or vector with the same length of `list`") "Parameter N must be a number greater than zero or vector with the same length of `list`")
let( let(
length = len(list), length = len(list),
reps_guess = is_list(N)? N : repeat(N/length,length), reps_guess = is_list(N)? N : repeat(N/length,length),
reps = exact ? reps = exact ?
_sum_preserving_round(reps_guess) _sum_preserving_round(reps_guess)
: [for (val=reps_guess) round(val)] : [for (val=reps_guess) round(val)]
) )
[for(i=[0:length-1]) each repeat(list[i],reps[i])]; [for(i=[0:length-1]) each repeat(list[i],reps[i])];
@ -434,20 +434,20 @@ function list_set(list=[],indices,values,dflt=0,minlen=0) =
assert(is_list(list)||is_string(list)) assert(is_list(list)||is_string(list))
!is_list(indices)? ( !is_list(indices)? (
(is_finite(indices) && indices<len(list))? (is_finite(indices) && indices<len(list))?
[for (i=idx(list)) i==indices? values : list[i]] [for (i=idx(list)) i==indices? values : list[i]]
: list_set(list,[indices],[values],dflt) ) : list_set(list,[indices],[values],dflt) )
: assert(is_vector(indices) && is_list(values) && len(values)==len(indices) , : assert(is_vector(indices) && is_list(values) && len(values)==len(indices) ,
"Index list and value list must have the same length") "Index list and value list must have the same length")
let( midx = max(len(list)-1, max(indices)) ) let( midx = max(len(list)-1, max(indices)) )
[ for(i=[0:midx] ) [ for(i=[0:midx] )
let( j = search(i,indices,0), let( j = search(i,indices,0),
k = j[0] ) k = j[0] )
assert( len(j)<2, "Repeated indices are not acceptable." ) assert( len(j)<2, "Repeated indices are not acceptable." )
k!=undef ? values[k] : k!=undef ? values[k] :
i<len(list) ? list[i]: i<len(list) ? list[i]:
dflt , dflt ,
each repeat(dflt, minlen-max(indices)) each repeat(dflt, minlen-max(indices))
]; ];
//*** //***
// a full refactoring without sorting; its is quite faster than the original // a full refactoring without sorting; its is quite faster than the original
@ -464,24 +464,24 @@ function list_set(list=[],indices,values,dflt=0,minlen=0) =
function list_insert(list, indices, values, _i=0) = function list_insert(list, indices, values, _i=0) =
assert(is_list(list)||is_string(list)) assert(is_list(list)||is_string(list))
! is_list(indices)? ! is_list(indices)?
assert( is_finite(indices) && is_finite(values), "Invalid indices/values." ) assert( is_finite(indices) && is_finite(values), "Invalid indices/values." )
assert( indices<=len(list), "Indices must be <= len(list) ." ) assert( indices<=len(list), "Indices must be <= len(list) ." )
[for (i=idx(list)) each ( i==indices? [ values, list[i] ] : [ list[i] ] ) ] [for (i=idx(list)) each ( i==indices? [ values, list[i] ] : [ list[i] ] ) ]
: assert( is_vector(indices) && is_list(values) && len(values)==len(indices) , : assert( is_vector(indices) && is_list(values) && len(values)==len(indices) ,
"Index list and value list must have the same length") "Index list and value list must have the same length")
assert( max(indices)<=len(list), "Indices must be <= len(list) ." ) assert( max(indices)<=len(list), "Indices must be <= len(list) ." )
let( maxidx = max(indices), let( maxidx = max(indices),
minidx = min(indices) ) minidx = min(indices) )
[ for(i=[0:1:minidx-1] ) list[i], [ for(i=[0:1:minidx-1] ) list[i],
for(i=[minidx: min(maxidx, len(list)-1)] ) for(i=[minidx: min(maxidx, len(list)-1)] )
let( j = search(i,indices,0), let( j = search(i,indices,0),
k = j[0], k = j[0],
x = assert( len(j)<2, "Repeated indices are not acceptable." ) x = assert( len(j)<2, "Repeated indices are not acceptable." )
) )
each ( k != undef ? [ values[k], list[i] ] : [ list[i] ] ), each ( k != undef ? [ values[k], list[i] ] : [ list[i] ] ),
for(i=[min(maxidx, len(list)-1)+1:1:len(list)-1] ) list[i], for(i=[min(maxidx, len(list)-1)+1:1:len(list)-1] ) list[i],
if(maxidx==len(list)) values[max_index(indices)] if(maxidx==len(list)) values[max_index(indices)]
]; ];
//*** //***
@ -503,12 +503,12 @@ function list_insert(list, indices, values, _i=0) =
function list_remove(list, indices) = function list_remove(list, indices) =
assert(is_list(list)||is_string(list), "Invalid list/string." ) assert(is_list(list)||is_string(list), "Invalid list/string." )
is_finite(indices) is_finite(indices)
? [ for(i=[0:1:min(indices, len(list)-1)-1]) list[i], ? [ for(i=[0:1:min(indices, len(list)-1)-1]) list[i],
for(i=[min(indices, len(list)-1)+1:1:len(list)-1]) list[i] ] for(i=[min(indices, len(list)-1)+1:1:len(list)-1]) list[i] ]
: assert( is_vector(indices), "Invalid list `indices`." ) : assert( is_vector(indices), "Invalid list `indices`." )
len(indices)==0 ? list : len(indices)==0 ? list :
[ for(i=[0:len(list)-1]) [ for(i=[0:len(list)-1])
if ( []==search(i,indices,1) ) list[i] ]; if ( []==search(i,indices,1) ) list[i] ];
//*** //***
// Refactoring without sort // Refactoring without sort
@ -645,9 +645,9 @@ function list_trim(array, maxlen) =
function list_fit(array, length, fill) = function list_fit(array, length, fill) =
assert(is_list(array)||is_string(list), "Invalid input." ) assert(is_list(array)||is_string(list), "Invalid input." )
let(l=len(array)) let(l=len(array))
l==length ? array : l==length ? array :
l> length ? list_trim(array,length) l> length ? list_trim(array,length)
: list_pad(array,length,fill); : list_pad(array,length,fill);
//*** //***
// formating // formating
@ -665,32 +665,32 @@ function shuffle(list) =
left = [for (i=[0:len(list)-1]) if (rval[i]< 0.5) list[i]], left = [for (i=[0:len(list)-1]) if (rval[i]< 0.5) list[i]],
right = [for (i=[0:len(list)-1]) if (rval[i]>=0.5) list[i]] right = [for (i=[0:len(list)-1]) if (rval[i]>=0.5) list[i]]
) )
concat(shuffle(left), shuffle(right)); concat(shuffle(left), shuffle(right));
// Sort a vector of scalar values // Sort a vector of scalar values
function _sort_scalars(arr) = function _sort_scalars(arr) =
len(arr)<=1 ? arr : len(arr)<=1 ? arr :
let( let(
pivot = arr[floor(len(arr)/2)], pivot = arr[floor(len(arr)/2)],
lesser = [ for (y = arr) if (y < pivot) y ], lesser = [ for (y = arr) if (y < pivot) y ],
equal = [ for (y = arr) if (y == pivot) y ], equal = [ for (y = arr) if (y == pivot) y ],
greater = [ for (y = arr) if (y > pivot) y ] greater = [ for (y = arr) if (y > pivot) y ]
) )
concat( _sort_scalars(lesser), equal, _sort_scalars(greater) ); concat( _sort_scalars(lesser), equal, _sort_scalars(greater) );
// Sort a vector of vectors based on the first entry only of each vector // Sort a vector of vectors based on the first entry only of each vector
function _sort_vectors1(arr) = function _sort_vectors1(arr) =
len(arr)<=1 ? arr : len(arr)<=1 ? arr :
!(len(arr)>0) ? [] : !(len(arr)>0) ? [] :
let( let(
pivot = arr[floor(len(arr)/2)], pivot = arr[floor(len(arr)/2)],
lesser = [ for (y = arr) if (y[0] < pivot[0]) y ], lesser = [ for (y = arr) if (y[0] < pivot[0]) y ],
equal = [ for (y = arr) if (y[0] == pivot[0]) y ], equal = [ for (y = arr) if (y[0] == pivot[0]) y ],
greater = [ for (y = arr) if (y[0] > pivot[0]) y ] greater = [ for (y = arr) if (y[0] > pivot[0]) y ]
) )
concat( _sort_vectors1(lesser), equal, _sort_vectors1(greater) ); concat( _sort_vectors1(lesser), equal, _sort_vectors1(greater) );
// Sort a vector of vectors based on the first two entries of each vector // Sort a vector of vectors based on the first two entries of each vector
@ -698,19 +698,19 @@ function _sort_vectors1(arr) =
function _sort_vectors2(arr) = function _sort_vectors2(arr) =
len(arr)<=1 ? arr : len(arr)<=1 ? arr :
!(len(arr)>0) ? [] : !(len(arr)>0) ? [] :
let( let(
pivot = arr[floor(len(arr)/2)], pivot = arr[floor(len(arr)/2)],
lesser = [ for (y = arr) if (y[0] < pivot[0] || (y[0]==pivot[0] && y[1]<pivot[1])) y ], lesser = [ for (y = arr) if (y[0] < pivot[0] || (y[0]==pivot[0] && y[1]<pivot[1])) y ],
equal = [ for (y = arr) if (y[0] == pivot[0] && y[1]==pivot[1]) y ], equal = [ for (y = arr) if (y[0] == pivot[0] && y[1]==pivot[1]) y ],
greater = [ for (y = arr) if (y[0] > pivot[0] || (y[0]==pivot[0] && y[1]>pivot[1])) y ] greater = [ for (y = arr) if (y[0] > pivot[0] || (y[0]==pivot[0] && y[1]>pivot[1])) y ]
) )
concat( _sort_vectors2(lesser), equal, _sort_vectors2(greater) ); concat( _sort_vectors2(lesser), equal, _sort_vectors2(greater) );
// Sort a vector of vectors based on the first three entries of each vector // Sort a vector of vectors based on the first three entries of each vector
// Lexicographic order, remaining entries of vector ignored // Lexicographic order, remaining entries of vector ignored
function _sort_vectors3(arr) = function _sort_vectors3(arr) =
len(arr)<=1 ? arr : len(arr)<=1 ? arr :
let( let(
pivot = arr[floor(len(arr)/2)], pivot = arr[floor(len(arr)/2)],
lesser = [ lesser = [
for (y = arr) if ( for (y = arr) if (
@ -742,14 +742,14 @@ function _sort_vectors3(arr) =
) y ) y
] ]
) )
concat( _sort_vectors3(lesser), equal, _sort_vectors3(greater) ); concat( _sort_vectors3(lesser), equal, _sort_vectors3(greater) );
// Sort a vector of vectors based on the first four entries of each vector // Sort a vector of vectors based on the first four entries of each vector
// Lexicographic order, remaining entries of vector ignored // Lexicographic order, remaining entries of vector ignored
function _sort_vectors4(arr) = function _sort_vectors4(arr) =
len(arr)<=1 ? arr : len(arr)<=1 ? arr :
let( let(
pivot = arr[floor(len(arr)/2)], pivot = arr[floor(len(arr)/2)],
lesser = [ lesser = [
for (y = arr) if ( for (y = arr) if (
@ -792,7 +792,7 @@ function _sort_vectors4(arr) =
) y ) y
] ]
) )
concat( _sort_vectors4(lesser), equal, _sort_vectors4(greater) ); concat( _sort_vectors4(lesser), equal, _sort_vectors4(greater) );
function _sort_general(arr, idx=undef) = function _sort_general(arr, idx=undef) =
@ -800,10 +800,10 @@ function _sort_general(arr, idx=undef) =
let( let(
pivot = arr[floor(len(arr)/2)], pivot = arr[floor(len(arr)/2)],
pivotval = idx==undef? pivot : [for (i=idx) pivot[i]], pivotval = idx==undef? pivot : [for (i=idx) pivot[i]],
compare = compare =
is_undef(idx) ? [for(entry=arr) compare_vals(entry, pivotval) ] : is_undef(idx) ? [for(entry=arr) compare_vals(entry, pivotval) ] :
[ for (entry = arr) [ for (entry = arr)
let( val = [for (i=idx) entry[i] ] ) let( val = [for (i=idx) entry[i] ] )
compare_vals(val, pivotval) ] , compare_vals(val, pivotval) ] ,
lesser = [ for (i = [0:1:len(arr)-1]) if (compare[i] < 0) arr[i] ], lesser = [ for (i = [0:1:len(arr)-1]) if (compare[i] < 0) arr[i] ],
equal = [ for (i = [0:1:len(arr)-1]) if (compare[i] ==0) arr[i] ], equal = [ for (i = [0:1:len(arr)-1]) if (compare[i] ==0) arr[i] ],
@ -832,19 +832,19 @@ function _sort_general(arr, idx=undef) =
// sorted = sort(l); // Returns [2,3,8,9,12,16,23,34,37,45,89] // sorted = sort(l); // Returns [2,3,8,9,12,16,23,34,37,45,89]
function sort(list, idx=undef) = function sort(list, idx=undef) =
!is_list(list) || len(list)<=1 ? list : !is_list(list) || len(list)<=1 ? list :
assert( is_undef(idx) || is_finite(idx) || is_vector(idx), "Invalid indices.") assert( is_undef(idx) || is_finite(idx) || is_vector(idx), "Invalid indices.")
is_def(idx) ? _sort_general(list,idx) : is_def(idx) ? _sort_general(list,idx) :
let(size = array_dim(list)) let(size = array_dim(list))
len(size)==1 ? _sort_scalars(list) : len(size)==1 ? _sort_scalars(list) :
len(size)==2 && size[1] <=4 len(size)==2 && size[1] <=4
? ( ? (
size[1]==0 ? list : size[1]==0 ? list :
size[1]==1 ? _sort_vectors1(list) : size[1]==1 ? _sort_vectors1(list) :
size[1]==2 ? _sort_vectors2(list) : size[1]==2 ? _sort_vectors2(list) :
size[1]==3 ? _sort_vectors3(list) size[1]==3 ? _sort_vectors3(list)
/*size[1]==4*/ : _sort_vectors4(list) /*size[1]==4*/ : _sort_vectors4(list)
) )
: _sort_general(list); : _sort_general(list);
//*** //***
// Formating and input check // Formating and input check
@ -872,9 +872,9 @@ function sort(list, idx=undef) =
// idxs3 = sortidx(lst, idx=[1,3]); // Returns: [3,0,2,1] // idxs3 = sortidx(lst, idx=[1,3]); // Returns: [3,0,2,1]
function sortidx(list, idx=undef) = function sortidx(list, idx=undef) =
assert( is_list(list) || is_string(list) , "Invalid input." ) assert( is_list(list) || is_string(list) , "Invalid input." )
assert( is_undef(idx) || is_finite(idx) || is_vector(idx), "Invalid indices.") assert( is_undef(idx) || is_finite(idx) || is_vector(idx), "Invalid indices.")
list==[] ? [] : list==[] ? [] :
let( let(
size = array_dim(list), size = array_dim(list),
aug = is_undef(idx) && (len(size) == 1 || (len(size) == 2 && size[1]<=4)) aug = is_undef(idx) && (len(size) == 1 || (len(size) == 2 && size[1]<=4))
? zip(list, list_range(len(list))) ? zip(list, list_range(len(list)))
@ -882,14 +882,14 @@ function sortidx(list, idx=undef) =
) )
is_undef(idx) && len(size) == 1? subindex(_sort_vectors1(aug),1) : is_undef(idx) && len(size) == 1? subindex(_sort_vectors1(aug),1) :
is_undef(idx) && len(size) == 2 && size[1] <=4 is_undef(idx) && len(size) == 2 && size[1] <=4
? ( ? (
size[1]==0 ? list_range(len(arr)) : size[1]==0 ? list_range(len(arr)) :
size[1]==1 ? subindex(_sort_vectors1(aug),1) : size[1]==1 ? subindex(_sort_vectors1(aug),1) :
size[1]==2 ? subindex(_sort_vectors2(aug),2) : size[1]==2 ? subindex(_sort_vectors2(aug),2) :
size[1]==3 ? subindex(_sort_vectors3(aug),3) size[1]==3 ? subindex(_sort_vectors3(aug),3)
/*size[1]==4*/ : subindex(_sort_vectors4(aug),4) /*size[1]==4*/ : subindex(_sort_vectors4(aug),4)
) )
: // general case : // general case
subindex(_sort_general(aug, idx=list_range(s=1,n=len(aug)-1)), 0); subindex(_sort_general(aug, idx=list_range(s=1,n=len(aug)-1)), 0);
//*** //***
@ -906,8 +906,8 @@ function sortidx(list, idx=undef) =
function unique(arr) = function unique(arr) =
assert(is_list(arr)||is_string(arr), "Invalid input." ) assert(is_list(arr)||is_string(arr), "Invalid input." )
len(arr)<=1? arr : len(arr)<=1? arr :
let( sorted = sort(arr)) let( sorted = sort(arr))
[ for (i=[0:1:len(sorted)-1]) [ for (i=[0:1:len(sorted)-1])
if (i==0 || (sorted[i] != sorted[i-1])) if (i==0 || (sorted[i] != sorted[i-1]))
sorted[i] sorted[i]
]; ];
@ -1079,9 +1079,9 @@ function triplet_wrap(v) =
// for (p=permute(regular_ngon(n=7,d=100))) stroke(p); // for (p=permute(regular_ngon(n=7,d=100))) stroke(p);
function permute(l,n=2,_s=0) = function permute(l,n=2,_s=0) =
assert(is_list(l), "Invalid list." ) assert(is_list(l), "Invalid list." )
assert( is_finite(n) && n>=1 && n<=len(l), "Invalid number `n`." ) assert( is_finite(n) && n>=1 && n<=len(l), "Invalid number `n`." )
n==1 n==1
? [for (i=[_s:1:len(l)-1]) [l[i]]] ? [for (i=[_s:1:len(l)-1]) [l[i]]]
: [for (i=[_s:1:len(l)-n], p=permute(l,n=n-1,_s=i+1)) concat([l[i]], p)]; : [for (i=[_s:1:len(l)-n], p=permute(l,n=n-1,_s=i+1)) concat([l[i]], p)];
@ -1108,23 +1108,23 @@ function permute(l,n=2,_s=0) =
// set_v = set_union(set_a, set_b, get_indices=true); // set_v = set_union(set_a, set_b, get_indices=true);
// // set_v now equals [[5,0,1,2,6], [2,3,5,7,11,1,8]] // // set_v now equals [[5,0,1,2,6], [2,3,5,7,11,1,8]]
function set_union(a, b, get_indices=false) = function set_union(a, b, get_indices=false) =
assert( is_list(a) && is_list(b), "Invalid sets." ) assert( is_list(a) && is_list(b), "Invalid sets." )
let( let(
found1 = search(b, a), found1 = search(b, a),
found2 = search(b, b), found2 = search(b, b),
c = [ for (i=idx(b)) c = [ for (i=idx(b))
if (found1[i] == [] && found2[i] == i) if (found1[i] == [] && found2[i] == i)
b[i] b[i]
], ],
nset = concat(a, c) nset = concat(a, c)
) )
! get_indices ? nset : ! get_indices ? nset :
let( let(
la = len(a), la = len(a),
found3 = search(b, c), found3 = search(b, c),
idxs = [ for (i=idx(b)) idxs = [ for (i=idx(b))
(found1[i] != [])? found1[i] : la + found3[i] (found1[i] != [])? found1[i] : la + found3[i]
] ]
) [idxs, nset]; ) [idxs, nset];
//*** //***
@ -1145,7 +1145,7 @@ function set_union(a, b, get_indices=false) =
// set_d = set_difference(set_a, set_b); // set_d = set_difference(set_a, set_b);
// // set_d now equals [7,11] // // set_d now equals [7,11]
function set_difference(a, b) = function set_difference(a, b) =
assert( is_list(a) && is_list(b), "Invalid sets." ) assert( is_list(a) && is_list(b), "Invalid sets." )
let( found = search(a, b, num_returns_per_match=1) ) let( found = search(a, b, num_returns_per_match=1) )
[ for (i=idx(a)) if(found[i]==[]) a[i] ]; [ for (i=idx(a)) if(found[i]==[]) a[i] ];
@ -1166,7 +1166,7 @@ function set_difference(a, b) =
// set_i = set_intersection(set_a, set_b); // set_i = set_intersection(set_a, set_b);
// // set_i now equals [2,3,5] // // set_i now equals [2,3,5]
function set_intersection(a, b) = function set_intersection(a, b) =
assert( is_list(a) && is_list(b), "Invalid sets." ) assert( is_list(a) && is_list(b), "Invalid sets." )
let( found = search(a, b, num_returns_per_match=1) ) let( found = search(a, b, num_returns_per_match=1) )
[ for (i=idx(a)) if(found[i]!=[]) a[i] ]; [ for (i=idx(a)) if(found[i]!=[]) a[i] ];
@ -1209,8 +1209,8 @@ function add_scalar(v,s) =
// subindex(v,[2,1]); // Returns [[3, 2], [7, 6], [11, 10], [15, 14]] // subindex(v,[2,1]); // Returns [[3, 2], [7, 6], [11, 10], [15, 14]]
// subindex(v,[1:3]); // Returns [[2, 3, 4], [6, 7, 8], [10, 11, 12], [14, 15, 16]] // subindex(v,[1:3]); // Returns [[2, 3, 4], [6, 7, 8], [10, 11, 12], [14, 15, 16]]
function subindex(v, idx) = function subindex(v, idx) =
[ for(val=v) [ for(val=v)
let( value=[for(i=idx) val[i]] ) let( value=[for(i=idx) val[i]] )
len(value)==1 ? value[0] : value len(value)==1 ? value[0] : value
]; ];
@ -1249,7 +1249,7 @@ function zip(vecs, v2, v3, fit=false, fill=undef) =
let( let(
minlen = list_shortest(vecs), minlen = list_shortest(vecs),
maxlen = list_longest(vecs) maxlen = list_longest(vecs)
) )
assert(fit!=false || minlen==maxlen, "Input vectors to zip must have the same length") assert(fit!=false || minlen==maxlen, "Input vectors to zip must have the same length")
(fit == "long") (fit == "long")
? [for(i=[0:1:maxlen-1]) [for(v=vecs) for(x=(i<len(v)? v[i] : (fill==undef)? [fill] : fill)) x] ] ? [for(i=[0:1:maxlen-1]) [for(v=vecs) for(x=(i<len(v)? v[i] : (fill==undef)? [fill] : fill)) x] ]
@ -1286,11 +1286,11 @@ function _array_dim_recurse(v) =
!is_list(v[0]) !is_list(v[0])
? sum( [for(entry=v) is_list(entry) ? 1 : 0] ) == 0 ? [] : [undef] ? sum( [for(entry=v) is_list(entry) ? 1 : 0] ) == 0 ? [] : [undef]
: let( : let(
firstlen = len(v[0]), firstlen = len(v[0]),
first = sum( [for(entry = v) len(entry) == firstlen ? 0 : 1] ) == 0 ? firstlen : undef, first = sum( [for(entry = v) len(entry) == firstlen ? 0 : 1] ) == 0 ? firstlen : undef,
leveldown = flatten(v) leveldown = flatten(v)
) )
is_list(leveldown[0]) is_list(leveldown[0])
? concat([first],_array_dim_recurse(leveldown)) ? concat([first],_array_dim_recurse(leveldown))
: [first]; : [first];
@ -1321,7 +1321,7 @@ function array_dim(v, depth=undef) =
(depth == undef) (depth == undef)
? concat([len(v)], _array_dim_recurse(v)) ? concat([len(v)], _array_dim_recurse(v))
: (depth == 0) : (depth == 0)
? len(v) ? len(v)
: let( dimlist = _array_dim_recurse(v)) : let( dimlist = _array_dim_recurse(v))
(depth > len(dimlist))? 0 : dimlist[depth-1] ; (depth > len(dimlist))? 0 : dimlist[depth-1] ;
@ -1362,10 +1362,10 @@ function array_dim(v, depth=undef) =
function transpose(arr) = function transpose(arr) =
let( a0 = arr[0] ) let( a0 = arr[0] )
is_list(a0) is_list(a0)
? assert([for(a=arr) if(len(a)!=len(a0)) 1]==[], "The array is not a matrix." ) ? assert([for(a=arr) if(len(a)!=len(a0)) 1]==[], "The array is not a matrix." )
[for (i=[0:1:len(a0)-1]) [for (i=[0:1:len(a0)-1])
[ for (j=[0:1:len(arr)-1]) arr[j][i] ] ] [ for (j=[0:1:len(arr)-1]) arr[j][i] ] ]
: arr; : arr;
//*** //***
// Input data check and formating // Input data check and formating

View file

@ -320,7 +320,7 @@ function scalar_vec3(v, dflt=undef) =
function segs(r) = function segs(r) =
$fn>0? ($fn>3? $fn : 3) : $fn>0? ($fn>3? $fn : 3) :
let( r = is_finite(r)? r: 0 ) let( r = is_finite(r)? r: 0 )
ceil(max(5, min(360/$fa, abs(r)*2*PI/$fs))) ; ceil(max(5, min(360/$fa, abs(r)*2*PI/$fs))) ;
//*** //***
// avoids undef // avoids undef

View file

@ -217,8 +217,8 @@ function vector_axis(v1,v2=undef,v3=undef) =
w1 = point3d(v1/norm(v1)), w1 = point3d(v1/norm(v1)),
w2 = point3d(v2/norm(v2)), w2 = point3d(v2/norm(v2)),
w3 = (norm(w1-w2) > eps && norm(w1+w2) > eps) ? w2 w3 = (norm(w1-w2) > eps && norm(w1+w2) > eps) ? w2
: (norm(vabs(w2)-UP) > eps)? UP : (norm(vabs(w2)-UP) > eps)? UP
: RIGHT : RIGHT
) unit(cross(w1,w3)); ) unit(cross(w1,w3));