POV-Ray : Newsgroups : povray.beta-test : Function weirdness : Re: Function weirdness Server Time
4 Nov 2024 23:20:25 EST (-0500)
  Re: Function weirdness  
From:
Date: 19 Sep 2001 04:41:56
Message: <5ulgqtgutqlojtjetl847g1r4s3rven3tn@4ax.com>
On Wed, 19 Sep 2001 00:20:42 -0400, "Slime" <noo### [at] hotmailcom>
wrote:

> Yeah, it makes sense now... I wish there were some way to force the function
> to store a value just so that the same value doesn't have to be calculated
> multiple times.

but you can do that !
just take another level of function

imagine - you want something like (in your expected notation)

#declare MyFunc=function(x,y,z){
  #local A=x+y+z;
  #local B=max3(x,y,z);
  (A*x/B)+(A*y/B)+(A*z/B)
} // I don't know what's this expression feel free to test

this can't work, but you can replace this with two declarations

#declare WithLocals=function(x,y,z,A,B){
  (A*x/B)+(A*y/B)+(A*z/B)
}
#declare MyFunc=function(x,y,z){WithLocals(x,y,z,x+y+z,max3(x,y,z))}

I don't know 3.5 engine yet but I think it causes one calculation of
such local variables.

ABX


Post a reply to this message

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