POV-Ray : Newsgroups : povray.advanced-users : function select logic : Re: function select logic Server Time
14 May 2024 04:30:22 EDT (-0400)
  Re: function select logic  
From: scott
Date: 23 Nov 2016 09:30:26
Message: <5835a802$1@news.povray.org>
On 23/11/2016 12:51, Bald Eagle wrote:
> Mike Horvath <mik### [at] gmailcom> wrote:
>> I have the following three functions:
>>
>> #declare correctRGB_R = function(R,G,B) {min(max(R,0),1)}
>> #declare correctRGB_G = function(R,G,B) {min(max(G,0),1)}
>> #declare correctRGB_B = function(R,G,B) {min(max(B,0),1)}
>>
>> They each process input and output one component of an R,G,B color vector.
>>
>> However, instead of the above, I want the entire vector discarded if
>> *any* of R, G or B is less than zero or greater than one.
>>
>> I'm not sure how to form the select statement. What is the best way to
>> do this?
>>
>> Mike

What do you mean by discarded? A function must always return a value, 
there is no "discarded" option. Where/how are you going to use these 
three functions and what do you want the final result to be if the input 
RGB is out of range? You could return a special value like -1 to 
indicate a "discarded" vector - but it depends what you're going to do 
next with the result.

> Wrap all three #declares in a conditional block?
>
> #if (R>1 | R<0 | G>1 | G<0 | B>1 | B<0)
>      // do nothing, or whatever else you want
> #else
>      #declare correctRGB_R = function(R,G,B) {min(max(R,0),1)}
>      #declare correctRGB_G = function(R,G,B) {min(max(G,0),1)}
>      #declare correctRGB_B = function(R,G,B) {min(max(B,0),1)}
> #end
>
> or something along those lines....

That's just going to decide whether or not to declare the functions in 
the scene, on some unrelated RGB variables (RGB in the function 
definitions are just parameters). It won't affect the behaviour of the 
function when it is actually used later on (apart from getting an error 
that it is undefined).


Post a reply to this message

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