Strange error message

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange error message

zapta
The code below is a reduction of a larger program that still preserves the error. If I compile it I get the following error:

Compiling design (CSG Tree generation)...
ERROR: Recursion detected calling function 'sqrt'
Rendering Polygon Mesh using CGAL...
WARNING: No top level geometry to render

If I change the 90 or 4 in the first line to any other number (e.g. 80/5) it does work as expected and prints the "ww" echo.

I am using OpenSCAD version 2015.03-3 on Max OSX 10.12.4.

Anybody else can reproduce it?

Thanks

--

===========


slices = max(10, 90/4);  // changing the 90 or 4 'fixes' the problem
height = 100;
d1 = 21;
d2 = 30;
dr = (d2-d1)/2;
R = (dr*dr + height*height/4) / (2 * dr);

function radius_at_height(h) =
  let (dz = (h - height/2))
  (d2/2 - (R - sqrt(R*R - dz*dz)));  

function contour_points(extra_r, i=0) =
  let(h = i * height / slices)
  let(r = radius_at_height(h) + extra_r)
  (i == slices)
    ?  [[r, h]]
    :  concat([[r, h]], contour_points(extra_r, i+1));

echo("ww", contour_points(0));
Reply | Threaded
Open this post in threaded view
|

Re: Strange error message

MichaelAtOz
Administrator
Because 90/4 is not an integer, so you compare slices==i (an integer) it wont match.
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Strange error message

MichaelAtOz
Administrator
Did I get a face palm???
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: Strange error message

zapta
In reply to this post by MichaelAtOz
Yes, that's it. Thanks Michael.

BTW, sqrt is not recursive. I presume this is where it hit the stack limit. A clearer message would be to report the deepest method in the stack that has reoccurring appearances.
Reply | Threaded
Open this post in threaded view
|

Re: Strange error message

MichaelAtOz
Administrator
The error showed 'radius_at_height' for me.
I don't know how easy it would be to examine the stack.
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!