POV-Ray : Newsgroups : povray.general : What is wrong with this? : Re: What is wrong with this? Server Time
28 Jun 2024 01:51:17 EDT (-0400)
  Re: What is wrong with this?  
From: Ron Parker
Date: 1 Sep 1999 16:09:17
Message: <37cd87ed@news.povray.org>
On Wed, 01 Sep 1999 14:10:59 -0400, TonyB wrote:
>I tried something new. I added the keyword "color" before the formula
>and it set the values straight. I don't like this. How come without that
>keyword the other expression works, and without it the compact one
>doesn't? I did a #debug on the value of the #declare'd variables and
>look at this:
>
> #declare b=(sky_color+White)/2;   //ugly
> #declare p=(sky_color*.5+White*.5);   //nice
>
> #debug concat("B = ",str(b.x,0,3)," ",str(b.y,0,3)," ",str(b.z,0,3),"
>P = ",str(p.x,0,3)," ",str(p.y,0,3)," ",str(p.z,0,3),"\n")
>
>See for yourselves how much B differs from P. I don't understand how
>this can generate such different results. At any rate, when you add
>"color" to the UGLY pigment declaration, it becomes NICE. :P

I did this myself and discovered the same thing.  I went further and looked
at the parser to see why, and it is indeed a bug.

By the way, I didn't get the same results you did.  I determined that
when the expression is in parentheses, or in any other way doesn't start
with a token that explicitly identifies it as a color, it parses as
a vector which is then promoted to a color, but the promotion is not 
done correctly.

In parse.c, in the function Parse_RValue, in the case where Terms is 5,
(search for "case 5" without the quotes) there was a line that said

            Assign_Colour(*DataPtr, Local_Express);

This is wrong, because Assign_Colour is a memcpy and Local_Express is an
array of DBL's, not of COLC's, and doesn't have the same layout in memory.  
This should read like so instead

            for (i=0;i<Terms;i++)
    	      ((COLC *)(*DataPtr))[i]=(COLC)Local_Express[i];

Don't forget to add a declaration for i at the top of the function.

This message has been crossposted to povray.bugreports, but followups 
remain in povray.general.  Please keep any discussion in .general.


Post a reply to this message

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