POV-Ray : Newsgroups : povray.general : Still making newbie mistakes Server Time
29 Jul 2024 08:18:10 EDT (-0400)
  Still making newbie mistakes (Message 11 to 17 of 17)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Cousin Ricky
Subject: Re: Still making newbie mistakes
Date: 25 Mar 2013 13:50:01
Message: <web.51508e25c4a906bb78641e0c0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 21.03.2013 03:32, schrieb Cousin Ricky:
>
> > POV-Ray veterans and C programmers will spot my error immediately.
>
> Will they?

I guess I shouldn't be so hard on myself, then.


Post a reply to this message

From: Le Forgeron
Subject: Re: Still making newbie mistakes
Date: 25 Mar 2013 13:56:59
Message: <51508feb$1@news.povray.org>
Le 25/03/2013 18:47, Cousin Ricky nous fit lire :
> Christian Froeschlin <chr### [at] chrfrde> wrote:
>> Cousin Ricky wrote:
>>
>>  > -Basic_shape (0.4, 0.4)
>>
>> I suspect this was intended to be the negative value
>> of Basic_shape(0.4,0.4), while it may turn out to only
>> change 1-sqrt to -1-sqrt.
> 
> Bingo.  But you're not a newbie, so the discount goes to the first newbie who
> explains why this happens and how to fix it.

That would be a kind of paradox (paradox of the Court): if a newbie can
explain why, (s)he is no more a newbie. (and to spoil the fix, it's
related to the usage of parentheses).

http://en.wikipedia.org/wiki/Paradox_of_the_Court


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Still making newbie mistakes
Date: 25 Mar 2013 14:13:23
Message: <515093c3$1@news.povray.org>
BTW I never really thought much about this but I think I exclusively
use macros to return complete entities (union, texture, function,...).

In this case it would be something like (untested online code snippet)

#macro Basic_shape (Rpipe, Rsaddle)
function
{
   1 - sqrt(...)
}
#end

#declare f_basic_shape = Basic_shape(0.4,0.4)

isosurface
{
   function { max (f_basic_shape(x,y,z), -f_basic_shape(x,y,z) ) }
   ...
}

Probably avoids a whole lot of trouble ;)


Post a reply to this message

From: Sohcahtoa
Subject: Re: Still making newbie mistakes
Date: 1 Apr 2013 15:15:01
Message: <web.5159dc9dc4a906bbc9c203510@news.povray.org>
"Cousin Ricky" <rickysttATyahooDOTcom> wrote:
> Christian Froeschlin <chr### [at] chrfrde> wrote:
> > Cousin Ricky wrote:
> >
> >  > -Basic_shape (0.4, 0.4)
> >
> > I suspect this was intended to be the negative value
> > of Basic_shape(0.4,0.4), while it may turn out to only
> > change 1-sqrt to -1-sqrt.
>
> Bingo.  But you're not a newbie, so the discount goes to the first newbie who
> explains why this happens and how to fix it.

Macros are expanded inline.  That is to say, the body of the macro is
substituted for the macro call.

You could fix it by either putting a call to the macro in parentheses, or
putting parentheses around the math in the macro definition, like this:

#macro Basic_shape (Rpipe, Rsaddle)
  (1 - sqrt
  ( RE_fn_Blob2 (f_sphere (0, y, z, Rpipe), Rsaddle)
  + RE_fn_Blob2 (f_sphere (x, 0, z, Rpipe), Rsaddle)
  - RE_fn_Blob2 (f_sphere (x, y, z, Rpipe), Rsaddle)
  ))
#end


Post a reply to this message

From: Le Forgeron
Subject: Re: Still making newbie mistakes
Date: 1 Apr 2013 16:46:05
Message: <5159f20d$1@news.povray.org>
Le 01/04/2013 21:14, Sohcahtoa nous fit lire :
> "Cousin Ricky" <rickysttATyahooDOTcom> wrote:
>> Christian Froeschlin <chr### [at] chrfrde> wrote:
>>> Cousin Ricky wrote:
>>>
>>>  > -Basic_shape (0.4, 0.4)
>>>
>>> I suspect this was intended to be the negative value
>>> of Basic_shape(0.4,0.4), while it may turn out to only
>>> change 1-sqrt to -1-sqrt.
>>
>> Bingo.  But you're not a newbie, so the discount goes to the first newbie who
>> explains why this happens and how to fix it.
> 
> Macros are expanded inline.  That is to say, the body of the macro is
> substituted for the macro call.
> 
> You could fix it by either putting a call to the macro in parentheses, or
> putting parentheses around the math in the macro definition, like this:
> 
> #macro Basic_shape (Rpipe, Rsaddle)
>   (1 - sqrt
>   ( RE_fn_Blob2 (f_sphere (0, y, z, Rpipe), Rsaddle)
>   + RE_fn_Blob2 (f_sphere (x, 0, z, Rpipe), Rsaddle)
>   - RE_fn_Blob2 (f_sphere (x, y, z, Rpipe), Rsaddle)
>   ))
> #end
> 
> 
> 
> 
IMHO, You would qualify as newbie, no cigar. What about the definition
of RE_fn_Blob2 ? no parentheses either ?

would you have the discount ? that's an open question.

And no offence ever intended. keep smiling.


Post a reply to this message

From: Cousin Ricky
Subject: Re: Still making newbie mistakes
Date: 3 Apr 2013 11:05:00
Message: <web.515c44a1c4a906bb78641e0c0@news.povray.org>
"Sohcahtoa" <kil### [at] yahoocom> wrote:
> You could fix it by either putting a call to the macro in parentheses, or
> putting parentheses around the math in the macro definition, like this:
>
> #macro Basic_shape (Rpipe, Rsaddle)
>   (1 - sqrt
>   ( RE_fn_Blob2 (f_sphere (0, y, z, Rpipe), Rsaddle)
>   + RE_fn_Blob2 (f_sphere (x, 0, z, Rpipe), Rsaddle)
>   - RE_fn_Blob2 (f_sphere (x, y, z, Rpipe), Rsaddle)
>   ))
> #end

Good programming practice suggests the latter.  The caller shouldn't have to
babysit the macro.  See also:

  http://www.povray.org/documentation/view/3.6.1/243/#s02_02_02_08_04


Post a reply to this message

From: Cousin Ricky
Subject: Re: Still making newbie mistakes
Date: 3 Apr 2013 11:25:01
Message: <web.515c48c2c4a906bb78641e0c0@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
>  What about the definition
> of RE_fn_Blob2 ? no parentheses either ?

RE_fn_Blob2() is a function, not a macro, so it doesn't need to be defined or
called with parentheses.

FYI, it is defined as:
  _________________________________________________________

  #declare RE_fn_Blob2 = function (RE_P0_Value, RE_P1_Blob)
  { select
    ( RE_P1_Blob - RE_P0_Value, 0,
      pow ((RE_P1_Blob - RE_P0_Value) / RE_P1_Blob, 2)
    )
  }
  _________________________________________________________


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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