Refactor trace_bezier_patches() to calculate vertices only once.

This commit is contained in:
Revar Desmera 2020-03-28 15:02:14 -07:00
parent 5e4889652b
commit e06ea582fb
2 changed files with 17 additions and 7 deletions

View file

@ -1009,11 +1009,22 @@ module bezier_polyhedron(patches=[], splinesteps=16, vnf=EMPTY_VNF, style="defau
// 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")
{
assert(is_undef(size)||is_num(size));
assert(is_int(splinesteps) && splinesteps>0);
assert(is_list(patches) && all([for (patch=patches) is_patch(patch)]));
assert(is_bool(showcps));
assert(is_bool(showdots));
assert(is_bool(showpatch));
assert(is_int(convexity) && convexity>0);
vnfs = [
for (patch = patches)
bezier_patch(patch, splinesteps=splinesteps, style=style)
];
if (showcps || showdots) {
for (patch = patches) {
bounds = pointlist_bounds(flatten(patch));
size = default(size, max(bounds[1]-bounds[0])*0.01);
echo(size=size);
size = is_num(size)? size :
let( bounds = pointlist_bounds(flatten(patch)) )
max(bounds[1]-bounds[0])*0.01;
if (showcps) {
move_copies(flatten(patch)) color("red") sphere(d=size*2);
color("cyan") {
@ -1032,13 +1043,12 @@ module trace_bezier_patches(patches=[], size, splinesteps=16, showcps=true, show
}
}
if (showdots){
vnf = bezier_patch(patch, splinesteps=splinesteps, style=style);
color("blue") move_copies(vnf[0]) sphere(d=size);
color("blue") move_copies(vnfs[i][0]) sphere(d=size);
}
}
}
if (showpatch) {
bezier_polyhedron(patches=patches, splinesteps=splinesteps, convexity=convexity, style=style);
vnf_polyhedron(vnfs, convexity=convexity);
}
}

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,235];
BOSL_VERSION = [2,0,236];
// Section: BOSL Library Version Functions