POV-Ray : Newsgroups : povray.general : Array in function. Not, but... : Array in function. Not, but... Server Time
14 Jun 2021 17:38:29 EDT (-0400)
  Array in function. Not, but...  
From: ingo
Date: 14 Apr 2021 13:50:14
Message: <XnsAD0CC9CB8C256seed7@news.povray.org>
As we can't use arrays inside functions I tried something else. A spline 
is an array, kind of and works in functions. So some test code, that 
works. There's one little thing I don't realy understand. I have to undef 
the 'i' used in SPL or rename it or the one in N. Otherwise I get: 

line xxx: Parse Error: Local variable name expected!

---%<------%<------%<---
#declare arrSPL = array[5]{
  <0,0>,
  <1,0>,
  <2,0>,
  <3,0>,
  <4,0>
}  
  
#declare SPL = spline{
  #for(i,0,dimension_size(arrSPL,1)-1)
    i, arrSPL[i],
  #end
}
#debug concat(str(SPL(4).x,5,5),"\n")
#undef arrSPL
#undef i      // <--------- !!

#declare Ar = function{
  spline{SPL}
}
#debug concat(str(Ar(4).x,5,5),"\n")
#undef SPL

#declare N = function(D){sum(i, 0, D, Ar(i).x)};
#declare NAR = N(4);
#debug concat(str(NAR,5,5),"\n")
---%<------%<------%<---

Ingo


Post a reply to this message

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