Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

puzzlecad-examples error #67

Open
Hickname opened this issue Mar 11, 2023 · 1 comment
Open

puzzlecad-examples error #67

Hickname opened this issue Mar 11, 2023 · 1 comment

Comments

@Hickname
Copy link

Hickname commented Mar 11, 2023

In puzzlecad-examples.scad in the box section we have following example:

// packing_box is also useful for modeling certain obstructed tray puzzles, by setting $burr_scale
// to a vector. Here's the tray from Coffin's Fourteen Steps. Notice how $box_wall_thickness and
// $box_inset are also vectors, in order to provide fine-grained control over the dimensions and
// tolerances.
*packing_box([
    "xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx",
    "xxxxxxx|x.....x|x.....x|x.....x|x.....x|x.....x|xxxxxxx",
    "xxxxxxx|x++...x|x+++..x|x+++..x|x+++++x|x+++++x|xxxxxxx"
], $burr_scale = [16, 16, 5.6], $box_wall_thickness = [8, 8, 3],
   $box_inset = [0.07, 0.07, 0.3], $plate_width = 200, $auto_layout = true);

It gives the following error: [ERROR: Assertion 'is_num($burr_inset)' failed: "$burr_inset must be a scalar." in file puzzlecad/puzzlecad-burr.scad, line 154]

@wesleyanderson
Copy link

wesleyanderson commented Dec 23, 2023

I am new to puzzlecad, and I only have a little experience with scad, but I've been a professional developer for a couple decades, so I thought I would dig into this a bit. Hopefully this will help resolve this issue or at least provide a workaround for others trying to get the examples to work.

The following might be a workaround, at least for the examples.
Including $box_cutout_inset = 0.07 as a parameter on the packing_box call in puzzlecad-examples.scad (see below), makes the example run successfully. I do not know if this is useful in practice (i.e. in a puzzle model that you want to 3D-print), or if it just makes the example work.
packing_box([ "xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx", "xxxxxxx|x.....x|x.....x|x.....x|x.....x|x.....x|xxxxxxx", "xxxxxxx|x++...x|x+++..x|x+++..x|x+++++x|x+++++x|xxxxxxx" ], $burr_scale = [16, 16, 5.6], $box_wall_thickness = [8, 8, 3], $box_inset = [0.07, 0.07, 0.3], $box_cutout_inset = 0.07, $plate_width = 200, $auto_layout = true);

TLDR:
This was my analysis.

Following the stack-trace, in puzzlecad-boxes.scad (line 351) I see
burr_piece_base(burr_info, $burr_inset = is_undef($box_cutout_inset) ? $box_inset : $box_cutout_inset);

And from the puzzlecad-examples.scad (line 495-500)
packing_box([ "xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx|xxxxxxx", "xxxxxxx|x.....x|x.....x|x.....x|x.....x|x.....x|xxxxxxx", "xxxxxxx|x++...x|x+++..x|x+++..x|x+++++x|x+++++x|xxxxxxx" ], $burr_scale = [16, 16, 5.6], $box_wall_thickness = [8, 8, 3], $box_inset = [0.07, 0.07, 0.3], $plate_width = 200, $auto_layout = true);

In puzzlecad-examples.scad, the $box_inset is described as a vector, and that is the only way it is used in the examples. I see that $box_cutout_inset is set to undef (in puzzlecad.scad, line 55), and since $box_inset is a vector, it looks like $burr_inset is being set to a vector, which is not the scalar that burr_piece_base requires.

If I change line 351 in puzzlecad-boxes.scad to use the first element in $box_inset (see below), then it also does not fail, but that is unlikely to be a correct fix. All that change does is confirm that $box_inset is being used for that example and that it is a vector as expected.
burr_piece_base(burr_info, $burr_inset = is_undef($box_cutout_inset) ? $box_inset[0] : $box_cutout_inset);

I don't see anything describing $box_cutout_inset in puzzlecad-examples.scad, but the only other place I see it used in puzzlecad-boxes.scad it is passed to vectorize, so it looks like it should be (or at least can be) a scalar.

As noted above, if I include $box_cutout_inset = 0.07 in the packing_box call in puzzlecad-examples.scad, then it does not fail. It is not clear to me, though whether $box_cutout_inset is intended to be used that way or what a good default value would be (zero gives warnings) or what a correct fix would be. If I get time to dig in and understand this project better I will try to submit a pull request. I appreciate all of the work that has gone into producing this project, and I would be happy to help if I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants