| 
|  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | This code shows something I found the other day: a macro (intp) wich returns a
number, affects the x-value when used in some vector expressions.
At first I thought it was a bug in MegaPov, but it also shows up in 
POV-Ray 3.1e
#macro intp(X,X1,Y1,X2,Y2)
    (Y2-Y1)/(X2-X1)*X - (Y2-Y1)/(X2-X1)*X1 + Y1
#end
#macro Print(V1)
    #local v1=V1*<1,1,1>;
    #render concat(
        str(i,1,0),": <",
        str(v1.x,2,1),", ",
        str(v1.y,2,1),", ",
        str(v1.z,2,1),">\n"
    )
#end
#declare var1=.1;
#declare var2=1;
// this one adds var1*x
#declare i=0;
#while (i<=3) 
    Print( x + (y+z)*intp(i, 0, var1, 3, var2)  )
    #local i=i+1; 
#end 
#render "\n"
// this is fine
#declare i=0;
#while (i<=3) 
    Print( <1, intp(i, 0, var1, 3, var2), intp(i, 0, var1, 3, var2)>  )
    #local i=i+1; 
#end 
#render "\n"
//this is fine
#declare i=0;
#while (i<=3) 
    Print( x + (y+z)*.3*i  )
    #local i=i+1; 
#end 
#render "\n"
//this is also fine
#declare i=0;
#while (i<=3) 
    Print( <1, .3*i, .3*i>  )
    #local i=i+1; 
#end
Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | Hei Kyrre!
If you put parenthesis around your macro result it will
stop acting strange.
Like this:
#macro intp(X,X1,Y1,X2,Y2)
    ((Y2-Y1)/(X2-X1)*X - (Y2-Y1)/(X2-X1)*X1 + Y1)
