[OpenSCAD] recursion limit on concat()

kitwallace kit.wallace at gmail.com
Mon Oct 14 09:07:53 EDT 2019


I have a function for generating a sequence of points from an L-System
string, such as might be used to define a Dragon curve.

The function itself is tail-recursive but blows up on recursion calling
concat()  -  it fails with list ps length somewhere between 2k and 4k

Anyone able to suggest a work-around?

function string_to_points(s,step=1,angle=90,pos=[0,0,0],dir=0,i=0,ps=[]) =
    i == len(s)
      ? concat([pos],ps)
      : let(c=s[i])
        let(newpos =
          c=="F" ||c=="A" || c=="B"
            ? pos + step*[cos(dir), sin(dir)]
            : pos)
        let(newdir =
            c=="+" 
             ? dir + angle
            : c=="-"
              ? dir - angle
              : dir)
        
        string_to_points(s,step,angle,newpos,newdir,i+1,concat([pos],ps)) 
     ;

Kit



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



More information about the Discuss mailing list