diff --git a/beziers.scad b/beziers.scad index af9675e..23735c9 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 ac95666..bdb05fb 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 8386094..98d6367 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 c219731..0c63a81 100644 --- a/shapes.scad +++ b/shapes.scad @@ -81,7 +81,7 @@ module cuboid( c2 = vmul(corner,c/2); $fn = is_finite(chamfer)? 4 : segs(r); translate(vmul(corner, size/2-c)) { - if (cnt == 0) { + if (cnt == 0 || approx(r,0)) { translate(c2) cube(c, center=true); } else if (cnt == 1) { if (e.x) right(c2.x) xcyl(l=c.x, r=r); @@ -120,6 +120,12 @@ module cuboid( size = scalar_vec3(size); edges = edges(edges, except=except_edges); + assert(is_vector(size,3)); + assert(is_undef(chamfer) || is_finite(chamfer)); + assert(is_undef(rounding) || is_finite(rounding)); + assert(is_undef(p1) || is_vector(p1)); + assert(is_undef(p2) || is_vector(p2)); + assert(is_bool(trimcorners)); if (!is_undef(p1)) { if (!is_undef(p2)) { translate(pointlist_bounds([p1,p2])[0]) { @@ -131,19 +137,19 @@ module cuboid( } } } else { - if (chamfer != undef) { + if (is_finite(chamfer)) { if (any(edges[0])) assert(chamfer <= size.y/2 && chamfer <=size.z/2, "chamfer must be smaller than half the cube length or height."); if (any(edges[1])) assert(chamfer <= size.x/2 && chamfer <=size.z/2, "chamfer must be smaller than half the cube width or height."); if (any(edges[2])) assert(chamfer <= size.x/2 && chamfer <=size.y/2, "chamfer must be smaller than half the cube width or length."); } - if (rounding != undef) { + if (is_finite(rounding)) { if (any(edges[0])) assert(rounding <= size.y/2 && rounding<=size.z/2, "rounding radius must be smaller than half the cube length or height."); if (any(edges[1])) assert(rounding <= size.x/2 && rounding<=size.z/2, "rounding radius must be smaller than half the cube width or height."); if (any(edges[2])) assert(rounding <= size.x/2 && rounding<=size.y/2, "rounding radius must be smaller than half the cube width or length."); } majrots = [[0,90,0], [90,0,0], [0,0,0]]; attachable(anchor,spin,orient, size=size) { - if (chamfer != undef) { + if (is_finite(chamfer) && !approx(chamfer,0)) { if (edges == EDGES_ALL && trimcorners) { if (chamfer<0) { cube(size, center=true) { @@ -212,7 +218,7 @@ module cuboid( corner_shape([ 1, 1, 1]); } } - } else if (rounding != undef) { + } else if (is_finite(rounding) && !approx(rounding,0)) { sides = quantup(segs(rounding),4); if (edges == EDGES_ALL) { if(rounding<0) { @@ -506,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(); } @@ -1389,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(); @@ -1561,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 4eda015..3401250 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 189eb41..12852f3 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,469]; +BOSL_VERSION = [2,0,471]; // Section: BOSL Library Version Functions