mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Syntax fix for group_data() asserts.
This commit is contained in:
parent
8ef32210c4
commit
d57e27f268
1 changed files with 12 additions and 6 deletions
18
arrays.scad
18
arrays.scad
|
@ -1816,16 +1816,22 @@ function array_group(v, cnt=2, dflt=0) =
|
|||
// Example:
|
||||
// groups = group_data([1,3,1], ["A","B","C"]); // Returns [[],["A","C"],[],["B"]]
|
||||
function group_data(groups, values) =
|
||||
assert(all_integer(groups) && all_nonnegative(groups));
|
||||
assert(is_list(values));
|
||||
assert(all_integer(groups) && all_nonnegative(groups))
|
||||
assert(is_list(values))
|
||||
assert(len(groups)==len(values),
|
||||
"The groups and values arguments should be lists of matching length.")
|
||||
let( sorted = _group_sort_by_index(zip(groups,values),0) )
|
||||
// retrieve values and insert []
|
||||
[for(i=idx(sorted))
|
||||
let( a = i==0? 0 : sorted[i-1][0][0]+1,
|
||||
g0 = sorted[i] )
|
||||
each [ for(j=[a:1:g0[0][0]-1]) [], [for(g1=g0) g1[1]] ]
|
||||
[
|
||||
for (i = idx(sorted))
|
||||
let(
|
||||
a = i==0? 0 : sorted[i-1][0][0]+1,
|
||||
g0 = sorted[i]
|
||||
)
|
||||
each [
|
||||
for (j = [a:1:g0[0][0]-1]) [],
|
||||
[for (g1 = g0) g1[1]]
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue