From 14e12d8456d7d793fca615437d67926915f9392c Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Wed, 9 Nov 2022 16:54:27 -0500 Subject: [PATCH] assert cleanup --- attachments.scad | 38 +++++++++++++++++--------------- beziers.scad | 7 +++--- cubetruss.scad | 7 +++--- distributors.scad | 6 +++--- drawing.scad | 55 ++++++++++++++++++++++++----------------------- geometry.scad | 9 +++++--- joiners.scad | 29 +++++++++++++------------ masks3d.scad | 15 +++++++------ modular_hose.scad | 2 +- mutators.scad | 18 +++++++++------- polyhedra.scad | 2 +- rounding.scad | 23 ++++++++++---------- skin.scad | 2 +- threading.scad | 13 +++++------ 14 files changed, 120 insertions(+), 106 deletions(-) diff --git a/attachments.scad b/attachments.scad index 3c222fb..0636c0a 100644 --- a/attachments.scad +++ b/attachments.scad @@ -465,17 +465,19 @@ module position(from) module orient(dir, anchor, spin) { req_children($children); if (!is_undef(dir)) { - assert(anchor==undef, "Only one of dir= or anchor= may be given to orient()"); - assert(is_vector(dir)); spin = default(spin, 0); - assert(is_finite(spin)); + check = + assert(anchor==undef, "Only one of dir= or anchor= may be given to orient()") + assert(is_vector(dir)) + assert(is_finite(spin)); two_d = _attach_geom_2d($parent_geom); fromvec = two_d? BACK : UP; rot(spin, from=fromvec, to=dir) children(); } else { - assert(dir==undef, "Only one of dir= or anchor= may be given to orient()"); - assert($parent_geom != undef, "No parent to orient from!"); - assert(is_string(anchor) || is_vector(anchor)); + check= + assert(dir==undef, "Only one of dir= or anchor= may be given to orient()") + assert($parent_geom != undef, "No parent to orient from!") + assert(is_string(anchor) || is_vector(anchor)); anch = _find_anchor(anchor, $parent_geom); two_d = _attach_geom_2d($parent_geom); fromvec = two_d? BACK : UP; @@ -568,8 +570,9 @@ module attach(from, to, overlap, norot=false) module tag(tag) { req_children($children); - assert(is_string(tag),"tag must be a string"); - assert(undef==str_find($tag," "),str("Tag string \"",$tag,"\" contains a space, which is not allowed")) ; + check= + assert(is_string(tag),"tag must be a string") + assert(undef==str_find(tag," "),str("Tag string \"",tag,"\" contains a space, which is not allowed")); $tag = str($tag_prefix,tag); children(); } @@ -627,7 +630,7 @@ module tag(tag) module force_tag(tag) { req_children($children); - assert(is_undef(tag) || is_string(tag),"tag must be a string"); + check1=assert(is_undef(tag) || is_string(tag),"tag must be a string"); $tag = str($tag_prefix,default(tag,$tag)); assert(undef==str_find($tag," "),str("Tag string \"",$tag,"\" contains a space, which is not allowed")); if(_is_shown()) @@ -710,6 +713,7 @@ module tag_scope(scope){ req_children($children); scope = is_undef(scope) ? rand_str(20) : scope; assert(is_string(scope), "scope must be a string"); + assert(undef==str_find(scope," "),str("Scope string \"",scope,"\" contains a space, which is not allowed")); $tag_prefix=scope; children(); } @@ -1206,7 +1210,7 @@ module tag_conv_hull(tag,keep="keep") module hide(tags) { req_children($children); - assert(is_string(tags), "tags must be a string"); + dummy=assert(is_string(tags), "tags must be a string"); taglist = [for(s=str_split(tags," ",keep_nulls=false)) str($tag_prefix,s)]; $tags_hidden = concat($tags_hidden,taglist); children(); @@ -1233,7 +1237,7 @@ module hide(tags) module show_only(tags) { req_children($children); - assert(is_string(tags), str("tags must be a string",tags)); + dummy=assert(is_string(tags), str("tags must be a string",tags)); taglist = [for(s=str_split(tags," ",keep_nulls=false)) str($tag_prefix,s)]; $tags_shown = taglist; children(); @@ -1270,7 +1274,7 @@ module show_all() module show_int(tags) { req_children($children); - assert(is_string(tags), str("tags must be a string",tags)); + dummy=assert(is_string(tags), str("tags must be a string",tags)); taglist = [for(s=str_split(tags," ",keep_nulls=false)) str($tag_prefix,s)]; $tags_shown = $tags_shown == "ALL" ? taglist : set_intersection($tags_shown,taglist); children(); @@ -1321,7 +1325,7 @@ module edge_mask(edges=EDGES_ALL, except=[]) { ]; for (vec = vecs) { vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0); - assert(vcount == 2, "Not an edge vector!"); + dummy=assert(vcount == 2, "Not an edge vector!"); anch = _find_anchor(vec, $parent_geom); $attach_to = undef; $attach_anchor = anch; @@ -1369,7 +1373,7 @@ module corner_mask(corners=CORNERS_ALL, except=[]) { vecs = [for (i = [0:7]) if (corners[i]>0) CORNER_OFFSETS[i]]; for (vec = vecs) { vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0); - assert(vcount == 3, "Not an edge vector!"); + dummy=assert(vcount == 3, "Not an edge vector!"); anch = _find_anchor(vec, $parent_geom); $attach_to = undef; $attach_anchor = anch; @@ -1452,7 +1456,7 @@ module edge_profile(edges=EDGES_ALL, except=[], convexity=10) { ]; for (vec = vecs) { vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0); - assert(vcount == 2, "Not an edge vector!"); + dummy=assert(vcount == 2, "Not an edge vector!"); anch = _find_anchor(vec, $parent_geom); $attach_to = undef; $attach_anchor = anch; @@ -1509,7 +1513,7 @@ module corner_profile(corners=CORNERS_ALL, except=[], r, d, convexity=10) { vecs = [for (i = [0:7]) if (corners[i]>0) CORNER_OFFSETS[i]]; for (vec = vecs) { vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0); - assert(vcount == 3, "Not an edge vector!"); + dummy=assert(vcount == 3, "Not an edge vector!"); anch = _find_anchor(vec, $parent_geom); $attach_to = undef; $attach_anchor = anch; @@ -2705,7 +2709,7 @@ function _standard_anchors(two_d=false) = [ // Example(FlatSpin,VPD=333): // cube(50, center=true) show_anchors(); module show_anchors(s=10, std=true, custom=true) { - check = assert($parent_geom != undef) 1; + check = assert($parent_geom != undef); two_d = _attach_geom_2d($parent_geom); if (std) { for (anchor=_standard_anchors(two_d=two_d)) { diff --git a/beziers.scad b/beziers.scad index f2521c2..e9a6e98 100644 --- a/beziers.scad +++ b/beziers.scad @@ -1424,9 +1424,10 @@ function bezier_patch_normals(patch, u, v) = // debug_bezier(bez, N=3, width=0.5); module debug_bezier(bezpath, width=1, N=3) { no_children($children); - assert(is_path(bezpath)); - assert(is_int(N)); - assert(len(bezpath)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); + check = + assert(is_path(bezpath),"bezpath must be a path") + assert(is_int(N) && N>0, "N must be a positive integer") + assert(len(bezpath)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); $fn=8; stroke(bezpath_curve(bezpath, N=N), width=width, color="cyan"); color("green") diff --git a/cubetruss.scad b/cubetruss.scad index b64b6ec..f3e03a4 100644 --- a/cubetruss.scad +++ b/cubetruss.scad @@ -133,9 +133,10 @@ module cubetruss_support(size, strut, extents=1, anchor=CENTER, spin=0, orient=U extents = is_num(extents)? [1,1,extents] : extents; size = is_undef(size)? $cubetruss_size : size; strut = is_undef(strut)? $cubetruss_strut_size : strut; - assert(is_int(extents.x) && extents.x > 0); - assert(is_int(extents.y) && extents.y > 0); - assert(is_int(extents.z) && extents.z > 0); + check = + assert(is_int(extents.x) && extents.x > 0) + assert(is_int(extents.y) && extents.y > 0) + assert(is_int(extents.z) && extents.z > 0); w = (size-strut) * extents.x + strut; l = (size-strut) * extents.y + strut; h = (size-strut) * extents.z + strut; diff --git a/distributors.scad b/distributors.scad index efa1798..36adb19 100644 --- a/distributors.scad +++ b/distributors.scad @@ -409,7 +409,7 @@ module grid2d(spacing, n, size, stagger=false, inside=undef, nonzero) module grid_copies(spacing, n, size, stagger=false, inside=undef, nonzero) { req_children($children); - assert(in_list(stagger, [false, true, "alt"])); + dummy = assert(in_list(stagger, [false, true, "alt"])); bounds = is_undef(inside)? undef : is_path(inside)? pointlist_bounds(inside) : assert(is_region(inside)) @@ -1035,8 +1035,8 @@ module path_copies(path, n, spacing, sp=undef, dist, rotate_children=true, dist, sort([for(entry=ptlist) posmod(entry-listcenter,length)]) : [for(entry=ptlist) entry + length/2-listcenter ] ); - distOK = is_def(n) || (min(distances)>=0 && max(distances)<=length); - assert(distOK,"Cannot fit all of the copies"); + distOK = min(distances)>=0 && max(distances)<=length; + dummy = assert(distOK,"Cannot fit all of the copies"); cutlist = path_cut_points(path, distances, closed, direction=true); planar = len(path[0])==2; for(i=[0:1:len(cutlist)-1]) { diff --git a/drawing.scad b/drawing.scad index 9949c61..92ec973 100644 --- a/drawing.scad +++ b/drawing.scad @@ -220,16 +220,17 @@ module stroke( ) * linewidth; closed = default(closed, is_region(path)); - assert(is_bool(closed)); + check1 = assert(is_bool(closed)); dots = dots==true? "dot" : dots; endcap1 = first_defined([endcap1, endcaps, dots, "round"]); endcap2 = first_defined([endcap2, endcaps, if (!closed) dots, "round"]); joints = first_defined([joints, dots, "round"]); - assert(is_bool(endcap1) || is_string(endcap1) || is_path(endcap1)); - assert(is_bool(endcap2) || is_string(endcap2) || is_path(endcap2)); - assert(is_bool(joints) || is_string(joints) || is_path(joints)); + check2 = + assert(is_bool(endcap1) || is_string(endcap1) || is_path(endcap1)) + assert(is_bool(endcap2) || is_string(endcap2) || is_path(endcap2)) + assert(is_bool(joints) || is_string(joints) || is_path(joints)); endcap1_dflts = _shape_defaults(endcap1); endcap2_dflts = _shape_defaults(endcap2); @@ -238,47 +239,47 @@ module stroke( endcap_width1 = first_defined([endcap_width1, endcap_width, dots_width, endcap1_dflts[0]]); endcap_width2 = first_defined([endcap_width2, endcap_width, dots_width, endcap2_dflts[0]]); joint_width = first_defined([joint_width, dots_width, joint_dflts[0]]); - assert(is_num(endcap_width1)); - assert(is_num(endcap_width2)); - assert(is_num(joint_width)); + check3 = + assert(is_num(endcap_width1)) + assert(is_num(endcap_width2)) + assert(is_num(joint_width)); endcap_length1 = first_defined([endcap_length1, endcap_length, dots_length, endcap1_dflts[1]*endcap_width1]); endcap_length2 = first_defined([endcap_length2, endcap_length, dots_length, endcap2_dflts[1]*endcap_width2]); joint_length = first_defined([joint_length, dots_length, joint_dflts[1]*joint_width]); - assert(is_num(endcap_length1)); - assert(is_num(endcap_length2)); - assert(is_num(joint_length)); + check4 = + assert(is_num(endcap_length1)) + assert(is_num(endcap_length2)) + assert(is_num(joint_length)); endcap_extent1 = first_defined([endcap_extent1, endcap_extent, dots_extent, endcap1_dflts[2]*endcap_width1]); endcap_extent2 = first_defined([endcap_extent2, endcap_extent, dots_extent, endcap2_dflts[2]*endcap_width2]); joint_extent = first_defined([joint_extent, dots_extent, joint_dflts[2]*joint_width]); - assert(is_num(endcap_extent1)); - assert(is_num(endcap_extent2)); - assert(is_num(joint_extent)); + check5 = + assert(is_num(endcap_extent1)) + assert(is_num(endcap_extent2)) + assert(is_num(joint_extent)); endcap_angle1 = first_defined([endcap_angle1, endcap_angle, dots_angle]); endcap_angle2 = first_defined([endcap_angle2, endcap_angle, dots_angle]); joint_angle = first_defined([joint_angle, dots_angle]); - assert(is_undef(endcap_angle1)||is_num(endcap_angle1)); - assert(is_undef(endcap_angle2)||is_num(endcap_angle2)); - assert(is_undef(joint_angle)||is_num(joint_angle)); + check6 = + assert(is_undef(endcap_angle1)||is_num(endcap_angle1)) + assert(is_undef(endcap_angle2)||is_num(endcap_angle2)) + assert(is_undef(joint_angle)||is_num(joint_angle)); endcap_color1 = first_defined([endcap_color1, endcap_color, dots_color, color]); endcap_color2 = first_defined([endcap_color2, endcap_color, dots_color, color]); joint_color = first_defined([joint_color, dots_color, color]); - paths = force_region(path); - assert(is_region(paths),"The path argument must be a list of 2D or 3D points, or a region."); - for (path = paths) { - assert(is_list(path)); - if (len(path) > 1) { - assert(is_path(path,[2,3]), "The path argument must be a list of 2D or 3D points, or a region."); - } + check7 = assert(is_region(paths),"The path argument must be a list of 2D or 3D points, or a region."); + for (path = paths) { + assert(len(path)==1 || is_path(path,[2,3]), "The path argument must be a list of 2D or 3D points, or a region."); path = deduplicate( closed? close_path(path) : path ); - assert(is_num(width) || (is_vector(width) && len(width)==len(path))); + check8 = assert(is_num(width) || (is_vector(width) && len(width)==len(path))); width = is_num(width)? [for (x=path) width] : width; - assert(all([for (w=width) w>0])); + check9 = assert(all([for (w=width) w>0])); endcap_shape1 = _shape_path(endcap1, width[0], endcap_width1, endcap_length1, endcap_extent1); endcap_shape2 = _shape_path(endcap2, last(width), endcap_width2, endcap_length2, endcap_extent2); @@ -289,7 +290,7 @@ module stroke( (endcap1=="arrow2")? endcap_length1*3/4 : 0 ]); - assert(is_num(trim1)); + check10 = assert(is_num(trim1)); trim2 = last(width) * first_defined([ trim2, trim, @@ -297,7 +298,7 @@ module stroke( (endcap2=="arrow2")? endcap_length2*3/4 : 0 ]); - assert(is_num(trim2)); + check11 = assert(is_num(trim2)); if (len(path) == 1) { diff --git a/geometry.scad b/geometry.scad index 07cc898..1ddfd8d 100644 --- a/geometry.scad +++ b/geometry.scad @@ -452,7 +452,8 @@ function is_coplanar(points, eps=EPSILON) = // p2 = The second point on the plane. // p3 = The third point on the plane. function plane3pt(p1, p2, p3) = - assert( is_path([p1,p2,p3],dim=3) && len(p1)==3, + is_undef(p2) && is_undef(p3) && is_path(p1,dim=3) ? plane3pt(p1[0],p1[1],p1[2]) + : assert( is_path([p1,p2,p3],dim=3) && len(p1)==3, "Invalid points or incompatible dimensions." ) let( crx = cross(p3-p1, p2-p1), @@ -476,6 +477,8 @@ function plane3pt(p1, p2, p3) = // i2 = The index into `points` of the second point on the plane. // i3 = The index into `points` of the third point on the plane. function plane3pt_indexed(points, i1, i2, i3) = + is_undef(i3) && is_undef(i2) && is_vector(i1) ? plane3pt_indexed(points, i1[0], i1[1], i1[2]) + : assert( is_vector([i1,i2,i3]) && min(i1,i2,i3)>=0 && is_list(points) && max(i1,i2,i3)=3, "Point list must contain 3 points") + check = assert(is_path(points)) + assert(len(points)>=3, "Point list must contain 3 points"); if (len(points[0])==2) hull() polygon(points=points); else { diff --git a/joiners.scad b/joiners.scad index 7ecbd92..4bfc9ca 100644 --- a/joiners.scad +++ b/joiners.scad @@ -625,12 +625,13 @@ module dovetail(gender, width, height, slide, h, w, angle, slope, thickness, tap orient = is_def(orient) ? orient : gender == "female" ? DOWN : UP; + dummy = + assert(count<=1, "Do not specify both angle and slope") + assert(count2<=1, "Do not specify both taper and back_width") + assert(count3<=1 || (radius==0 && chamfer==0), "Do not specify both chamfer and radius"); count = num_defined([angle,slope]); - assert(count<=1, "Do not specify both angle and slope"); count2 = num_defined([taper,back_width]); - assert(count2<=1, "Do not specify both taper and back_width"); count3 = num_defined([chamfer, radius]); - assert(count3<=1 || (radius==0 && chamfer==0), "Do not specify both chamfer and radius"); slope = is_def(slope) ? slope : is_def(angle) ? 1/tan(angle) : 6; extra_slop = gender == "female" ? 2*get_slop() : 0; @@ -1047,17 +1048,17 @@ function rabbit_clip(type, length, width, snap, thickness, depth, compression=0 module rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1, clearance=.1, lock=false, lock_clearance=0, splinesteps=8, anchor, orient, spin=0) { - assert(is_num(width) && width>0,"Width must be a positive value"); - assert(is_num(length) && length>0, "Length must be a positive value"); - assert(is_num(thickness) && thickness>0, "Thickness must be a positive value"); - assert(is_num(snap) && snap>=0, "Snap must be a non-negative value"); - assert(is_num(depth) && depth>0, "Depth must be a positive value"); - assert(is_num(compression) && compression >= 0, "Compression must be a nonnegative value"); - assert(is_bool(lock)); - assert(is_num(lock_clearance)); legal_types = ["pin","socket","male","female","double"]; - assert(in_list(type,legal_types),str("type must be one of ",legal_types)); - + check = + assert(is_num(width) && width>0,"Width must be a positive value") + assert(is_num(length) && length>0, "Length must be a positive value") + assert(is_num(thickness) && thickness>0, "Thickness must be a positive value") + assert(is_num(snap) && snap>=0, "Snap must be a non-negative value") + assert(is_num(depth) && depth>0, "Depth must be a positive value") + assert(is_num(compression) && compression >= 0, "Compression must be a nonnegative value") + assert(is_bool(lock)) + assert(is_num(lock_clearance)) + assert(in_list(type,legal_types),str("type must be one of ",legal_types)); if (type=="double") { attachable(size=[width+2*compression, depth, 2*length], anchor=default(anchor,BACK), spin=spin, orient=default(orient,BACK)){ union(){ @@ -1100,7 +1101,7 @@ module rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1 [bottom_pt], reverse(apply(xflip(),sidepath)) ); - assert(fullpath[4].y < fullpath[3].y, "Pin is too wide for its length"); + dummy2 = assert(fullpath[4].y < fullpath[3].y, "Pin is too wide for its length"); snapmargin = -snap + last(sidepath).x;// - compression; if (is_pin){ diff --git a/masks3d.scad b/masks3d.scad index 74d4b8d..db9e046 100644 --- a/masks3d.scad +++ b/masks3d.scad @@ -471,15 +471,16 @@ module rounding_hole_mask(r, rounding, excess=0.1, d, anchor=CENTER, spin=0, ori // Module: teardrop_edge_mask() // Usage: -// teardrop_edge_mask(r|d=, [angle], [excess]); +// teardrop_edge_mask(l, r|d=, [angle], [excess], [anchor], [spin], [orient]) [ATTACHMENTS]; // Description: // Makes an apropriate 3D corner rounding mask that keeps within `angle` degrees of vertical. // Arguments: +// l = length of mask // r = Radius of the mask rounding. -// d = Diameter of the mask rounding. // angle = Maximum angle from vertical. Default: 45 // excess = Excess mask size. Default: 0.1 // --- +// d = Diameter of the mask rounding. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` @@ -496,10 +497,10 @@ module rounding_hole_mask(r, rounding, excess=0.1, d, anchor=CENTER, spin=0, ori function teardrop_edge_mask(l, r, angle, excess=0.1, d, anchor, spin, orient) = no_function("teardrop_edge_mask"); module teardrop_edge_mask(l, r, angle, excess=0.1, d, anchor=CTR, spin=0, orient=UP) { - assert(is_num(l)); - assert(is_num(angle)); - assert(is_num(excess)); - assert(angle>0 && angle<90); + check = + assert(is_num(l) && l>0, "Length of mask must be positive") + assert(is_num(angle) && angle>0 && angle<90, "Angle must be a number between 0 and 90") + assert(is_num(excess)); r = get_radius(r=r, d=d, dflt=1); path = mask2d_teardrop(r=r, angle=angle, excess=excess); linear_sweep(path, height=l, center=true, atype="bbox", anchor=anchor, spin=spin, orient=orient) children(); @@ -508,7 +509,7 @@ module teardrop_edge_mask(l, r, angle, excess=0.1, d, anchor=CTR, spin=0, orient // Module: teardrop_corner_mask() // Usage: -// teardrop_corner_mask(r|d=, [angle], [excess]); +// teardrop_corner_mask(r|d=, [angle], [excess], [anchor], [spin], [orient]) [ATTACHMENTS]; // Description: // Makes an apropriate 3D corner rounding mask that keeps within `angle` degrees of vertical. // Arguments: diff --git a/modular_hose.scad b/modular_hose.scad index 954e527..c07fb50 100644 --- a/modular_hose.scad +++ b/modular_hose.scad @@ -163,7 +163,7 @@ module modular_hose(size, type, clearance=0, waist_len, anchor=BOTTOM, spin=0,or bigend = move([clearance[1], -bbound[0].y], p=_big_end[ind]); midlength = first_defined([waist_len, _hose_waist[ind]]); - assert(midlength>=0,"midlength must be nonnegative"); + dummy = assert(midlength>=0,"midlength must be nonnegative"); goodtypes = ["small","big","segment","socket","ball"]; shape = diff --git a/mutators.scad b/mutators.scad index 005755a..c370daa 100644 --- a/mutators.scad +++ b/mutators.scad @@ -196,13 +196,14 @@ module chain_hull() // circle(r=1.5); module path_extrude2d(path, caps=false, closed=false, s, convexity=10) { extra_ang = 0.1; // Extra angle for overlap of joints - assert(caps==false || closed==false, "Cannot have caps on a closed extrusion"); - assert(is_path(path,2)); + check = + assert(caps==false || closed==false, "Cannot have caps on a closed extrusion") + assert(is_path(path,2)); path = deduplicate(path); s = s!=undef? s : let(b = pointlist_bounds(path)) norm(b[1]-b[0]); - assert(is_finite(s)); + check2 = assert(is_finite(s)); L = len(path); for (i = [0:1:L-(closed?1:2)]) { seg = select(path, i, i+1); @@ -286,15 +287,15 @@ module path_extrude2d(path, caps=false, closed=false, s, convexity=10) { // cylindrical_extrude(or=40, ir=35, orient=BACK) // text(text="Hello World!", size=10, halign="center", valign="center"); module cylindrical_extrude(ir, or, od, id, size=1000, convexity=10, spin=0, orient=UP) { - assert(is_num(size) || is_vector(size,2)); + check1 = assert(is_num(size) || is_vector(size,2)); size = is_num(size)? [size,size] : size; ir = get_radius(r=ir,d=id); or = get_radius(r=or,d=od); - assert(all_positive([ir,or]), "Must supply positive inner and outer radius or diameter"); + check2 = assert(all_positive([ir,or]), "Must supply positive inner and outer radius or diameter"); index_r = or; circumf = 2 * PI * index_r; width = min(size.x, circumf); - assert(width <= circumf, "Shape would more than completely wrap around."); + check3 = assert(width <= circumf, "Shape would more than completely wrap around."); sides = segs(or); step = circumf / sides; steps = ceil(width / step); @@ -338,8 +339,9 @@ module cylindrical_extrude(ir, or, od, id, size=1000, convexity=10, spin=0, orie // xcopies(3) circle(3, $fn=32); // } module extrude_from_to(pt1, pt2, convexity, twist, scale, slices) { - assert(is_vector(pt1)); - assert(is_vector(pt2)); + check = + assert(is_vector(pt1),"First point must be a vector") + assert(is_vector(pt2),"Second point must be a vector"); pt1 = point3d(pt1); pt2 = point3d(pt2); rtp = xyz_to_spherical(pt2-pt1); diff --git a/polyhedra.scad b/polyhedra.scad index 45331fb..4c85e21 100644 --- a/polyhedra.scad +++ b/polyhedra.scad @@ -308,7 +308,7 @@ module regular_polyhedron( longside=undef, // special parameter for trapezohedron h=undef // special parameter for trapezohedron ) { - assert(rounding>=0, "'rounding' must be nonnegative"); + dummy=assert(is_num(rounding) && rounding>=0, "'rounding' must be nonnegative"); entry = regular_polyhedron_info( "fullentry", name=name, index=index, type=type, faces=faces, facetype=facetype, diff --git a/rounding.scad b/rounding.scad index dc7c9bb..d231324 100644 --- a/rounding.scad +++ b/rounding.scad @@ -1850,15 +1850,14 @@ module convex_offset_extrude( top_height = len(offsets_top)==0 ? 0 : abs(last(offsets_top)[1]) - struct_val(top,"extra"); height = one_defined([l,h,height,length], "l,h,height,length", dflt=u_add(bottom_height,top_height)); - assert(height>=0, "Height must be nonnegative"); - middle = height-bottom_height-top_height; - assert( - middle>=0, str( - "Specified end treatments (bottom height = ",bottom_height, - " top_height = ",top_height,") are too large for extrusion height (",height,")" - ) - ); + check = + assert(height>=0, "Height must be nonnegative") + assert(middle>=0, str( + "Specified end treatments (bottom height = ",bottom_height, + " top_height = ",top_height,") are too large for extrusion height (",height,")" + ) + ); // The entry r[i] is [radius,z] for a given layer r = move([0,bottom_height],p=concat( reverse(offsets_bot), [[0,0], [0,middle]], move([0,middle], p=offsets_top))); @@ -2453,9 +2452,9 @@ module bent_cutout_mask(r, thickness, path, radius, convexity=10) r = get_radius(r1=r, r2=radius); dummy1=assert(is_def(r) && r>0,"Radius of the cylinder to bend around must be positive"); path2 = force_path(path); - dummy2=assert(is_path(path2,2),"Input path must be a 2D path"); - assert(r-thickness>0, "Thickness too large for radius"); - assert(thickness>0, "Thickness must be positive"); + dummy2=assert(is_path(path2,2),"Input path must be a 2D path") + assert(r-thickness>0, "Thickness too large for radius") + assert(thickness>0, "Thickness must be positive"); fixpath = clockwise_polygon(path2); curvepoints = arc(d=thickness, angle = [-180,0]); profiles = [for(pt=curvepoints) _cyl_hole(r+pt.x,apply(xscale((r+pt.x)/r), offset(fixpath,delta=thickness/2+pt.y,check_valid=false,closed=true)))]; @@ -2463,7 +2462,7 @@ module bent_cutout_mask(r, thickness, path, radius, convexity=10) minangle = (min(pathx)-thickness/2)*360/(2*PI*r); maxangle = (max(pathx)+thickness/2)*360/(2*PI*r); mindist = (r+thickness/2)/cos((maxangle-minangle)/2); - assert(maxangle-minangle<180,"Cutout angle span is too large. Must be smaller than 180."); + dummy3 = assert(maxangle-minangle<180,"Cutout angle span is too large. Must be smaller than 180."); zmean = mean(column(fixpath,1)); innerzero = repeat([0,0,zmean], len(fixpath)); outerpt = repeat( [1.5*mindist*cos((maxangle+minangle)/2),1.5*mindist*sin((maxangle+minangle)/2),zmean], len(fixpath)); diff --git a/skin.scad b/skin.scad index ee540a4..13becab 100644 --- a/skin.scad +++ b/skin.scad @@ -3607,7 +3607,7 @@ module _textured_revolution( convexity=10, counts, samples, anchor=CENTER, spin=0, orient=UP ) { - assert(in_list(atype, _ANCHOR_TYPES), "Anchor type must be \"hull\" or \"intersect\""); + dummy = assert(in_list(atype, _ANCHOR_TYPES), "Anchor type must be \"hull\" or \"intersect\""); vnf = _textured_revolution( shape, texture, tex_size=tex_size, tex_scale=tex_scale, inset=inset, rot=rot, diff --git a/threading.scad b/threading.scad index 5c01c00..f1e0bd4 100644 --- a/threading.scad +++ b/threading.scad @@ -606,12 +606,13 @@ module npt_threaded_rod( internal=false, anchor, spin, orient ) { - assert(is_finite(size)); - assert(is_bool(left_handed)); - assert(is_undef(bevel) || is_bool(bevel)); - assert(is_bool(hollow)); - assert(is_bool(internal)); - assert(!(internal&&hollow), "Cannot created a hollow internal threads mask."); + checks = + assert(is_finite(size)) + assert(is_bool(left_handed)) + assert(is_undef(bevel) || is_bool(bevel)) + assert(is_bool(hollow)) + assert(is_bool(internal)) + assert(!(internal&&hollow), "Cannot created a hollow internal threads mask."); info_table = [ // Size len OD TPI [ 1/16, [ 0.3896, 0.308, 27 ]],