POV-Ray : Newsgroups : povray.general : Function: Problem in Defining Server Time
25 Apr 2024 21:12:50 EDT (-0400)
  Function: Problem in Defining (Message 7 to 16 of 16)  
<<< Previous 6 Messages Goto Initial 10 Messages
From: Sven Littkowski
Subject: Re: Function: Problem in Defining
Date: 5 Apr 2018 18:40:59
Message: <5ac6a5fb$1@news.povray.org>
Tttttsssssssssssssssssssssssss.

That is insider knowledge! Thanks! I would never have discovered this
option on my own. Giving a try.   :-)

---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com


Post a reply to this message

From: dick balaska
Subject: Re: Function: Problem in Defining
Date: 5 Apr 2018 21:02:06
Message: <5ac6c70e$1@news.povray.org>
On 04/05/2018 12:21 PM, clipka wrote:

>      #declare MySeed = seed(4711);
>      #macro MyRand(Min,Max)
>        // compute stuff
>        #local Rand = rand(MySeed);
>        #local Result = Min + (Max-Min)*Rand;
>        // "return" the computed value
>        Result
>      #end
> 

I wrap the return value in parenthesis. The intent is a little clearer 
in the macro def and may avoid usage problems.

     // "return" the computed value
     (Result)

I know clipka, legally this is not required, because Result is a single 
number. But I tend to do

     #local V=<1,2,3>;
     // "return" the computed value
     (Result+V)

where it is morally (debuggingly?) required.

sven, this is because when you use it, think of the expansion.

     #local R = MyRand(low, high) * 2;

which without parens, is
     #local R = Result + V * 2

which of course evaluates as
     #local R = Result + (V * 2)

which is not at all what you want.  With the parens, you get
     #local R = (Result + V) * 2

which is the intent of your usage.

-- 
dik
Rendered 328976 of 330000 (99%)


Post a reply to this message

From: Thomas de Groot
Subject: Re: Function: Problem in Defining
Date: 6 Apr 2018 02:47:16
Message: <5ac717f4$1@news.povray.org>
On 5-4-2018 22:57, Bald Eagle wrote:
> And you don't even really need a separate function or macro - just use
> 
> #include "rand.inc"
> 
> then use (IIRC)
> 
> RRand (0, 360)
> 
> or
> 
> RRand (-180, 180) to give you your rotation angles directly.
> 

To be correct:

#declare R=seed(1234);

RRand (-180, 180, R)


Post a reply to this message

From: Thomas de Groot
Subject: Re: Function: Problem in Defining
Date: 6 Apr 2018 03:32:37
Message: <5ac72295@news.povray.org>
On 6-4-2018 0:41, Sven Littkowski wrote:
> Tttttsssssssssssssssssssssssss.
> 
> That is insider knowledge! Thanks! I would never have discovered this
> option on my own. Giving a try.   :-)
> 

Everybody can discover it. No "insider knowledge" here at all imo. When 
you need randomness, you naturally go and look at the content of 
rand.inc and its description in the docs. Nothing arcane involved.

-- 
Thomas


Post a reply to this message

From: Sven Littkowski
Subject: Re: Function: Problem in Defining
Date: 6 Apr 2018 07:13:58
Message: <5ac75676$1@news.povray.org>
Using RRand now, testing. Looks good.

---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com


Post a reply to this message

From: Sven Littkowski
Subject: Re: Function: Problem in Defining
Date: 6 Apr 2018 07:16:20
Message: <5ac75704$1@news.povray.org>
I just did not know about the existence of that include. But such is
life: you never stop to discover or learn new things. :-)

---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com


Post a reply to this message

From: Sven Littkowski
Subject: Re: Function: Problem in Defining
Date: 6 Apr 2018 07:17:14
Message: <5ac7573a$1@news.povray.org>
Yes, I already found it that. I opened that include file, and saw the
parameter for the SEED item.

---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com


Post a reply to this message

From: clipka
Subject: Re: Function: Problem in Defining
Date: 6 Apr 2018 12:06:45
Message: <5ac79b15$1@news.povray.org>
Am 06.04.2018 um 03:02 schrieb dick balaska:
> On 04/05/2018 12:21 PM, clipka wrote:
> 
>>      #declare MySeed = seed(4711);
>>      #macro MyRand(Min,Max)
>>        // compute stuff
>>        #local Rand = rand(MySeed);
>>        #local Result = Min + (Max-Min)*Rand;
>>        // "return" the computed value
>>        Result
>>      #end
>>
> 
> I wrap the return value in parenthesis. The intent is a little clearer
> in the macro def and may avoid usage problems.
> 
>     // "return" the computed value
>     (Result)

You run into problems with this approach if you ever want to return
something that isn't a scalar or vector. For instance, the following
won't fly:

    #macro FullName(FileName)
      #local Result = concat("C:/Fnord/", FileName);
      (Result)
    #end

    #include FullName("stuff.inc")


> I know clipka, legally this is not required, because Result is a single
> number. But I tend to do
> 
>     #local V=<1,2,3>;
>     // "return" the computed value
>     (Result+V)
> 
> where it is morally (debuggingly?) required.

Then maybe don't do that ;)

I really literally use `Result` as the local variable name, and make
sure to always store the very end result in there, for the same purpose
that you use the parentheses. That way

    Result

is guaranteed to be the only thing the macro "emits". Solves the same
problem as your parentheses, but has the added benefit of working in
more scenarios.


Post a reply to this message

From: Thomas de Groot
Subject: Re: Function: Problem in Defining
Date: 7 Apr 2018 02:47:35
Message: <5ac86987$1@news.povray.org>
On 6-4-2018 13:16, Sven Littkowski wrote:
> I just did not know about the existence of that include. But such is
> life: you never stop to discover or learn new things. :-)
> 

I cannot believe this! :-O

I would urgently ask you to look at the POV-Ray folders! You pretend you 
have been using POV-Ray for over /ten/ years and you /never ever/ looked 
into the include?!? the Insert Menu?!? the scenes?!? folders; not to 
speak of the documentation. I begin to understand the background of some 
of your questions...

-- 
Thomas


Post a reply to this message

From: Sven Littkowski
Subject: Re: Function: Problem in Defining
Date: 7 Apr 2018 21:46:11
Message: <5ac97463$1@news.povray.org>
Well, of course I have looked at files inside the INCLUDE folder many,
many times, but each time I checked only on some specific names, mostly
when i ran into some problems. Can't change it.

I actually use POV-Ray since 1990 or so...   :-D

---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com


Post a reply to this message

<<< Previous 6 Messages Goto Initial 10 Messages

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