Fixed trace_bezier_patch to correct fatal error and modified it so it

only calculates the vnf when needed, as this can be slow.
This commit is contained in:
Adrian Mariano 2020-05-21 15:52:44 -04:00
parent 30c63fd165
commit 83ed788ac6

View file

@ -1255,49 +1255,41 @@ module bezier_polyhedron(patches=[], splinesteps=16, vnf=EMPTY_VNF, style="defau
// trace_bezier_patches(patches=[patch1, patch2], splinesteps=8, showcps=true); // trace_bezier_patches(patches=[patch1, patch2], splinesteps=8, showcps=true);
module trace_bezier_patches(patches=[], size, splinesteps=16, showcps=true, showdots=false, showpatch=true, convexity=10, style="default") module trace_bezier_patches(patches=[], size, splinesteps=16, showcps=true, showdots=false, showpatch=true, convexity=10, style="default")
{ {
assert(is_undef(size)||is_num(size)); assert(is_undef(size)||is_num(size));
assert(is_int(splinesteps) && splinesteps>0); assert(is_int(splinesteps) && splinesteps>0);
assert(is_list(patches) && all([for (patch=patches) is_patch(patch)])); assert(is_list(patches) && all([for (patch=patches) is_patch(patch)]));
assert(is_bool(showcps)); assert(is_bool(showcps));
assert(is_bool(showdots)); assert(is_bool(showdots));
assert(is_bool(showpatch)); assert(is_bool(showpatch));
assert(is_int(convexity) && convexity>0); assert(is_int(convexity) && convexity>0);
vnfs = [ for (patch = patches) {
for (patch = patches) size = is_num(size)? size :
bezier_patch(patch, splinesteps=splinesteps, style=style) let( bounds = pointlist_bounds(flatten(patch)) )
]; max(bounds[1]-bounds[0])*0.01;
if (showcps || showdots) { if (showcps) {
for (patch = patches) { move_copies(flatten(patch)) color("red") sphere(d=size*2);
size = is_num(size)? size : color("cyan") {
let( bounds = pointlist_bounds(flatten(patch)) ) if (is_tripatch(patch)) {
max(bounds[1]-bounds[0])*0.01; for (i=[0:1:len(patch)-2], j=[0:1:len(patch[i])-2]) {
if (showcps) { extrude_from_to(patch[i][j], patch[i+1][j]) circle(d=size);
move_copies(flatten(patch)) color("red") sphere(d=size*2); extrude_from_to(patch[i][j], patch[i][j+1]) circle(d=size);
color("cyan") { extrude_from_to(patch[i+1][j], patch[i][j+1]) circle(d=size);
if (is_tripatch(patch)) { }
for (i=[0:1:len(patch)-2], j=[0:1:len(patch[i])-2]) { } else {
extrude_from_to(patch[i][j], patch[i+1][j]) circle(d=size); for (i=[0:1:len(patch)-1], j=[0:1:len(patch[i])-1]) {
extrude_from_to(patch[i][j], patch[i][j+1]) circle(d=size); if (i<len(patch)-1) extrude_from_to(patch[i][j], patch[i+1][j]) circle(d=size);
extrude_from_to(patch[i+1][j], patch[i][j+1]) circle(d=size); if (j<len(patch[i])-1) extrude_from_to(patch[i][j], patch[i][j+1]) circle(d=size);
} }
} else { }
for (i=[0:1:len(patch)-1], j=[0:1:len(patch[i])-1]) { }
if (i<len(patch)-1) extrude_from_to(patch[i][j], patch[i+1][j]) circle(d=size); }
if (j<len(patch[i])-1) extrude_from_to(patch[i][j], patch[i][j+1]) circle(d=size); if (showpatch || showdots){
} vnf = bezier_patch(patch, splinesteps=splinesteps, style=style);
} if (showpatch) vnf_polyhedron(vnf, convexity=convexity);
} if (showdots) color("blue") move_copies(vnf[0]) sphere(d=size);
} }
if (showdots){ }
color("blue") move_copies(vnfs[i][0]) sphere(d=size);
}
}
}
if (showpatch) {
vnf_polyhedron(vnfs, convexity=convexity);
}
} }
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap // vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap