mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Fixed transpose for vectors and non-array lists
This commit is contained in:
parent
78e3cd3c27
commit
dba2edc984
2 changed files with 2 additions and 3 deletions
|
@ -496,8 +496,7 @@ function array_dim(v, depth=undef) =
|
|||
// transpose([3,4,5]); // Returns: [[3],[4],[5]]
|
||||
function transpose(arr) =
|
||||
arr==[]? [] :
|
||||
is_list(arr[0])? [for (i=[0:len(arr[0])-1]) [for (j=[0:len(arr)-1]) arr[j][i]]] :
|
||||
[for (x=arr) [x]];
|
||||
is_list(arr[0])? [for (i=[0:len(arr[0])-1]) [for (j=[0:len(arr)-1]) arr[j][i]]] : arr;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ test_array_dim();
|
|||
module test_transpose() {
|
||||
assert(transpose([[1,2,3],[4,5,6],[7,8,9]]) == [[1,4,7],[2,5,8],[3,6,9]]);
|
||||
assert(transpose([[1,2,3],[4,5,6]]) == [[1,4],[2,5],[3,6]]);
|
||||
assert(transpose([3,4,5]) == [[3],[4],[5]]);
|
||||
assert(transpose([3,4,5]) == [3,4,5]);
|
||||
}
|
||||
test_transpose();
|
||||
|
||||
|
|
Loading…
Reference in a new issue