mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
Large optimization to select()
This commit is contained in:
parent
55a797b9b9
commit
015c34d637
2 changed files with 11 additions and 4 deletions
|
@ -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);
|
||||
|
||||
|
||||
|
|
13
math.scad
13
math.scad
|
@ -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,6]
|
||||
function select(list, start, end=undef) =
|
||||
let(l = len(list))
|
||||
let(l=len(list))
|
||||
(list==[])? [] :
|
||||
!is_def(end)? (
|
||||
is_scalar(start)?
|
||||
list[posmod(start, l)] :
|
||||
let(s=posmod(start,l)) list[s] :
|
||||
[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()
|
||||
|
|
Loading…
Reference in a new issue