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
20
paths.scad
20
paths.scad
|
@ -134,7 +134,8 @@ function _path_select(path, s1, u1, s2, u2, closed=false) =
|
||||||
// SynTags: Path
|
// SynTags: Path
|
||||||
// Topics: Paths, Regions
|
// Topics: Paths, Regions
|
||||||
// Description:
|
// 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:
|
// Usage:
|
||||||
// path_merge_collinear(path, [eps])
|
// path_merge_collinear(path, [eps])
|
||||||
// Arguments:
|
// Arguments:
|
||||||
|
@ -146,17 +147,14 @@ function path_merge_collinear(path, closed, eps=EPSILON) =
|
||||||
let(closed=default(closed,false))
|
let(closed=default(closed,false))
|
||||||
assert(is_bool(closed))
|
assert(is_bool(closed))
|
||||||
assert( is_path(path), "Invalid path in path_merge_collinear." )
|
assert( is_path(path), "Invalid path in path_merge_collinear." )
|
||||||
assert( is_undef(eps) || (is_finite(eps) && (eps>=0) ), "Invalid tolerance." )
|
assert( is_undef(eps) || (is_finite(eps) && (eps>=0) ), "Invalid tolerance." )
|
||||||
len(path)<=2 ? path :
|
len(path)<=2 ? path :
|
||||||
let(
|
[
|
||||||
indices = [
|
if(!closed) path[0],
|
||||||
0,
|
for(triple=triplet(path,wrap=closed))
|
||||||
for (i=[1:1:len(path)-(closed?1:2)])
|
if (!is_collinear(triple,eps=eps)) triple[1],
|
||||||
if (!is_collinear(path[i-1], path[i], select(path,i+1), eps=eps)) i,
|
if(!closed) last(path)
|
||||||
if (!closed) len(path)-1
|
];
|
||||||
]
|
|
||||||
) [for (i=indices) path[i]];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Section: Path length calculation
|
// Section: Path length calculation
|
||||||
|
|
Loading…
Reference in a new issue