#end
The third parameter; Var1 (Y1) passed to your macro
will not be multiplied with (y+z) if you don't do this.
(If you omit the parenthesis, then Var1 is promoted to
a vector before it's added to a vector.)
Tor Olav
mailto:tor### [at] hotmail com
http://www.crosswinds.net/~tok/tokrays.html
Sigmund Kyrre Aas wrote:
> This code shows something I found the other day: a macro (intp) wich returns a
> number, affects the x-value when used in some vector expressions.
>
> At first I thought it was a bug in MegaPov, but it also shows up in
> POV-Ray 3.1e
>
> #macro intp(X,X1,Y1,X2,Y2)
>     (Y2-Y1)/(X2-X1)*X - (Y2-Y1)/(X2-X1)*X1 + Y1
> #end
>
> ...
> #declare var1=.1;
> #declare var2=1;
>
> // this one adds var1*x
> #declare i=0;
> #while (i<=3)
>     Print( x + (y+z)*intp(i, 0, var1, 3, var2)  )
>     #local i=i+1;
> #end
> #render "\n"Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | Ah! Thanks. It's so easy to treat something like intp() like a function.
sig
Tor Olav Kristensen wrote:
> 
> Hei Kyrre!
> 
> If you put parenthesis around your macro result it will
> stop acting strange.
> 
> Like this:
> 
> #macro intp(X,X1,Y1,X2,Y2)
>     ((Y2-Y1)/(X2-X1)*X - (Y2-Y1)/(X2-X1)*X1 + Y1)
> #end
> 
> The third parameter; Var1 (Y1) passed to your macro
> will not be multiplied with (y+z) if you don't do this.
> 
> (If you omit the parenthesis, then Var1 is promoted to
> a vector before it's added to a vector.)
> 
> Tor Olav
> 
> mailto:tor### [at] hotmail com
> http://www.crosswinds.net/~tok/tokrays.html
> 
> Sigmund Kyrre Aas wrote:
> 
> > This code shows something I found the other day: a macro (intp) wich returns a
> > number, affects the x-value when used in some vector expressions.
> >
> > At first I thought it was a bug in MegaPov, but it also shows up in
> > POV-Ray 3.1e
> >
> > #macro intp(X,X1,Y1,X2,Y2)
> >     (Y2-Y1)/(X2-X1)*X - (Y2-Y1)/(X2-X1)*X1 + Y1
> > #end
> >
> > ...
> > #declare var1=.1;
> > #declare var2=1;
> >
> > // this one adds var1*x
> > #declare i=0;
> > #while (i<=3)
> >     Print( x + (y+z)*intp(i, 0, var1, 3, var2)  )
> >     #local i=i+1;
> > #end
> > #render "\n" Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | Hei igjen.
Tor Olav Kristensen wrote:
> (If you omit the parenthesis, then Var1 is promoted to
> a vector before it's added to a vector.)
This part of the expression would also have been
promoted to a vector if you hadn't passed 0 for the
second argument (X1) to the macro:
(Y2-Y1)/(X2-X1)*X1
> Sigmund Kyrre Aas wrote:
> ...
>  // this one adds var1*x
> ...
It actually adds var1*(x + y + z)
(or <var1, var1, var1>)
Tor Olav
mailto:tor### [at] hotmail com
http://www.crosswinds.net/~tok/tokrays.html
Btw.: Here's a slightly simpler macro to do the same:
#macro intp(X,X1,Y1,X2,Y2)
    ((Y2-Y1)/(X2-X1)*(X-X1)+Y1)
#end Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | You have to remember that a macro is _not_ a function. A macro is a
substitution string. The body if the macro is inserted in the place of
the call as-is.
  So, for example this:
#macro Sum(X, Y)
  X+Y
#end
#declare result = 2*Sum(3,4);
will result in:
#declare result = 2*3+4;
  The right way of doing the macro is, of course:
#macro Sum(X, Y)
  (X+Y)
#end
  Now the result will be:
#declare result = 2*(3+4);
-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | Warp wrote:
>   You have to remember that a macro is _not_ a function. A macro is a
> substitution string. The body if the macro is inserted in the place of
> the call as-is.
Hmmm...
If that is true, then why does this not work?
#macro Test(ss)
  { ss, ss, ss }
#end
#declare TestArray = array[3] Test(2)
Tor Olav
mailto:tor### [at] hotmail com
http://www.crosswinds.net/~tok/tokrays.htmlPost a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | Tor Olav Kristensen <tto### [at] online no> wrote:
: If that is true, then why does this not work?
  I have no idea.
-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/ Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | In article <38E3ACD4.9A9E063B@online.no>, tor### [at] hotmail com wrote:
> Warp wrote:
> 
> >   You have to remember that a macro is _not_ a function. A macro is a
> > substitution string. The body if the macro is inserted in the place of
> > the call as-is.
> 
> Hmmm...
> If that is true, then why does this not work?
Er, well...it should work.
I tried some other combinations, putting the brackets outside the macro, 
enclosing each value with parenthesis...it still doesn't work. When I 
put a #debug statement in the macro, I found the macro is never called. 
Maybe you should compose a bug report. This looks like a real bug.
-- 
Christopher James Huff - Personal e-mail: chr### [at] yahoo  com
TAG(Technical Assistance Group) e-mail: chr### [at] tag  povray  org
Web page: http://chrishuff.dhs.org/ Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | I suppose that it's because a macro call is not expected after the
declaration of an array and thus it never gets parsed.
  Probably a mistake.
-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | Warp wrote:
>   I suppose that it's because a macro call is not expected after the
> declaration of an array and thus it never gets parsed.
>   Probably a mistake.
For me it seems to be parsed in some strange way, because I
get this error message:
#end
#declare TestArray = array[3] Test(2)
  { <----ERROR
Test.pov: error: object or directive expected but { found instead.
Would the "{" appear in the error message if the macro
wasn't ever parsed?
Tor Olav
mailto:tor### [at] hotmail com
http://www.crosswinds.net/~tok/tokrays.html
Btw: Does anyone know if it's possible to copy (and paste)
a text string from the error message window in the
Windows POV?Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |