POV-Ray : Newsgroups : povray.general : array.length()? : Re: array.length()? Server Time
30 Jul 2024 12:22:29 EDT (-0400)
  Re: array.length()?  
From: Tim Attwood
Date: 24 Feb 2009 03:33:26
Message: <49a3b0d6$1@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?

Yeah, it does support redimensioning, you just redeclare it;
there's a bit of memory overhead is all.

// oversized array sample
#declare MyArray = array [1000];
#declare MyArray[0] = 1;
#declare MyArray[1] = 2;

// resize the array to fit the data
#macro resize_array(ar)
   #local c = 0;
   #while (defined(ar[c]))
      #local c=c+1;
   #end
   #local new_ar = array[c];
   #local c2=0;
   #while (c2<c)
      #local new_ar[c2]=ar[c2];
      #local c2=c2+1;
   #end
   #declare ar = new_ar;
#end

// some output
#debug concat("Dimension Size = ", str(dimension_size(MyArray,1),0,0),"\n")
resize_array(MyArray)
#debug concat("Dimension Size = ", str(dimension_size(MyArray,1),0,0),"\n")
#error "Stop"


Post a reply to this message

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