Large optimization to select()

This commit is contained in:
Revar Desmera 2019-03-30 22:39:44 -07:00
parent 55a797b9b9
commit 015c34d637
2 changed files with 11 additions and 4 deletions

View file

@ -108,7 +108,7 @@ module CR_cube(size=[100,100,100], r=10, splinesteps=8, cheat=false)
} }
CR_cube(size=[100,100,100], r=20, splinesteps=2, cheat=false); CR_cube(size=[100,100,100], r=20, splinesteps=9, cheat=false);
cube(1); cube(1);

View file

@ -457,12 +457,19 @@ function wrap_range(list, start, end=undef) = select(list,start,end);
// select(l, [1:3]); // Returns [4,5,6] // select(l, [1:3]); // Returns [4,5,6]
// select(l, [1,3]); // Returns [4,6] // select(l, [1,3]); // Returns [4,6]
function select(list, start, end=undef) = function select(list, start, end=undef) =
let(l = len(list)) let(l=len(list))
(list==[])? [] :
!is_def(end)? ( !is_def(end)? (
is_scalar(start)? is_scalar(start)?
list[posmod(start, l)] : let(s=posmod(start,l)) list[s] :
[for (i=start) list[posmod(i, l)]] [for (i=start) list[posmod(i, l)]]
) : [for (i = modrange(start, end, l)) list[i]]; ) : (
let(s=posmod(start,l), e=posmod(end,l))
(s<=e)?
[for (i = [s:e]) list[i]] :
concat([for (i = [s:l-1]) list[i]], [for (i = [0:e]) list[i]])
);
// Function: reverse() // Function: reverse()