mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Fixed wrap_range negative index wrapping.
This commit is contained in:
parent
d52a0b7ab4
commit
74702b5863
1 changed files with 9 additions and 4 deletions
13
math.scad
13
math.scad
|
@ -73,13 +73,18 @@ function reverse(list) = [ for (i = [len(list)-1 : -1 : 0]) list[i] ];
|
|||
|
||||
// Returns a slice of the given array, wrapping around past the beginning, if end < start
|
||||
function wrap_range(list, start, end) =
|
||||
(end<start)?
|
||||
let(
|
||||
l = len(list),
|
||||
st = start<0? (start%l)+l : (start%l),
|
||||
en = end<0? (end%l)+l : (end%l)
|
||||
)
|
||||
(en<st)?
|
||||
concat(
|
||||
[for (i=[start:len(list)-1]) list[i]],
|
||||
[for (i=[0:end]) list[i]]
|
||||
[for (i=[st:l-1]) list[i]],
|
||||
[for (i=[0:en]) list[i]]
|
||||
)
|
||||
:
|
||||
[for (i=[start:end]) list[i]]
|
||||
[for (i=[st:en]) list[i]]
|
||||
;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue