Skip to content

Commit 14e12d8

Browse files
assert cleanup
1 parent dbb20fa commit 14e12d8

14 files changed

+120
-106
lines changed

attachments.scad

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -465,17 +465,19 @@ module position(from)
465465
module orient(dir, anchor, spin) {
466466
req_children($children);
467467
if (!is_undef(dir)) {
468-
assert(anchor==undef, "Only one of dir= or anchor= may be given to orient()");
469-
assert(is_vector(dir));
470468
spin = default(spin, 0);
471-
assert(is_finite(spin));
469+
check =
470+
assert(anchor==undef, "Only one of dir= or anchor= may be given to orient()")
471+
assert(is_vector(dir))
472+
assert(is_finite(spin));
472473
two_d = _attach_geom_2d($parent_geom);
473474
fromvec = two_d? BACK : UP;
474475
rot(spin, from=fromvec, to=dir) children();
475476
} else {
476-
assert(dir==undef, "Only one of dir= or anchor= may be given to orient()");
477-
assert($parent_geom != undef, "No parent to orient from!");
478-
assert(is_string(anchor) || is_vector(anchor));
477+
check=
478+
assert(dir==undef, "Only one of dir= or anchor= may be given to orient()")
479+
assert($parent_geom != undef, "No parent to orient from!")
480+
assert(is_string(anchor) || is_vector(anchor));
479481
anch = _find_anchor(anchor, $parent_geom);
480482
two_d = _attach_geom_2d($parent_geom);
481483
fromvec = two_d? BACK : UP;
@@ -568,8 +570,9 @@ module attach(from, to, overlap, norot=false)
568570
module tag(tag)
569571
{
570572
req_children($children);
571-
assert(is_string(tag),"tag must be a string");
572-
assert(undef==str_find($tag," "),str("Tag string \"",$tag,"\" contains a space, which is not allowed")) ;
573+
check=
574+
assert(is_string(tag),"tag must be a string")
575+
assert(undef==str_find(tag," "),str("Tag string \"",tag,"\" contains a space, which is not allowed"));
573576
$tag = str($tag_prefix,tag);
574577
children();
575578
}
@@ -627,7 +630,7 @@ module tag(tag)
627630
module force_tag(tag)
628631
{
629632
req_children($children);
630-
assert(is_undef(tag) || is_string(tag),"tag must be a string");
633+
check1=assert(is_undef(tag) || is_string(tag),"tag must be a string");
631634
$tag = str($tag_prefix,default(tag,$tag));
632635
assert(undef==str_find($tag," "),str("Tag string \"",$tag,"\" contains a space, which is not allowed"));
633636
if(_is_shown())
@@ -710,6 +713,7 @@ module tag_scope(scope){
710713
req_children($children);
711714
scope = is_undef(scope) ? rand_str(20) : scope;
712715
assert(is_string(scope), "scope must be a string");
716+
assert(undef==str_find(scope," "),str("Scope string \"",scope,"\" contains a space, which is not allowed"));
713717
$tag_prefix=scope;
714718
children();
715719
}
@@ -1206,7 +1210,7 @@ module tag_conv_hull(tag,keep="keep")
12061210
module hide(tags)
12071211
{
12081212
req_children($children);
1209-
assert(is_string(tags), "tags must be a string");
1213+
dummy=assert(is_string(tags), "tags must be a string");
12101214
taglist = [for(s=str_split(tags," ",keep_nulls=false)) str($tag_prefix,s)];
12111215
$tags_hidden = concat($tags_hidden,taglist);
12121216
children();
@@ -1233,7 +1237,7 @@ module hide(tags)
12331237
module show_only(tags)
12341238
{
12351239
req_children($children);
1236-
assert(is_string(tags), str("tags must be a string",tags));
1240+
dummy=assert(is_string(tags), str("tags must be a string",tags));
12371241
taglist = [for(s=str_split(tags," ",keep_nulls=false)) str($tag_prefix,s)];
12381242
$tags_shown = taglist;
12391243
children();
@@ -1270,7 +1274,7 @@ module show_all()
12701274
module show_int(tags)
12711275
{
12721276
req_children($children);
1273-
assert(is_string(tags), str("tags must be a string",tags));
1277+
dummy=assert(is_string(tags), str("tags must be a string",tags));
12741278
taglist = [for(s=str_split(tags," ",keep_nulls=false)) str($tag_prefix,s)];
12751279
$tags_shown = $tags_shown == "ALL" ? taglist : set_intersection($tags_shown,taglist);
12761280
children();
@@ -1321,7 +1325,7 @@ module edge_mask(edges=EDGES_ALL, except=[]) {
13211325
];
13221326
for (vec = vecs) {
13231327
vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0);
1324-
assert(vcount == 2, "Not an edge vector!");
1328+
dummy=assert(vcount == 2, "Not an edge vector!");
13251329
anch = _find_anchor(vec, $parent_geom);
13261330
$attach_to = undef;
13271331
$attach_anchor = anch;
@@ -1369,7 +1373,7 @@ module corner_mask(corners=CORNERS_ALL, except=[]) {
13691373
vecs = [for (i = [0:7]) if (corners[i]>0) CORNER_OFFSETS[i]];
13701374
for (vec = vecs) {
13711375
vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0);
1372-
assert(vcount == 3, "Not an edge vector!");
1376+
dummy=assert(vcount == 3, "Not an edge vector!");
13731377
anch = _find_anchor(vec, $parent_geom);
13741378
$attach_to = undef;
13751379
$attach_anchor = anch;
@@ -1452,7 +1456,7 @@ module edge_profile(edges=EDGES_ALL, except=[], convexity=10) {
14521456
];
14531457
for (vec = vecs) {
14541458
vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0);
1455-
assert(vcount == 2, "Not an edge vector!");
1459+
dummy=assert(vcount == 2, "Not an edge vector!");
14561460
anch = _find_anchor(vec, $parent_geom);
14571461
$attach_to = undef;
14581462
$attach_anchor = anch;
@@ -1509,7 +1513,7 @@ module corner_profile(corners=CORNERS_ALL, except=[], r, d, convexity=10) {
15091513
vecs = [for (i = [0:7]) if (corners[i]>0) CORNER_OFFSETS[i]];
15101514
for (vec = vecs) {
15111515
vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0);
1512-
assert(vcount == 3, "Not an edge vector!");
1516+
dummy=assert(vcount == 3, "Not an edge vector!");
15131517
anch = _find_anchor(vec, $parent_geom);
15141518
$attach_to = undef;
15151519
$attach_anchor = anch;
@@ -2705,7 +2709,7 @@ function _standard_anchors(two_d=false) = [
27052709
// Example(FlatSpin,VPD=333):
27062710
// cube(50, center=true) show_anchors();
27072711
module show_anchors(s=10, std=true, custom=true) {
2708-
check = assert($parent_geom != undef) 1;
2712+
check = assert($parent_geom != undef);
27092713
two_d = _attach_geom_2d($parent_geom);
27102714
if (std) {
27112715
for (anchor=_standard_anchors(two_d=two_d)) {

beziers.scad

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,9 +1424,10 @@ function bezier_patch_normals(patch, u, v) =
14241424
// debug_bezier(bez, N=3, width=0.5);
14251425
module debug_bezier(bezpath, width=1, N=3) {
14261426
no_children($children);
1427-
assert(is_path(bezpath));
1428-
assert(is_int(N));
1429-
assert(len(bezpath)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1."));
1427+
check =
1428+
assert(is_path(bezpath),"bezpath must be a path")
1429+
assert(is_int(N) && N>0, "N must be a positive integer")
1430+
assert(len(bezpath)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1."));
14301431
$fn=8;
14311432
stroke(bezpath_curve(bezpath, N=N), width=width, color="cyan");
14321433
color("green")

cubetruss.scad

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ module cubetruss_support(size, strut, extents=1, anchor=CENTER, spin=0, orient=U
133133
extents = is_num(extents)? [1,1,extents] : extents;
134134
size = is_undef(size)? $cubetruss_size : size;
135135
strut = is_undef(strut)? $cubetruss_strut_size : strut;
136-
assert(is_int(extents.x) && extents.x > 0);
137-
assert(is_int(extents.y) && extents.y > 0);
138-
assert(is_int(extents.z) && extents.z > 0);
136+
check =
137+
assert(is_int(extents.x) && extents.x > 0)
138+
assert(is_int(extents.y) && extents.y > 0)
139+
assert(is_int(extents.z) && extents.z > 0);
139140
w = (size-strut) * extents.x + strut;
140141
l = (size-strut) * extents.y + strut;
141142
h = (size-strut) * extents.z + strut;

distributors.scad

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ module grid2d(spacing, n, size, stagger=false, inside=undef, nonzero)
409409
module grid_copies(spacing, n, size, stagger=false, inside=undef, nonzero)
410410
{
411411
req_children($children);
412-
assert(in_list(stagger, [false, true, "alt"]));
412+
dummy = assert(in_list(stagger, [false, true, "alt"]));
413413
bounds = is_undef(inside)? undef :
414414
is_path(inside)? pointlist_bounds(inside) :
415415
assert(is_region(inside))
@@ -1035,8 +1035,8 @@ module path_copies(path, n, spacing, sp=undef, dist, rotate_children=true, dist,
10351035
sort([for(entry=ptlist) posmod(entry-listcenter,length)]) :
10361036
[for(entry=ptlist) entry + length/2-listcenter ]
10371037
);
1038-
distOK = is_def(n) || (min(distances)>=0 && max(distances)<=length);
1039-
assert(distOK,"Cannot fit all of the copies");
1038+
distOK = min(distances)>=0 && max(distances)<=length;
1039+
dummy = assert(distOK,"Cannot fit all of the copies");
10401040
cutlist = path_cut_points(path, distances, closed, direction=true);
10411041
planar = len(path[0])==2;
10421042
for(i=[0:1:len(cutlist)-1]) {

drawing.scad

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,17 @@ module stroke(
220220
) * linewidth;
221221

222222
closed = default(closed, is_region(path));
223-
assert(is_bool(closed));
223+
check1 = assert(is_bool(closed));
224224

225225
dots = dots==true? "dot" : dots;
226226

227227
endcap1 = first_defined([endcap1, endcaps, dots, "round"]);
228228
endcap2 = first_defined([endcap2, endcaps, if (!closed) dots, "round"]);
229229
joints = first_defined([joints, dots, "round"]);
230-
assert(is_bool(endcap1) || is_string(endcap1) || is_path(endcap1));
231-
assert(is_bool(endcap2) || is_string(endcap2) || is_path(endcap2));
232-
assert(is_bool(joints) || is_string(joints) || is_path(joints));
230+
check2 =
231+
assert(is_bool(endcap1) || is_string(endcap1) || is_path(endcap1))
232+
assert(is_bool(endcap2) || is_string(endcap2) || is_path(endcap2))
233+
assert(is_bool(joints) || is_string(joints) || is_path(joints));
233234

234235
endcap1_dflts = _shape_defaults(endcap1);
235236
endcap2_dflts = _shape_defaults(endcap2);
@@ -238,47 +239,47 @@ module stroke(
238239
endcap_width1 = first_defined([endcap_width1, endcap_width, dots_width, endcap1_dflts[0]]);
239240
endcap_width2 = first_defined([endcap_width2, endcap_width, dots_width, endcap2_dflts[0]]);
240241
joint_width = first_defined([joint_width, dots_width, joint_dflts[0]]);
241-
assert(is_num(endcap_width1));
242-
assert(is_num(endcap_width2));
243-
assert(is_num(joint_width));
242+
check3 =
243+
assert(is_num(endcap_width1))
244+
assert(is_num(endcap_width2))
245+
assert(is_num(joint_width));
244246

245247
endcap_length1 = first_defined([endcap_length1, endcap_length, dots_length, endcap1_dflts[1]*endcap_width1]);
246248
endcap_length2 = first_defined([endcap_length2, endcap_length, dots_length, endcap2_dflts[1]*endcap_width2]);
247249
joint_length = first_defined([joint_length, dots_length, joint_dflts[1]*joint_width]);
248-
assert(is_num(endcap_length1));
249-
assert(is_num(endcap_length2));
250-
assert(is_num(joint_length));
250+
check4 =
251+
assert(is_num(endcap_length1))
252+
assert(is_num(endcap_length2))
253+
assert(is_num(joint_length));
251254

252255
endcap_extent1 = first_defined([endcap_extent1, endcap_extent, dots_extent, endcap1_dflts[2]*endcap_width1]);
253256
endcap_extent2 = first_defined([endcap_extent2, endcap_extent, dots_extent, endcap2_dflts[2]*endcap_width2]);
254257
joint_extent = first_defined([joint_extent, dots_extent, joint_dflts[2]*joint_width]);
255-
assert(is_num(endcap_extent1));
256-
assert(is_num(endcap_extent2));
257-
assert(is_num(joint_extent));
258+
check5 =
259+
assert(is_num(endcap_extent1))
260+
assert(is_num(endcap_extent2))
261+
assert(is_num(joint_extent));
258262

259263
endcap_angle1 = first_defined([endcap_angle1, endcap_angle, dots_angle]);
260264
endcap_angle2 = first_defined([endcap_angle2, endcap_angle, dots_angle]);
261265
joint_angle = first_defined([joint_angle, dots_angle]);
262-
assert(is_undef(endcap_angle1)||is_num(endcap_angle1));
263-
assert(is_undef(endcap_angle2)||is_num(endcap_angle2));
264-
assert(is_undef(joint_angle)||is_num(joint_angle));
266+
check6 =
267+
assert(is_undef(endcap_angle1)||is_num(endcap_angle1))
268+
assert(is_undef(endcap_angle2)||is_num(endcap_angle2))
269+
assert(is_undef(joint_angle)||is_num(joint_angle));
265270

266271
endcap_color1 = first_defined([endcap_color1, endcap_color, dots_color, color]);
267272
endcap_color2 = first_defined([endcap_color2, endcap_color, dots_color, color]);
268273
joint_color = first_defined([joint_color, dots_color, color]);
269-
270274
paths = force_region(path);
271-
assert(is_region(paths),"The path argument must be a list of 2D or 3D points, or a region.");
272-
for (path = paths) {
273-
assert(is_list(path));
274-
if (len(path) > 1) {
275-
assert(is_path(path,[2,3]), "The path argument must be a list of 2D or 3D points, or a region.");
276-
}
275+
check7 = assert(is_region(paths),"The path argument must be a list of 2D or 3D points, or a region.");
276+
for (path = paths) {
277+
assert(len(path)==1 || is_path(path,[2,3]), "The path argument must be a list of 2D or 3D points, or a region.");
277278
path = deduplicate( closed? close_path(path) : path );
278279

279-
assert(is_num(width) || (is_vector(width) && len(width)==len(path)));
280+
check8 = assert(is_num(width) || (is_vector(width) && len(width)==len(path)));
280281
width = is_num(width)? [for (x=path) width] : width;
281-
assert(all([for (w=width) w>0]));
282+
check9 = assert(all([for (w=width) w>0]));
282283

283284
endcap_shape1 = _shape_path(endcap1, width[0], endcap_width1, endcap_length1, endcap_extent1);
284285
endcap_shape2 = _shape_path(endcap2, last(width), endcap_width2, endcap_length2, endcap_extent2);
@@ -289,15 +290,15 @@ module stroke(
289290
(endcap1=="arrow2")? endcap_length1*3/4 :
290291
0
291292
]);
292-
assert(is_num(trim1));
293+
check10 = assert(is_num(trim1));
293294

294295
trim2 = last(width) * first_defined([
295296
trim2, trim,
296297
(endcap2=="arrow")? endcap_length2-0.01 :
297298
(endcap2=="arrow2")? endcap_length2*3/4 :
298299
0
299300
]);
300-
assert(is_num(trim2));
301+
check11 = assert(is_num(trim2));
301302

302303

303304
if (len(path) == 1) {

geometry.scad

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ function is_coplanar(points, eps=EPSILON) =
452452
// p2 = The second point on the plane.
453453
// p3 = The third point on the plane.
454454
function plane3pt(p1, p2, p3) =
455-
assert( is_path([p1,p2,p3],dim=3) && len(p1)==3,
455+
is_undef(p2) && is_undef(p3) && is_path(p1,dim=3) ? plane3pt(p1[0],p1[1],p1[2])
456+
: assert( is_path([p1,p2,p3],dim=3) && len(p1)==3,
456457
"Invalid points or incompatible dimensions." )
457458
let(
458459
crx = cross(p3-p1, p2-p1),
@@ -476,6 +477,8 @@ function plane3pt(p1, p2, p3) =
476477
// i2 = The index into `points` of the second point on the plane.
477478
// i3 = The index into `points` of the third point on the plane.
478479
function plane3pt_indexed(points, i1, i2, i3) =
480+
is_undef(i3) && is_undef(i2) && is_vector(i1) ? plane3pt_indexed(points, i1[0], i1[1], i1[2])
481+
:
479482
assert( is_vector([i1,i2,i3]) && min(i1,i2,i3)>=0 && is_list(points) && max(i1,i2,i3)<len(points),
480483
"Invalid or out of range indices." )
481484
assert( is_path([points[i1], points[i2], points[i3]],dim=3),
@@ -2290,8 +2293,8 @@ function hull(points) =
22902293
// hull_points(pts);
22912294
module hull_points(points, fast=false) {
22922295
no_children($children);
2293-
assert(is_path(points))
2294-
assert(len(points)>=3, "Point list must contain 3 points")
2296+
check = assert(is_path(points))
2297+
assert(len(points)>=3, "Point list must contain 3 points");
22952298
if (len(points[0])==2)
22962299
hull() polygon(points=points);
22972300
else {

joiners.scad

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -625,12 +625,13 @@ module dovetail(gender, width, height, slide, h, w, angle, slope, thickness, tap
625625
orient = is_def(orient) ? orient
626626
: gender == "female" ? DOWN
627627
: UP;
628+
dummy =
629+
assert(count<=1, "Do not specify both angle and slope")
630+
assert(count2<=1, "Do not specify both taper and back_width")
631+
assert(count3<=1 || (radius==0 && chamfer==0), "Do not specify both chamfer and radius");
628632
count = num_defined([angle,slope]);
629-
assert(count<=1, "Do not specify both angle and slope");
630633
count2 = num_defined([taper,back_width]);
631-
assert(count2<=1, "Do not specify both taper and back_width");
632634
count3 = num_defined([chamfer, radius]);
633-
assert(count3<=1 || (radius==0 && chamfer==0), "Do not specify both chamfer and radius");
634635
slope = is_def(slope) ? slope :
635636
is_def(angle) ? 1/tan(angle) : 6;
636637
extra_slop = gender == "female" ? 2*get_slop() : 0;
@@ -1047,17 +1048,17 @@ function rabbit_clip(type, length, width, snap, thickness, depth, compression=0
10471048
module rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1, clearance=.1, lock=false, lock_clearance=0,
10481049
splinesteps=8, anchor, orient, spin=0)
10491050
{
1050-
assert(is_num(width) && width>0,"Width must be a positive value");
1051-
assert(is_num(length) && length>0, "Length must be a positive value");
1052-
assert(is_num(thickness) && thickness>0, "Thickness must be a positive value");
1053-
assert(is_num(snap) && snap>=0, "Snap must be a non-negative value");
1054-
assert(is_num(depth) && depth>0, "Depth must be a positive value");
1055-
assert(is_num(compression) && compression >= 0, "Compression must be a nonnegative value");
1056-
assert(is_bool(lock));
1057-
assert(is_num(lock_clearance));
10581051
legal_types = ["pin","socket","male","female","double"];
1059-
assert(in_list(type,legal_types),str("type must be one of ",legal_types));
1060-
1052+
check =
1053+
assert(is_num(width) && width>0,"Width must be a positive value")
1054+
assert(is_num(length) && length>0, "Length must be a positive value")
1055+
assert(is_num(thickness) && thickness>0, "Thickness must be a positive value")
1056+
assert(is_num(snap) && snap>=0, "Snap must be a non-negative value")
1057+
assert(is_num(depth) && depth>0, "Depth must be a positive value")
1058+
assert(is_num(compression) && compression >= 0, "Compression must be a nonnegative value")
1059+
assert(is_bool(lock))
1060+
assert(is_num(lock_clearance))
1061+
assert(in_list(type,legal_types),str("type must be one of ",legal_types));
10611062
if (type=="double") {
10621063
attachable(size=[width+2*compression, depth, 2*length], anchor=default(anchor,BACK), spin=spin, orient=default(orient,BACK)){
10631064
union(){
@@ -1100,7 +1101,7 @@ module rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1
11001101
[bottom_pt],
11011102
reverse(apply(xflip(),sidepath))
11021103
);
1103-
assert(fullpath[4].y < fullpath[3].y, "Pin is too wide for its length");
1104+
dummy2 = assert(fullpath[4].y < fullpath[3].y, "Pin is too wide for its length");
11041105

11051106
snapmargin = -snap + last(sidepath).x;// - compression;
11061107
if (is_pin){

0 commit comments

Comments
 (0)