mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 00:09:41 +00:00
Optimized cleanup_path() and list_rotate()
This commit is contained in:
parent
d69242f848
commit
84bd2088e5
2 changed files with 12 additions and 3 deletions
|
@ -432,7 +432,14 @@ function reverse(x) =
|
|||
function list_rotate(list,n=1) =
|
||||
assert(is_list(list)||is_string(list), "Invalid list or string.")
|
||||
assert(is_finite(n), "Invalid number")
|
||||
let (elems = select(list,n,n+len(list)-1))
|
||||
let (
|
||||
ll = len(list),
|
||||
n = ((n % ll) + ll) % ll,
|
||||
elems = [
|
||||
for (i=[n:1:ll-1]) list[i],
|
||||
for (i=[0:1:n-1]) list[i]
|
||||
]
|
||||
)
|
||||
is_string(list)? str_join(elems) : elems;
|
||||
|
||||
|
||||
|
|
|
@ -62,7 +62,8 @@ function is_closed_path(path, eps=EPSILON) = approx(path[0], path[len(path)-1],
|
|||
// close_path(path);
|
||||
// Description:
|
||||
// If a path's last point does not coincide with its first point, closes the path so it does.
|
||||
function close_path(path, eps=EPSILON) = is_closed_path(path,eps=eps)? path : concat(path,[path[0]]);
|
||||
function close_path(path, eps=EPSILON) =
|
||||
is_closed_path(path,eps=eps)? path : concat(path,[path[0]]);
|
||||
|
||||
|
||||
// Function: cleanup_path()
|
||||
|
@ -70,7 +71,8 @@ function close_path(path, eps=EPSILON) = is_closed_path(path,eps=eps)? path : co
|
|||
// cleanup_path(path);
|
||||
// Description:
|
||||
// If a path's last point coincides with its first point, deletes the last point in the path.
|
||||
function cleanup_path(path, eps=EPSILON) = is_closed_path(path,eps=eps)? select(path,0,-2) : path;
|
||||
function cleanup_path(path, eps=EPSILON) =
|
||||
is_closed_path(path,eps=eps)? [for (i=[0:1:len(path)-2]) path[i]] : path;
|
||||
|
||||
|
||||
// Function: path_subselect()
|
||||
|
|
Loading…
Reference in a new issue