|
|
[GDS|Entropy] <nomail@nomail> wrote:
> Is there a way in SDL to flatten an n-dimensional array?
> Everything I've tried so far seems to require knowing the array size in advance
> and accessing specifically: flat[foo] = array[x][y]
> It looks like the only way to make a method which can take an array as input and
> flatten it will need to have a switch statement in it to fork to appropriately
> deep loops. I don't like that though.
> Any other options?
I'm too lazy to check now, but wouldn't dimension_size() return 0 for
dimensions higher than what the array is? (It could also cause an error,
in which case this couldn't be used.)
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.
--
- Warp
Post a reply to this message
|
|
|
|
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
|
|