POV-Ray : Newsgroups : povray.advanced-users : Macros acting strange Server Time
2 Nov 2024 07:25:06 EDT (-0400)
  Macros acting strange (Message 1 to 10 of 11)  
Goto Latest 10 Messages Next 1 Messages >>>
From: Sigmund Kyrre Aas
Subject: Macros acting strange
Date: 28 Mar 2000 14:43:02
Message: <38E10B3A.7C6D3308@stud.ntnu.no>
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

From: Tor Olav Kristensen
Subject: Re: Macros acting strange
Date: 28 Mar 2000 16:15:06
Message: <38E11FBD.8BEAA009@online.no>
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] hotmailcom
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

From: Sigmund Kyrre Aas
Subject: Re: Macros acting strange
Date: 28 Mar 2000 16:32:20
Message: <38E124D8.33B8DF84@stud.ntnu.no>
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] hotmailcom
> 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

From: Tor Olav Kristensen
Subject: Re: Macros acting strange
Date: 28 Mar 2000 16:51:21
Message: <38E12832.F9273777@online.no>
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] hotmailcom
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

From: Warp
Subject: Re: Macros acting strange
Date: 29 Mar 2000 04:07:15
Message: <38e1c7c3@news.povray.org>
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

From: Tor Olav Kristensen
Subject: Re: Macros acting strange
Date: 30 Mar 2000 14:41:44
Message: <38E3ACD4.9A9E063B@online.no>
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] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

From: Warp
Subject: Re: Macros acting strange
Date: 31 Mar 2000 03:56:00
Message: <38e4681f@news.povray.org>
Tor Olav Kristensen <tto### [at] onlineno> 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

From: Chris Huff
Subject: Re: Macros acting strange
Date: 31 Mar 2000 06:09:50
Message: <chrishuff_99-F3724F.06120931032000@news.povray.org>
In article <38E3ACD4.9A9E063B@online.no>, tor### [at] hotmailcom 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] yahoocom
TAG(Technical Assistance Group) e-mail: chr### [at] tagpovrayorg
Web page: http://chrishuff.dhs.org/


Post a reply to this message

From: Warp
Subject: Re: Macros acting strange
Date: 31 Mar 2000 08:02:16
Message: <38e4a1d8@news.povray.org>
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

From: Tor Olav Kristensen
Subject: Re: Macros acting strange
Date: 31 Mar 2000 08:42:23
Message: <38E4AA17.61D172C5@online.no>
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] hotmailcom
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

Goto Latest 10 Messages Next 1 Messages >>>

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