mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-31 05:20:35 +02:00
formating
This commit is contained in:
42
arrays.scad
42
arrays.scad
@@ -73,9 +73,6 @@ function select(list, start, end=undef) =
|
||||
: concat([for (i = [s:1:l-1]) list[i]], [for (i = [0:1:e]) list[i]]) ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Function: slice()
|
||||
// Description:
|
||||
// Returns a slice of a list. The first item is index 0.
|
||||
@@ -101,8 +98,6 @@ function slice(list,start,end) =
|
||||
) [for (i=[s:1:e-1]) if (e>s) list[i]];
|
||||
|
||||
|
||||
|
||||
|
||||
// Function: in_list()
|
||||
// Description: Returns true if value `val` is in list `list`. When `val==NAN` the answer will be false for any list.
|
||||
// Arguments:
|
||||
@@ -118,7 +113,6 @@ function in_list(val,list,idx=undef) =
|
||||
s==[] || s[0]==[] ? false
|
||||
: is_undef(idx) ? val==list[s]
|
||||
: val==list[s][idx];
|
||||
|
||||
|
||||
|
||||
// Function: min_index()
|
||||
@@ -209,7 +203,6 @@ function repeat(val, n, i=0) =
|
||||
[for (j=[1:1:n[i]]) repeat(val, n, i+1)];
|
||||
|
||||
|
||||
|
||||
// Function: list_range()
|
||||
// Usage:
|
||||
// list_range(n, [s], [e])
|
||||
@@ -246,8 +239,6 @@ function list_range(n=undef, s=0, e=undef, step=undef) =
|
||||
[for (i=[0:1:n-1]) s+step*i ]
|
||||
: assert( is_vector([s,step,e]), "Start `s`, step `step` and end `e` must be numbers.")
|
||||
[for (v=[s:step:e]) v] ;
|
||||
|
||||
|
||||
|
||||
|
||||
// Section: List Manipulation
|
||||
@@ -315,8 +306,6 @@ function deduplicate(list, closed=false, eps=EPSILON) =
|
||||
: [for (i=[0:1:l-1]) if (i==end || !approx(list[i], list[(i+1)%l], eps)) list[i]];
|
||||
|
||||
|
||||
|
||||
|
||||
// Function: deduplicate_indexed()
|
||||
// Usage:
|
||||
// new_idxs = deduplicate_indexed(list, indices, [closed], [eps]);
|
||||
@@ -351,8 +340,6 @@ function deduplicate_indexed(list, indices, closed=false, eps=EPSILON) =
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
// Function: repeat_entries()
|
||||
// Usage:
|
||||
// newlist = repeat_entries(list, N)
|
||||
@@ -392,8 +379,6 @@ function repeat_entries(list, N, exact = true) =
|
||||
[for(i=[0:length-1]) each repeat(list[i],reps[i])];
|
||||
|
||||
|
||||
|
||||
|
||||
// Function: list_set()
|
||||
// Usage:
|
||||
// list_set(list, indices, values, [dflt], [minlen])
|
||||
@@ -433,7 +418,6 @@ function list_set(list=[],indices,values,dflt=0,minlen=0) =
|
||||
];
|
||||
|
||||
|
||||
|
||||
// Function: list_insert()
|
||||
// Usage:
|
||||
// list_insert(list, indices, values);
|
||||
@@ -465,8 +449,6 @@ function list_insert(list, indices, values, _i=0) =
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
// Function: list_remove()
|
||||
// Usage:
|
||||
// list_remove(list, indices)
|
||||
@@ -489,8 +471,6 @@ function list_remove(list, indices) =
|
||||
if ( []==search(i,indices,1) ) list[i] ];
|
||||
|
||||
|
||||
|
||||
|
||||
// Function: list_remove_values()
|
||||
// Usage:
|
||||
// list_remove_values(list,values,all=false) =
|
||||
@@ -560,8 +540,6 @@ function list_bset(indexset, valuelist, dflt=0) =
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
// Section: List Length Manipulation
|
||||
|
||||
// Function: list_shortest()
|
||||
@@ -574,7 +552,6 @@ function list_shortest(array) =
|
||||
min([for (v = array) len(v)]);
|
||||
|
||||
|
||||
|
||||
// Function: list_longest()
|
||||
// Description:
|
||||
// Returns the length of the longest sublist in a list of lists.
|
||||
@@ -624,7 +601,6 @@ function list_fit(array, length, fill) =
|
||||
: list_pad(array,length,fill);
|
||||
|
||||
|
||||
|
||||
// Section: List Shuffling and Sorting
|
||||
|
||||
// Function: shuffle()
|
||||
@@ -679,6 +655,7 @@ function _sort_vectors2(arr) =
|
||||
)
|
||||
concat( _sort_vectors2(lesser), equal, _sort_vectors2(greater) );
|
||||
|
||||
|
||||
// Sort a vector of vectors based on the first three entries of each vector
|
||||
// Lexicographic order, remaining entries of vector ignored
|
||||
function _sort_vectors3(arr) =
|
||||
@@ -756,6 +733,7 @@ function _sort_general(arr, idx=undef) =
|
||||
)
|
||||
concat(_sort_general(lesser,idx), equal, _sort_general(greater,idx));
|
||||
|
||||
|
||||
function _sort_general(arr, idx=undef) =
|
||||
(len(arr)<=1) ? arr :
|
||||
let(
|
||||
@@ -774,9 +752,6 @@ function _sort_general(arr, idx=undef) =
|
||||
concat(_sort_general(lesser,idx), equal, _sort_general(greater,idx));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Function: sort()
|
||||
// Usage:
|
||||
// sort(list, [idx])
|
||||
@@ -809,7 +784,6 @@ function sort(list, idx=undef) =
|
||||
: _sort_general(list);
|
||||
|
||||
|
||||
|
||||
// Function: sortidx()
|
||||
// Description:
|
||||
// Given a list, calculates the sort order of the list, and returns
|
||||
@@ -853,6 +827,7 @@ function sortidx(list, idx=undef) =
|
||||
: // general case
|
||||
subindex(_sort_general(aug, idx=list_range(s=1,n=len(aug)-1)), 0);
|
||||
|
||||
|
||||
function sortidx(list, idx=undef) =
|
||||
list==[] ? [] : let(
|
||||
size = array_dim(list),
|
||||
@@ -891,7 +866,6 @@ function unique(arr) =
|
||||
];
|
||||
|
||||
|
||||
|
||||
// Function: unique_count()
|
||||
// Usage:
|
||||
// unique_count(arr);
|
||||
@@ -908,8 +882,6 @@ function unique_count(arr) =
|
||||
[ select(arr,ind), deltas( concat(ind,[len(arr)]) ) ];
|
||||
|
||||
|
||||
|
||||
|
||||
// Section: List Iteration Helpers
|
||||
|
||||
// Function: idx()
|
||||
@@ -1104,8 +1076,6 @@ function set_union(a, b, get_indices=false) =
|
||||
) [idxs, nset];
|
||||
|
||||
|
||||
|
||||
|
||||
// Function: set_difference()
|
||||
// Usage:
|
||||
// s = set_difference(a, b);
|
||||
@@ -1125,7 +1095,6 @@ function set_difference(a, b) =
|
||||
[ for (i=idx(a)) if(found[i]==[]) a[i] ];
|
||||
|
||||
|
||||
|
||||
// Function: set_intersection()
|
||||
// Usage:
|
||||
// s = set_intersection(a, b);
|
||||
@@ -1145,8 +1114,6 @@ function set_intersection(a, b) =
|
||||
[ for (i=idx(a)) if(found[i]!=[]) a[i] ];
|
||||
|
||||
|
||||
|
||||
|
||||
// Section: Array Manipulation
|
||||
|
||||
// Function: add_scalar()
|
||||
@@ -1165,7 +1132,6 @@ function add_scalar(v,s) =
|
||||
is_finite(s) ? [for (x=v) is_list(x)? add_scalar(x,s) : is_finite(x) ? x+s: x] : v;
|
||||
|
||||
|
||||
|
||||
// Function: subindex()
|
||||
// Description:
|
||||
// For each array item, return the indexed subitem.
|
||||
@@ -1349,6 +1315,4 @@ function transpose(arr) =
|
||||
: arr;
|
||||
|
||||
|
||||
|
||||
|
||||
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
||||
|
Reference in New Issue
Block a user