limit on range in for statement

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

limit on range in for statement

kitwallace
I'm bumping into another limit - for long lists of points the following fails
with

WARNING: Bad range parameter in for statement: too many elements (12288), in
file lsystem.scad, line 69

module path(points,width,closed=false) {
   r=width/2;
   for (i=[0:len(points)-2]) {
      hull() {    
          translate(points[i]) circle(r);
          translate(points[i+1]) circle(r);
      }    
    }
    if (closed) {
      hull() {    
          translate(points[len(points)-1])
              circle(r);
          translate(points[0])
              circle(r);
      }
    }
};

A workaround is to replace the range with a vector in the for statement:

for (i=to_n(len(points)-2))

where

function to_n(n) = [for (i=0;i<=n;i=i+1) i];

but this seems clumsy
Any other ways to get past this limit - I believe it's 9999 ?

Kit



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: limit on range in for statement

nophead
Another workaround is to use a nested loop.

This is hardcoded in OpenSCAD in about half a dozen places. I should either be a preference of a much higher value. 10000 elements in a list is nothing on today's hardware. 10000 3D CSG operations on the other hand will bring CGAL to its knees.

On Tue, 15 Oct 2019 at 10:07, kitwallace <[hidden email]> wrote:
I'm bumping into another limit - for long lists of points the following fails
with

WARNING: Bad range parameter in for statement: too many elements (12288), in
file lsystem.scad, line 69

module path(points,width,closed=false) {
   r=width/2;
   for (i=[0:len(points)-2]) {
      hull() {   
          translate(points[i]) circle(r);
          translate(points[i+1]) circle(r);
      }   
    }
    if (closed) {
      hull() {   
          translate(points[len(points)-1])
              circle(r);
          translate(points[0])
              circle(r);
      }
    }
};

A workaround is to replace the range with a vector in the for statement:

for (i=to_n(len(points)-2))

where

function to_n(n) = [for (i=0;i<=n;i=i+1) i];

but this seems clumsy
Any other ways to get past this limit - I believe it's 9999 ?

Kit



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: limit on range in for statement

kitwallace
Although 2D CSG is really fast  -  16,000 hull() operations in less than a
minute with the DXF output destined for laser engraving.  




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: limit on range in for statement

nophead
Yes I think the 10000 limit comes from the days when 2D was done with CGAL and there were no list comprehensions, so everything was slow.

On Tue, 15 Oct 2019 at 10:56, kitwallace <[hidden email]> wrote:
Although 2D CSG is really fast  -  16,000 hull() operations in less than a
minute with the DXF output destined for laser engraving. 




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org