POV-Ray : Newsgroups : povray.advanced-users : function select logic : Re: function select logic Server Time
2 May 2024 13:07:44 EDT (-0400)
  Re: function select logic  
From: Mike Horvath
Date: 23 Nov 2016 18:28:42
Message: <5836262a$1@news.povray.org>
On 11/23/2016 1:59 AM, Mike Horvath 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

Here is the code I came up with:

// utility
#declare selectRGBa = function(C,D) {select(C,0,D)}
#declare selectRGBb = function(C,D) {select(C-1,D,D,0)}


// input R: between 0 and 1
// input G: between 0 and 1
// input B: between 0 and 1
// output R: between 0 and 1
// output G: between 0 and 1
// output B: between 0 and 1
#declare correctRGBa1 = function(R,G,B) 
{selectRGBa(R,selectRGBa(G,selectRGBa(B,R)))}
#declare correctRGBa2 = function(R,G,B) 
{selectRGBa(R,selectRGBa(G,selectRGBa(B,G)))}
#declare correctRGBa3 = function(R,G,B) 
{selectRGBa(R,selectRGBa(G,selectRGBa(B,B)))}
#declare correctRGBb1 = function(R,G,B) 
{selectRGBb(R,selectRGBb(G,selectRGBb(B,correctRGBa1(R,G,B))))}
#declare correctRGBb2 = function(R,G,B) 
{selectRGBb(R,selectRGBb(G,selectRGBb(B,correctRGBa2(R,G,B))))}
#declare correctRGBb3 = function(R,G,B) 
{selectRGBb(R,selectRGBb(G,selectRGBb(B,correctRGBa3(R,G,B))))}

The selectRGBa and selectRGBb functions are new helper functions.

Mike


Post a reply to this message

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