mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
path_merge_collinear can delete first point
This commit is contained in:
parent
01c364ec3a
commit
869888c7ec
1 changed files with 9 additions and 11 deletions
18
paths.scad
18
paths.scad
|
@ -134,7 +134,8 @@ function _path_select(path, s1, u1, s2, u2, closed=false) =
|
|||
// SynTags: Path
|
||||
// Topics: Paths, Regions
|
||||
// Description:
|
||||
// Takes a path and removes unnecessary sequential collinear points.
|
||||
// Takes a path and removes unnecessary sequential collinear points. Note that when `closed=true` either of the path
|
||||
// endpoints may be removed.
|
||||
// Usage:
|
||||
// path_merge_collinear(path, [eps])
|
||||
// Arguments:
|
||||
|
@ -148,15 +149,12 @@ function path_merge_collinear(path, closed, eps=EPSILON) =
|
|||
assert( is_path(path), "Invalid path in path_merge_collinear." )
|
||||
assert( is_undef(eps) || (is_finite(eps) && (eps>=0) ), "Invalid tolerance." )
|
||||
len(path)<=2 ? path :
|
||||
let(
|
||||
indices = [
|
||||
0,
|
||||
for (i=[1:1:len(path)-(closed?1:2)])
|
||||
if (!is_collinear(path[i-1], path[i], select(path,i+1), eps=eps)) i,
|
||||
if (!closed) len(path)-1
|
||||
]
|
||||
) [for (i=indices) path[i]];
|
||||
|
||||
[
|
||||
if(!closed) path[0],
|
||||
for(triple=triplet(path,wrap=closed))
|
||||
if (!is_collinear(triple,eps=eps)) triple[1],
|
||||
if(!closed) last(path)
|
||||
];
|
||||
|
||||
|
||||
// Section: Path length calculation
|
||||
|
|
Loading…
Reference in a new issue