From 06b69475cb8d1bef5794e3dcff2d0e2945af3ec9 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Sun, 2 Aug 2020 10:38:11 -0400 Subject: [PATCH] Fix bug. Add test for subindex. --- arrays.scad | 2 +- tests/test_arrays.scad | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arrays.scad b/arrays.scad index 1a10b9f..0b7b924 100644 --- a/arrays.scad +++ b/arrays.scad @@ -1187,7 +1187,7 @@ function add_scalar(v,s) = // subindex(M,[2]); // Returns [[3], [7], [11], [15]] // subindex(M,[2,1]); // Returns [[3, 2], [7, 6], [11, 10], [15, 14]] // subindex(M,[1:3]); // Returns [[2, 3, 4], [6, 7, 8], [10, 11, 12], [14, 15, 16]] -function subindex(v, idx) = +function subindex(M, idx) = is_num(idx) ? [for(row=M) row[idx]] : [for(row=M) [for(i=idx) row[i]]]; diff --git a/tests/test_arrays.scad b/tests/test_arrays.scad index f621cd0..4fffb7d 100644 --- a/tests/test_arrays.scad +++ b/tests/test_arrays.scad @@ -358,6 +358,7 @@ test_add_scalar(); module test_subindex() { v = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]; assert(subindex(v,2) == [3, 7, 11, 15]); + assert(subindex(v,[2]) == [[3], [7], [11], [15]]); assert(subindex(v,[2,1]) == [[3, 2], [7, 6], [11, 10], [15, 14]]); assert(subindex(v,[1:3]) == [[2, 3, 4], [6, 7, 8], [10, 11, 12], [14, 15, 16]]); }