From d86b94193b03ecfe7ba1b8652428e1a51f2021e2 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Fri, 12 Jul 2019 20:19:33 -0400 Subject: [PATCH] Handle zero length inputs for list_set and list_remove --- arrays.scad | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arrays.scad b/arrays.scad index 4fd651b..f8e9d60 100644 --- a/arrays.scad +++ b/arrays.scad @@ -190,7 +190,7 @@ function list_set(list=[],indices,values,dflt=0,minlen=0) = assert(len(indices)==len(values),"Index list and value list must have the same length") let( sortind = list_increasing(indices) ? list_range(len(indices)) : sortidx(indices), - lastind = indices[select(sortind,-1)] + lastind = len(indices)==0 ? -1 : indices[select(sortind,-1)] ) concat( [for(j=[0:1:indices[sortind[0]]-1]) j>=len(list) ? dflt : list[j]], @@ -217,6 +217,7 @@ function list_set(list=[],indices,values,dflt=0,minlen=0) = // elements = The list of indexes of items to remove. function list_remove(list, elements) = !is_list(elements) ? list_remove(list,[elements]) : + len(elements)==0 ? list : let( sortind = list_increasing(elements) ? list_range(len(elements)) : sortidx(elements), lastind = elements[select(sortind,-1)] )