From 48b154b9f849db97085cc2f4b40cadf8aea6ab21 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Fri, 28 Jun 2019 18:26:05 -0400 Subject: [PATCH] Fixed bug in list_set and arg order --- arrays.scad | 8 ++++---- structs.scad | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arrays.scad b/arrays.scad index a06d681..17d794d 100644 --- a/arrays.scad +++ b/arrays.scad @@ -171,7 +171,7 @@ function deduplicate(list, eps=EPSILON) = // Function: list_set() // Usage: -// list_set(indices, values, list, [dflt], [minlen]) +// list_set(list, indices, values, [dflt], [minlen]) // Description: // Takes the input list and returns a new list such that `list[indices[i]] = values[i]` for all of // the (index,value) pairs supplied. If you supply `indices` that are beyond the length of the list @@ -180,12 +180,12 @@ function deduplicate(list, eps=EPSILON) = // order but run time will be (much) faster for long lists if it is already sorted. Reptitions are // not allowed. // Arguments: +// list = List to set items in. Default: [] // indices = List of indices into `list` to set. // values = List of values to set. -// list = List to set items in. // dflt = Default value to store in sparse skipped indices. // minlen = Minimum length to expand list to. -function list_set(indices,values,list=[],dflt=0,minlen=0) = +function list_set(list=[],indices,values,dflt=0,minlen=0) = !is_list(indices) ? list_set(list,[indices],[values],dflt) : assert(len(indices)==len(values),"Index list and value list must have the same length") let( @@ -272,7 +272,7 @@ function list_bset(indexset, valuelist, dflt=0) = let( trueind = search([true], indexset,0)[0] ) concat( - list_set(trueind, valuelist, dflt=dflt), // Fill in all of the values + list_set([],trueind, valuelist, dflt=dflt), // Fill in all of the values replist(dflt,len(indexset)-max(trueind)-1) // Add trailing values so length matches indexset ); diff --git a/structs.scad b/structs.scad index eed3cb0..d0be5ad 100644 --- a/structs.scad +++ b/structs.scad @@ -25,7 +25,7 @@ function struct_set(struct, keyword, value=undef, grow=true) = let(ind=search([keyword],struct,1,0)[0]) (ind==[] ? assert(grow,str("Unknown keyword \"",keyword)) concat(struct, [[keyword,value]]) : - list_set([ind], [[keyword,value]],struct)) : + list_set(struct, [ind], [[keyword,value]])) : _parse_pairs(struct,keyword,grow); function _parse_pairs(spec, input, grow=true, index=0, result=undef) =