From 0399cd085cbf9c6665fa1be85c79318153eeb5b3 Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Sun, 29 Nov 2020 20:23:03 -0800 Subject: [PATCH] Guard various linear_extrude()s for height=0 --- beziers.scad | 6 ++++-- paths.scad | 14 +++++++++----- primitives.scad | 20 +++++++++++++------- shapes.scad | 26 ++++++++++++++++---------- shapes2d.scad | 4 ++-- version.scad | 2 +- 6 files changed, 45 insertions(+), 27 deletions(-) diff --git a/beziers.scad b/beziers.scad index af9675e2..23735c9b 100644 --- a/beziers.scad +++ b/beziers.scad @@ -762,8 +762,10 @@ module linear_sweep_bezier(bezier, height=100, splinesteps=16, N=3, center, conv maxy = max([for (pt = bezier) abs(pt[1])]); anchor = get_anchor(anchor,center,BOT,BOT); attachable(anchor,spin,orient, size=[maxx*2,maxy*2,height]) { - linear_extrude(height=height, center=true, convexity=convexity, twist=twist, slices=slices, scale=scale) { - bezier_polygon(bezier, splinesteps=splinesteps, N=N); + if (height > 0) { + linear_extrude(height=height, center=true, convexity=convexity, twist=twist, slices=slices, scale=scale) { + bezier_polygon(bezier, splinesteps=splinesteps, N=N); + } } children(); } diff --git a/paths.scad b/paths.scad index ac956667..bdb05fb5 100644 --- a/paths.scad +++ b/paths.scad @@ -779,12 +779,14 @@ module modulated_circle(r, sines=[10], d) // extrude_from_to([0,0,0], [10,20,30], convexity=4, twist=360, scale=3.0, slices=40) { // xcopies(3) circle(3, $fn=32); // } -module extrude_from_to(pt1, pt2, convexity=undef, twist=undef, scale=undef, slices=undef) { +module extrude_from_to(pt1, pt2, convexity, twist, scale, slices) { rtp = xyz_to_spherical(pt2-pt1); translate(pt1) { rotate([0, rtp[2], rtp[1]]) { - linear_extrude(height=rtp[0], convexity=convexity, center=false, slices=slices, twist=twist, scale=scale) { - children(); + if (rtp[0] > 0) { + linear_extrude(height=rtp[0], convexity=convexity, center=false, slices=slices, twist=twist, scale=scale) { + children(); + } } } } @@ -895,8 +897,10 @@ module path_extrude(path, convexity=10, clipsize=100) { translate(pt1) { Qrot(q) { down(clipsize/2/2) { - linear_extrude(height=dist+clipsize/2, convexity=convexity) { - children(); + if ((dist+clipsize/2) > 0) { + linear_extrude(height=dist+clipsize/2, convexity=convexity) { + children(); + } } } } diff --git a/primitives.scad b/primitives.scad index 83860948..98d63678 100644 --- a/primitives.scad +++ b/primitives.scad @@ -108,8 +108,10 @@ module cube(size=1, center, anchor, spin=0, orient=UP) anchor = get_anchor(anchor, center, ALLNEG, ALLNEG); size = scalar_vec3(size); attachable(anchor,spin,orient, size=size) { - linear_extrude(height=size.z, center=true, convexity=2) { - square([size.x,size.y], center=true); + if (size.z > 0) { + linear_extrude(height=size.z, center=true, convexity=2) { + square([size.x,size.y], center=true); + } } children(); } @@ -189,14 +191,18 @@ module cylinder(h, r1, r2, center, l, r, d, d1, d2, anchor, spin=0, orient=UP) l = first_defined([h, l, 1]); sides = segs(max(r1,r2)); attachable(anchor,spin,orient, r1=r1, r2=r2, l=l) { - if(r1>r2) { - linear_extrude(height=l, center=true, convexity=2, scale=r2/r1) { - circle(r=r1); + if (r1 > r2) { + if (l > 0) { + linear_extrude(height=l, center=true, convexity=2, scale=r2/r1) { + circle(r=r1); + } } } else { zflip() { - linear_extrude(height=l, center=true, convexity=2, scale=r1/r2) { - circle(r=r2); + if (l > 0) { + linear_extrude(height=l, center=true, convexity=2, scale=r1/r2) { + circle(r=r2); + } } } } diff --git a/shapes.scad b/shapes.scad index 97075992..0c63a812 100644 --- a/shapes.scad +++ b/shapes.scad @@ -512,8 +512,10 @@ module right_triangle(size=[1, 1, 1], center, anchor, spin=0, orient=UP) size = scalar_vec3(size); anchor = get_anchor(anchor, center, ALLNEG, ALLNEG); attachable(anchor,spin,orient, size=size) { - linear_extrude(height=size.z, convexity=2, center=true) { - polygon([[-size.x/2,-size.y/2], [-size.x/2,size.y/2], [size.x/2,-size.y/2]]); + if (size.z > 0) { + linear_extrude(height=size.z, convexity=2, center=true) { + polygon([[-size.x/2,-size.y/2], [-size.x/2,size.y/2], [size.x/2,-size.y/2]]); + } } children(); } @@ -1395,8 +1397,10 @@ module teardrop(r=undef, d=undef, l=undef, h=undef, ang=45, cap_h=undef, anchor= size = [r*2,l,r*2]; attachable(anchor,spin,orient, size=size) { rot(from=UP,to=FWD) { - linear_extrude(height=l, center=true, slices=2) { - teardrop2d(r=r, ang=ang, cap_h=cap_h); + if (l > 0) { + linear_extrude(height=l, center=true, slices=2) { + teardrop2d(r=r, ang=ang, cap_h=cap_h); + } } } children(); @@ -1567,12 +1571,14 @@ module interior_fillet(l=1.0, r, ang=90, overlap=0.01, d, anchor=FRONT+LEFT, spi steps = ceil(segs(r)*ang/360); step = ang/steps; attachable(anchor,spin,orient, size=[r,r,l]) { - linear_extrude(height=l, convexity=4, center=true) { - path = concat( - [[0,0]], - [for (i=[0:1:steps]) let(a=270-i*step) r*[cos(a),sin(a)]+[dy,r]] - ); - translate(-[r,r]/2) polygon(path); + if (l > 0) { + linear_extrude(height=l, convexity=4, center=true) { + path = concat( + [[0,0]], + [for (i=[0:1:steps]) let(a=270-i*step) r*[cos(a),sin(a)]+[dy,r]] + ); + translate(-[r,r]/2) polygon(path); + } } children(); } diff --git a/shapes2d.scad b/shapes2d.scad index 4eda015d..34012507 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -298,7 +298,7 @@ module stroke( } } else { rotate([90,0,endcap_angle1]) { - linear_extrude(height=widths[0], center=true, convexity=convexity) { + linear_extrude(height=max(widths[0],0.001), center=true, convexity=convexity) { polygon(endcap_shape1); } } @@ -318,7 +318,7 @@ module stroke( } } else { rotate([90,0,endcap_angle2]) { - linear_extrude(height=select(widths,-1), center=true, convexity=convexity) { + linear_extrude(height=max(select(widths,-1),0.001), center=true, convexity=convexity) { polygon(endcap_shape2); } } diff --git a/version.scad b/version.scad index 7b409d9f..12852f35 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,470]; +BOSL_VERSION = [2,0,471]; // Section: BOSL Library Version Functions