diff --git a/src/main/scad/puzzlecad/puzzlecad-burr.scad b/src/main/scad/puzzlecad/puzzlecad-burr.scad index f38d8d0..992b8b5 100644 --- a/src/main/scad/puzzlecad/puzzlecad-burr.scad +++ b/src/main/scad/puzzlecad/puzzlecad-burr.scad @@ -267,7 +267,7 @@ module burr_piece_base(burr_spec, test_poly = undef) { // If the facing cell *is* defined but is from a different component, then // we need to render a space-filler. - if (lookup3(burr, facing_cell) > 0 && lookup3(burr, facing_cell) != lookup3(burr, cell)) { + if (is_nonzero(lookup3(burr, facing_cell)) && lookup3(burr, facing_cell) != lookup3(burr, cell)) { // Space-filler is 2*insets wide in the facing direction, and (scale - 2*insets - bevel/2) // in the orthogonal directions. This ensures that the corners exactly meet the bevel line @@ -283,9 +283,9 @@ module burr_piece_base(burr_spec, test_poly = undef) { // duplicates. if (face < 5) for (other_face=[face+1:5]) { - if (lookup3(burr, facing_cell) > 0 && - lookup3(burr, cell + directions[other_face]) > 0 && - lookup3(burr, facing_cell + directions[other_face]) > 0 && + if (is_nonzero(lookup3(burr, facing_cell)) && + is_nonzero(lookup3(burr, cell + directions[other_face])) && + is_nonzero(lookup3(burr, facing_cell + directions[other_face])) && ( lookup3(burr, facing_cell) != lookup3(burr, cell) || lookup3(burr, cell + directions[other_face]) != lookup3(burr, cell) || lookup3(burr, facing_cell + directions[other_face]) != lookup3(burr, cell) diff --git a/src/main/scad/puzzlecad/puzzlecad-layout.scad b/src/main/scad/puzzlecad/puzzlecad-layout.scad index 43742dd..e601170 100644 --- a/src/main/scad/puzzlecad/puzzlecad-layout.scad +++ b/src/main/scad/puzzlecad/puzzlecad-layout.scad @@ -172,8 +172,8 @@ function auto_layout_joints(layers, next_joint_letter, z, type) = function is_joint_location(layers, offset, x, y, z) = layers[z][y][x][0] > 0 && layers[z + offset][y][x][0] > 0 && - !(layers[z][y-1][x][0] > 0 && layers[z][y+1][x][0] > 0 && layers[z + offset][y-1][x][0] > 0 && layers[z + offset][y+1][x][0] > 0) && - !(layers[z][y][x-1][0] > 0 && layers[z][y][x+1][0] > 0 && layers[z + offset][y][x-1][0] > 0 && layers[z + offset][y][x+1][0] > 0); + !(is_nonzero(layers[z][y-1][x][0]) && is_nonzero(layers[z][y+1][x][0]) && is_nonzero(layers[z + offset][y-1][x][0]) && is_nonzero(layers[z + offset][y+1][x][0])) && + !(is_nonzero(layers[z][y][x-1][0]) && is_nonzero(layers[z][y][x+1][0]) && is_nonzero(layers[z + offset][y][x-1][0]) && is_nonzero(layers[z + offset][y][x+1][0])); function to_blank_layer(layer) = [ for (yslice = layer) diff --git a/src/main/scad/puzzlecad/puzzlecad-polyhedra.scad b/src/main/scad/puzzlecad/puzzlecad-polyhedra.scad index 86c7957..0f6a24e 100644 --- a/src/main/scad/puzzlecad/puzzlecad-polyhedra.scad +++ b/src/main/scad/puzzlecad/puzzlecad-polyhedra.scad @@ -413,6 +413,7 @@ function has_beveling() = !is_undef($burr_bevel_adjustments); function is_positive_bevel(bevel) = + is_undef(bevel) ? undef : let (bevel_or_pair = to_2_vector(bevel)) bevel_or_pair[0] >= 0.01 || bevel_or_pair[1] >= 0.01; diff --git a/src/main/scad/puzzlecad/puzzlecad-util.scad b/src/main/scad/puzzlecad/puzzlecad-util.scad index e6dca75..7de3695 100644 --- a/src/main/scad/puzzlecad/puzzlecad-util.scad +++ b/src/main/scad/puzzlecad/puzzlecad-util.scad @@ -257,6 +257,9 @@ function union_of_number_lists(list1, list2, i = 0, j = 0) = /***** Misc *****/ +// Returns true if x is defined and not equal to 0. +function is_nonzero(x) = !is_undef(x) && x != 0; + function argmin(list, i = 0, cur_argmin = undef, cur_min = undef) = i >= len(list) ? cur_argmin : is_undef(cur_argmin) || list[i] < cur_min ? argmin(list, i + 1, i, list[i])