[OpenSCAD] flattening mixed lists of lists

kitwallace kit.wallace at gmail.com
Mon Apr 13 02:54:07 EDT 2015


Hi Doug

The code is here -
https://github.com/KitWallace/openscad/blob/master/poly_nets.scad

faces are constructed in function rrp (line 234) as a nested list and
flattened in fold_render(line 256) using function dflatten()

The context of the code is described in my blog - basically  it generates
nets of solids and folds them

http://kitwallace.tumblr.com/post/115973599619/polyhedral-nets

Chris


On Sun, Apr 12, 2015 at 5:26 PM, doug.moen [via OpenSCAD] <
ml-node+s1091067n12350h42 at n5.nabble.com> wrote:

> Kit, could you show your code that generates the face list?
>
> I'd like to see it, because I'm considering an extension to list
> comprehensions that would eliminate the need to use 'flatten'
> functions for post processing. I'd like to see if my proposed
> extension works for your code.
>
> Doug Moen
>
> On 06/04/2015, kitwallace <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=12350&i=0>> wrote:
>
> > 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.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email] <http:///user/SendEmail.jtp?type=node&node=12350&i=1>
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://forum.openscad.org/flattening-mixed-lists-of-lists-tp12316p12350.html
>  To unsubscribe from flattening mixed lists of lists, click here
> <http://forum.openscad.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=12316&code=a2l0LndhbGxhY2VAZ21haWwuY29tfDEyMzE2fDE3Nzk2Mzg2MzQ=>
> .
> NAML
> <http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://forum.openscad.org/flattening-mixed-lists-of-lists-tp12316p12352.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/20150412/74df5911/attachment-0002.html>


More information about the Discuss mailing list