[OpenSCAD] flattening mixed lists of lists
doug at moens.org
Sun Apr 12 12:25:52 EDT 2015
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.
On 06/04/2015, kitwallace <kit.wallace at gmail.com> 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);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:
> Sent from the OpenSCAD mailing list archive at Nabble.com.
More information about the Discuss