POV-Ray : Newsgroups : povray.advanced-users : Conditional expressions in functions Server Time
20 Apr 2024 01:31:03 EDT (-0400)
  Conditional expressions in functions (Message 1 to 4 of 4)  
From: Bald Eagle
Subject: Conditional expressions in functions
Date: 27 Feb 2021 17:00:00
Message: <web.603ac097ad97ece51f9dae300@news.povray.org>
One thing I noticed while trying to compose some functions is that the
conditional expressions are not recognized by POV-Ray's function VM.

I can work around this with select(), but sometimes it would just be a lot
easier on my brain to use the simpler and more direct conditional syntax.






Possible Parse Error: Suspicious identifier found in function! If you want to
call a function make sure the function you call has been declared. If you call
an internal function, make sure you have included 'functions.inc'.

Parse Error: Expected 'operator', ? found instead

Conditional expressions: The operand C is boolean while operands A and B are any
expressions. The result is of the same type as A and B.

(C ? A : B) if C then A else B


Post a reply to this message

From: Bald Eagle
Subject: Re: Conditional expressions in functions
Date: 27 Feb 2021 20:15:01
Message: <web.603aede88a182d6d1f9dae300@news.povray.org>
I was also trying to minimize the processing of vectors, and executed the
following:

#declare f_Axis = function (Vector) {select (Vector, x, y, z)}

Which worked, but did not give me the expected results.
My debug statements with str complained that it expected a value, but a vector
was encountered instead, which leads me to believe that it was returning the
_vector_ quantities x, y, and z - which I thought functions couldn't do?

modifying/correcting to:

#declare f_Axis = function (x, y, z, Vector) {select (Vector, x, y, z)}

yielded the expected scalar world-coordinate, so that's an interesting pair of
results.


Post a reply to this message

From: BayashiPascal
Subject: Re: Conditional expressions in functions
Date: 28 Feb 2021 00:30:01
Message: <web.603b2a358a182d6d6396ca3e0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I was also trying to minimize the processing of vectors, and executed the
> following:
>
> #declare f_Axis = function (Vector) {select (Vector, x, y, z)}
>
> Which worked, but did not give me the expected results.
> My debug statements with str complained that it expected a value, but a vector
> was encountered instead, which leads me to believe that it was returning the
> _vector_ quantities x, y, and z - which I thought functions couldn't do?
>
> modifying/correcting to:
>
> #declare f_Axis = function (x, y, z, Vector) {select (Vector, x, y, z)}
>
> yielded the expected scalar world-coordinate, so that's an interesting pair of
> results.


+1 to the addition of conditional in user-defined functions ! I also use select
as a replacement but as you say it would be much easier to use an explicit
condition.
Having no limitation of parameters to float values would also be very helpful.
Also, I found the equivalence x/u and y/v, the default x,y,z optional arguments,
or the fact they share the same name with the predefined vectors x,y,z, all very
confusing. It made me avoid the use of user-defined functions for a long time,
and even now I'm always a bit reluctant, trying to find workaround as much as
possible.
Hopefully a future version of Pov-ray will improve their usability.

Pascal


Post a reply to this message

From: Kenneth
Subject: Re: Conditional expressions in functions
Date: 28 Feb 2021 08:30:01
Message: <web.603b9a1c8a182d6dd98418910@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I was also trying to minimize the processing of vectors, and executed the
> following:
>
> #declare f_Axis = function (Vector) {select (Vector, x, y, z)}
>
> Which worked, but did not give me the expected results.
> My debug statements with str complained that it expected a value, but a vector
> was encountered instead...
>

For your #debug, did you try just  str?  or   vstr (for vectors, to see what
would happen)? This is probably tangential to you're main concern, but it's
worth a try...

example...
#debug concat("\n","my vector = <",vstr(3,Vector,", ",0,5),">","\n")


Post a reply to this message

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