POV-Ray : Newsgroups : povray.general : array.length()? : Re: array.length()? Server Time
30 Jul 2024 12:32:57 EDT (-0400)
  Re: array.length()?  
From: Chris B
Date: 24 Feb 2009 03:44:08
Message: <49a3b358$1@news.povray.org>
"[GDS|Entropy]" <gds### [at] hotmailcom> wrote in message 
news:49a3abc7@news.povray.org...
> Because the array is declared outside of the macro which populates it, to 
> facilitate its passing to other macros as a variable, so always returns 
> whatever you defined its length to be, regardless if it has been populated 
> with that many values.
>
> Pov doesn't support redimensioning, does it?
>

Just to make sure I understand you correctly: You define an array that is, 
say 5000 elements long. You then call a macro to populate some elements of 
that array, but there are gaps. You then need a second macro to loop through 
the array, ignoring any unassigned elements?

If that's right, you just need to use #ifdef to see if an element of the 
array has been assigned before you use it.

If by 'redimensioning' you mean just scrunching up the gaps, then you can do 
that very simply in a loop using #ifdef on an array element. If it exists 
move it to the current 'write' point in the array. Plus you can count the 
actual number of elements uses as you go.

#local I = 0;
#declare NewSize = 0;
#while (I<dimension_size(MyArray,1))
  #ifdef(MyArray[I])
    #declare MyArray[NewSize] = MyArray[I];
    #declare NewSize = NewSize+1;
  #end
  #local I=I+1;
#end

Untested code Warning! I didn't run this, so it may contain syntax errors 
etc.

Regards,
Chris B.


Post a reply to this message

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