POV-Ray : Newsgroups : povray.general : Flatten n-dimension array? : Re: Flatten n-dimension array? Server Time
29 Jul 2024 10:27:29 EDT (-0400)
  Re: Flatten n-dimension array?  
From: [GDS|Entropy]
Date: 18 Oct 2011 19:45:01
Message: <web.4e9e0ea59b1e54a277e50e540@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
>   I'm too lazy to check now, but wouldn't dimension_size() return 0 for
> dimensions higher than what the array is?

The way I currently handle this is by using dimensions() to set the counter in a
for loop, which then measures each dimension individually [I assume oddly shaped
arrays] and utilizes this to produce a count of indices required in the 1D
array. This works based on my testing so far [not extensive].

>   A recursive macro can be created to do what you want (once you know the
> dimensions of the array). It's not completely trivial to write, but shouldn't
> be too difficult either.

That seems to be the generic solution I've seen implemented in languages similar
to SDL. I wanted something cleaner, but that may not be an option.

If the urge strikes you, feel free to take a stab at it along with me. :p

I'll put some more effort into this, but since it isn't really for anything I'm
doing specifically, other than making a .mcr file of array utilities typically
found in many C based languages, I may abandon it for things more interesting
and less time consuming. time == money ;)

I need to make some more context-selected pseudo overloads for higher
dimensions/etc.., but so far I have:
IndexOf() [Vector, non-vector]
Contains() [Vector, non-vector]
Shuffle() [Fisher-Yates, Bruteforce]
Resize()
CountDefined()

Just those few have made a *lot* of things I usually do much less tedious.

Ian


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.