[metapost] rfc: consistent color values

Brooks Moses bmoses at stanford.edu
Mon Apr 11 20:47:14 CEST 2005


At 03:39 AM 4/11/2005, Taco Hoekwater wrote:
>Jens-Uwe Morawski wrote:
>>Additionally, it must be possible to change the behaviour for
>>each addto
>>addto ... withcolor (-1,-2,-3) ; % truncated color
>>begingroup
>>   interim truecolors:=1 ;
>>   addto ... withcolor (-1,-2,-3) ; % not truncated color ;
>>endgroup
>
>This is exactly how it would work, so no problem there.

I do have a couple of questions with this, and a suggestion.  First, the 
semantics are still slightly unclear.  Suppose I do the following (with the 
relevant variables defined appropriately):

   truecolors :=1 ;
   addto P doublepath path1 withcolor (-1, -1, -1) ;
   for I in within P: show (redpart I) ; endfor;
   truecolors :=0 ;
   for J in within P: show (redpart J) ; endfor;
   addto P doublepath path2 withcolor (.5, .5, .5) ;

What color does the first object end up as?  Does the addition of another 
path to P cause all parts of P to be clipped to the [0,1] color range?  If 
not, do we need to introduce a primitive to do this clipping?  If it does, 
does this have a risk of large unwanted side effects from merely "touching" 
a picture?

Further, what does the show(redpart(J)) statement do?  It should not 
actually change the value of P; however, one would expect that when 
truecolors is zero, a redpart() function should return a value in the [0,1] 
range.


Finally, it seems to me that there is no need to introduce a "truecolors" 
flag to get this functionality; we could equally well define intrinsics 
"withtruecolor" and "redtruepart" (etc.), and write the above example as:

   addto P doublepath path1 withtruecolor (-1, -1, -1) ;
   for I in within P: show (redtruepart I) ; endfor;
   for J in within P: show (redpart J) ; endfor;
   addto P doublepath path2 withcolor (.5, .5, .5) ;

This is, I think, a better implementation.  It avoids the problems 
associated with flags -- namely, the fact that the behavior of a given 
statement depends on a hidden mode that can be set in some completely 
different part of the program, and may even be set in some separate 
inputted package file that (completely unknown to the user) didn't include 
all of its truecolor:=1 statements in groups.

And, if we implement this version and for some reason one _does_ want the 
flag behavior, it is quite trivial to implement it in one's MetaPost code, 
with a function withmaybetruecolor returns either withcolor or 
withtruecolor depending on the state of a user-defined truecolors variable 
(and similarly for redmaybetruepart, etc.).

Thus, I would strongly urge implementing this with extra intrinsics, rather 
than with a flag.

- Brooks



More information about the metapost mailing list