ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* MetaFun refill/do_repath bug
@ 2002-09-16 15:31 Jens-Uwe Morawski
  2002-09-16 16:29 ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Jens-Uwe Morawski @ 2002-09-16 15:31 UTC (permalink / raw)


Ahoi Hans,

i wrote an article for the magazine of the german TUG that explains
some advanced features of MetaPost. Esp. it explains the
within,pathpart,penpart... stuff. In the article i give an example
that refills all filled elements of a picture with a new color.

The article is not yet published, but one who has proof-read the
article told me that an equal macro is provided by MetaFun. A little
bit surprised, since i thought that i know most of the MetaFun
features, i've tried the "refill" macro and was surprised again, since
it does not work correctly (IMO). The problem is that the macro
"do_repath" does not handle clipped and bounded graphic elements
correctly.

Your macro ignores totally that clipped and bounded elements
contain again some more graphic elements, i.e. lines, filled
paths etc. Therefore the macro has to be applied recursively to
these elements too. Furthermore the pathpart of a clipped
or bounded object has to be applied only to the elements in
that object and not to the whole picture.

Please find below a MP-file that illustrates what i mean.
It compares the macro "uniformfilled" from my article with
your "refill".

Best,
  Jens

%%% ---snip--- 

input metafun ;

primarydef p uniformfilled c =
	begingroup
	save t, f, s ;
	picture t, s ;
	t := nullpicture ; color f ;

	for i within p :
		f := (redpart i, greenpart i, bluepart i) ;
		if bounded i :
			s := i uniformfilled c ;
			setbounds s to pathpart i ;
			addto t also s ;
		elseif clipped i :
			s := i uniformfilled c ;
			clip s to pathpart i ;
			addto t also s ;
		elseif stroked i : 
			addto t doublepath pathpart i 
			  dashed dashpart i withpen penpart i 
			  withcolor f ;
		elseif filled i : 
			addto t contour pathpart i 
			  withcolor c ;
		else:
			addto t also i ;
	     fi ;
	endfor; t endgroup
enddef;

picture pic[] ;

%-- a clipped picture
pic[0] := nullpicture ;
addto pic[0] contour ( unitsquare scaled 2cm )
	withcolor green ;
addto pic[0] contour ( unitsquare scaled 2cm shifted (-2cm,-2cm) )
	withcolor green ;
addto pic[0] contour ( unitsquare scaled 2cm shifted (0,-2cm) )
	withcolor red ;
addto pic[0] contour ( unitsquare scaled 2cm shifted (-2cm,0) )
	withcolor red ;

clip pic[0] to fullcircle scaled 4cm ;

%-- the base picture
pic[1] := nullpicture ;
addto pic[1] contour
	( unitsquare xscaled 5cm yscaled 1cm shifted (-2.5cm,1cm) )
	withcolor blue ;
addto pic[1] contour
	( unitsquare xscaled 5cm yscaled 1cm shifted (-2.5cm,-2cm) )
	withcolor blue ;
addto pic[1] also pic[0] ;
addto pic[1] doublepath fullcircle scaled 4cm
	withpen pencircle scaled 3pt;

%-- "uniformfilled" applied to the base picture
pic[2] := pic[1] uniformfilled .6white ;

%-- "refill" applied to the base picture
pic[3] := pic[1] ;
refill pic[3] withcolor .6white ;

beginfig(1);

label.top(pic[1],origin) ;
label.bot("original",origin) ;

label.top(pic[2],(5.3cm,0)) ;
label.bot("uniformfilled",(5.3cm,0)) ;

label.top(pic[3],(10.6cm,0)) ;
label.bot("MetaFun/refill",(10.6cm,0)) ;

endfig;
end


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-09-17  7:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-16 15:31 MetaFun refill/do_repath bug Jens-Uwe Morawski
2002-09-16 16:29 ` Hans Hagen
2002-09-16 20:03   ` Jens-Uwe Morawski
2002-09-17  7:57     ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).