discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] ranges to vectors

C
ctchin
Thu, Nov 12, 2015 2:09 PM

MichaelAtOz wrote

function r2v(r,index=undef) =
(index==undef)
?  r2v(r,r[0],dir=(r[0]<=r[2]) )
:  (dir && index>r[2]) || (!dir && index<r[2])
? []
: concat([index],r2v(r,index+r[1],dir=dir));

Hmm how about just

function range2vector(r) = [ for (i=r) i];

No recursion needed, seems to work just fine.  It's been in my privately
kept stdlib.scad for a while... Not that's I've found much use of it.
Ranges are peculiar indeed, but I've found little practical purpose to
manipulate ranges, other than in a for loop.

--
View this message in context: http://forum.openscad.org/ranges-to-vectors-tp7651p14404.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

MichaelAtOz wrote > function r2v(r,index=undef) = > (index==undef) > ? r2v(r,r[0],dir=(r[0]<=r[2]) ) > : (dir && index>r[2]) || (!dir && index&lt;r[2]) > ? [] > : concat([index],r2v(r,index+r[1],dir=dir)); Hmm how about just function range2vector(r) = [ for (i=r) i]; No recursion needed, seems to work just fine. It's been in my privately kept stdlib.scad for a while... Not that's I've found much use of it. Ranges are peculiar indeed, but I've found little practical purpose to manipulate ranges, other than in a for loop. -- View this message in context: http://forum.openscad.org/ranges-to-vectors-tp7651p14404.html Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Thu, Nov 12, 2015 8:59 PM

ctchin wrote

MichaelAtOz wrote

function r2v(r,index=undef) =
(index==undef)
?  r2v(r,r[0],dir=(r[0]<=r[2]) )
:  (dir && index>r[2]) || (!dir && index<r[2])
? []
: concat([index],r2v(r,index+r[1],dir=dir));

Hmm how about just

function range2vector(r) = [ for (i=r) i];

No recursion needed, seems to work just fine.  It's been in my privately
kept stdlib.scad for a while... Not that's I've found much use of it.
Ranges are peculiar indeed, but I've found little practical purpose to
manipulate ranges, other than in a for loop.

That was written prior to the release of List Comprehensions...


Newly minted Admin - PM me if you need anything, or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

View this message in context: http://forum.openscad.org/ranges-to-vectors-tp7651p14421.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

ctchin wrote > > MichaelAtOz wrote >> function r2v(r,index=undef) = >> (index==undef) >> ? r2v(r,r[0],dir=(r[0]<=r[2]) ) >> : (dir && index>r[2]) || (!dir && index&lt;r[2]) >> ? [] >> : concat([index],r2v(r,index+r[1],dir=dir)); > Hmm how about just > > function range2vector(r) = [ for (i=r) i]; > > No recursion needed, seems to work just fine. It's been in my privately > kept stdlib.scad for a while... Not that's I've found much use of it. > Ranges are peculiar indeed, but I've found little practical purpose to > manipulate ranges, other than in a for loop. That was written prior to the release of List Comprehensions... ----- Newly minted Admin - PM me if you need anything, or if I've done something stupid... Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- View this message in context: http://forum.openscad.org/ranges-to-vectors-tp7651p14421.html Sent from the OpenSCAD mailing list archive at Nabble.com.
C
ctchin
Fri, Nov 13, 2015 1:56 AM

Oh... sorry didn't pay attention to the original post date...

--
View this message in context: http://forum.openscad.org/ranges-to-vectors-tp7651p14428.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Oh... sorry didn't pay attention to the original post date... -- View this message in context: http://forum.openscad.org/ranges-to-vectors-tp7651p14428.html Sent from the OpenSCAD mailing list archive at Nabble.com.