[OpenSCAD] flattening mixed lists of lists

kitwallace kit.wallace at gmail.com
Mon Apr 6 05:52:12 EDT 2015


I'm generating faces as a list of points.  However the list of faces
comprises a mixture of faces and lists of faces.  I need to flatten this
mixed list.  So far I'm using
function depth(a) =   len(a)== undef        ? 0       :
1+depth(a[0]);function flatten(l) = [ for (a = l) for (b = a) b ] ;function
dflatten(l,d=2) =// hack to flatten mixed list and list of lists   
flatten([for (a = l) depth(a) > d ? [for (b=a) b] : [a]]); l= [ 
[[1,2],[2,3]], [[[1,2],[2,3]]] ];lf = dflatten(l);echo(len(lf),lf);
but it doesn't really work generally : d = 1 should yield 4 , not 3  I've
really struggled to come up with a correct recursive formulation.



--
View this message in context: http://forum.openscad.org/flattening-mixed-lists-of-lists-tp12316.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20150406/4731d813/attachment-0002.html>


More information about the Discuss mailing list