add deduplicate to rect(), add deduplicate to is_path_simple

add epsilon to degenerate bezier patch detection
This commit is contained in:
Adrian Mariano 2024-01-28 18:22:04 -05:00
parent 75f7a75ac2
commit 5435bb1fc2
4 changed files with 14 additions and 5 deletions

View File

@ -1252,8 +1252,8 @@ function bezier_vnf_degenerate_patch(patch, splinesteps=16, reverse=false, retur
assert(is_bezier_patch(patch), "Input is not a Bezier patch")
assert(is_int(splinesteps) && splinesteps>0, "splinesteps must be a positive integer")
let(
row_degen = [for(row=patch) all_equal(row)],
col_degen = [for(col=transpose(patch)) all_equal(col)],
row_degen = [for(row=patch) all_equal(row,eps=EPSILON)],
col_degen = [for(col=transpose(patch)) all_equal(col,eps=EPSILON)],
top_degen = row_degen[0],
bot_degen = last(row_degen),
left_degen = col_degen[0],

View File

@ -280,7 +280,7 @@ function _path_self_intersections(path, closed=true, eps=EPSILON) =
// [a1,a2]. The variable signals is zero when abs(vals[j]-ref) is less than
// eps and the sign of vals[j]-ref otherwise.
signals = [for(j=[i+2:1:plen-(i==0 && closed? 2: 1)])
abs(vals[j]-ref) < eps ? 0 : sign(vals[j]-ref) ]
abs(vals[j]-ref) < eps ? 0 : sign(vals[j]-ref) ]
)
if(max(signals)>=0 && min(signals)<=0 ) // some remaining edge intersects line [a1,a2]
for(j=[i+2:1:plen-(i==0 && closed? 3: 2)])
@ -581,6 +581,9 @@ function is_path_simple(path, closed, eps=EPSILON) =
let(closed=default(closed,false))
assert(is_path(path, 2),"Must give a 2D path")
assert(is_bool(closed))
let(
path = deduplicate(path,closed=closed,eps=eps)
)
// check for path reversals
[for(i=[0:1:len(path)-(closed?2:3)])
let(v1=path[i+1]-path[i],

View File

@ -214,7 +214,7 @@ function rect(size=1, rounding=0, chamfer=0, atype="box", anchor=CENTER, spin=0,
assert(is_undef(cornerpt) || len(cornerpt)==1,"Cannot find corner point to anchor")
[move(cp, p=qrpts), is_undef(cornerpt)? undef : move(cp,p=cornerpt[0])]
],
path = flatten(column(corners,0)),
path = deduplicate(flatten(column(corners,0)),closed=true),
override = [for(i=[0:3])
let(quad=quadorder[i])
if (is_def(corners[i][1])) [quadpos[quad], [corners[i][1], min(chamfer[quad],rounding[quad])<0 ? [quadpos[quad].x,0] : undef]]]

View File

@ -298,5 +298,11 @@ test_path_torsion();
//echo(fmt_float(sampled));
module test_is_path_simple(){
assert(is_path_simple([[0,0],[1,1],[1,1],[2,1]]));
assert(is_path_simple([[0,0],[10,0],[0,20],[10,20]],closed=false));
assert(!is_path_simple([[0,0],[10,0],[0,20],[10,20]],closed=true));
assert(is_path_simple(circle($fn=20, r=10)));
}