POV-Ray : Newsgroups : povray.general : Why does POV always evaluate both expressions with a '&'? : Re: Why does POV always evaluate both expressions with a '&'? Server Time
7 Aug 2024 17:29:11 EDT (-0400)
  Re: Why does POV always evaluate both expressions with a '&'?  
From: Thorsten Froehlich
Date: 27 Sep 2001 14:19:13
Message: <3bb36da1@news.povray.org>
In article <2vk### [at] michariser> , Micha Riser <mri### [at] gmxnet>  
wrote:

> Can you do it without extra variable?

I can do it with i and n

> One solution working in pov is:
>
> #declare goon=1;
> #declare i=0;
> #while ((i<n)&(goon=1))
>         #if (a[i]=0)
>                 #declare i=i+1;
>         #else
>                 #declare goon=0;
>         #end
> #end
>
> So this can impossible be better style. Please enlighten me with your
> solution.

Of course it depends on what exactly you want to do with the result to find
an optimal solution (in particular one that doesn't process the whole
array).  This macro should do what you want and it does not need more
variables:

#macro findzero(a, n)
 #local i = n;
 #while(i >= 0)
  #if(a[i] != 0)
   #declare n = i;
  #end
  #declare i = i - 1;
 #end
#end

#declare myarray = array[5]

#declare myarray[0] = 0;
#declare myarray[1] = 0;
#declare myarray[2] = 0;
#declare myarray[3] = 0;
#declare myarray[4] = 0;

#declare p = 4;
findzero(myarray, p)
#debug str(p,1,1)

#declare myarray[3] = 4;
#declare myarray[4] = 2;

#declare p = 4;
findzero(myarray, p)
#debug str(p,1,1)

#declare myarray[0] = 6;
#declare myarray[1] = 7;
#declare myarray[2] = 3;

#declare p = 4;
findzero(myarray, p)
#debug str(p,1,1)

#declare myarray[2] = 0;

#declare p = 4;
findzero(myarray, p)
#debug str(p,1,1)


Post a reply to this message

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