From 14e89a3a09a23371f3936488b090c0f3f865d670 Mon Sep 17 00:00:00 2001 From: Alex Matulich Date: Sat, 22 Mar 2025 23:52:45 -0700 Subject: [PATCH] resolved closed true/false behavior --- isosurface.scad | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/isosurface.scad b/isosurface.scad index 360a7f04..d66c1eae 100644 --- a/isosurface.scad +++ b/isosurface.scad @@ -1080,15 +1080,16 @@ function _contour_pixels(pixsize, bbox, fieldarray, fieldfunc, pixcenters, isova nx = len(field)-2, ny = len(field[0])-2, v0 = bbox[0] -) [ +) let(isocorrect = sign(isovalue)*max(abs(isovalue)*1.000001, isovalue+0.0000001)) [ for(i=[0:nx]) let(x=v0.x+pixsize.x*i) for(j=[0:ny]) let(y=v0.y+pixsize.y*j) let(i1=i+1, j1=j+1, pf = let( - f0=min(1e9,max(-1e9,field[i][j])), - f1=min(1e9,max(-1e9,field[i][j1])), - f2=min(1e9,max(-1e9,field[i1][j])), - f3=min(1e9,max(-1e9,field[i1][j1])) + // clamp corner values to ±1e9, make sure no corner=isovalue + f0=let(c=min(1e9,max(-1e9,field[i][j]))) abs(c-isovalue)0) left[0],if (len(right)>0) right[0]]), - update_path = left==[] && right==[] ? edges[i] + update_path = left==[] && right==[] ? edges[i] : left==[] ? concat(list_head(edges[i]),paths[right[0]]) : right==[] ? concat(paths[left[0]],slice(edges[i],1,-1)) - : left[0] != right[0] ? concat(paths[left[0]], paths[right[0]]) - : concat(paths[left[0]], slice(edges[i],1,-1)) // last arg should be -2 to avoid duplicating endpoints on closed path + : left[0] != right[0] ? concat(paths[left[0]],slice(edges[i],1,-2), paths[right[0]]) + : concat(paths[left[0]], slice(edges[i],1,-1)) // last arg -2 removes duplicate endpoints but this is handled in passthrough function ) _assemble_partial_paths_recur(edges, concat(keep_path, [update_path]), i+1); @@ -3609,7 +3612,7 @@ function _region_smooth(reg, passes, bbox, count=0) = count >= passes ? reg : let(sm = [ for(r=reg) let( - n=len(r), + n = r[0]==last(r) ? len(r)-1 : len(r), pb = [for(i=[0:n-1]) _is_pt_on_bbox(r[i],bbox)] ) [ for(i=[0:n-1]) let(j=(i+1)%n) each [