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

* Re: MetaFun refill/do_repath bug
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2002-09-16 16:29 UTC (permalink / raw)
  Cc: ConTeXt

At 05:31 PM 9/16/2002 +0200, Jens-Uwe Morawski wrote:

>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

did a short talk on some of those metafun thingies at the last dante 
meeting -)

>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.

hm, will look into it, kind of funny that "i" then is a path and picture at 
the same time

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

btw, a real robust solution also takes fonts into account so i'll have a 
look at that (fontpart and textpart)

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------


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

* Re: MetaFun refill/do_repath bug
  2002-09-16 16:29 ` Hans Hagen
@ 2002-09-16 20:03   ` Jens-Uwe Morawski
  2002-09-17  7:57     ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Jens-Uwe Morawski @ 2002-09-16 20:03 UTC (permalink / raw)


On Mon, 16 Sep 2002 18:29:55 +0200
Hans Hagen <pragma@wxs.nl> wrote:

> At 05:31 PM 9/16/2002 +0200, Jens-Uwe Morawski wrote:
> >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.
> 
> hm, will look into it, kind of funny that "i" then is a path and picture at 
> the same time

the i in the loop is always a picture but the macro pathpath extracts
the path information. for clipped and bounded objects these paths are
the clip or setbounds paths. 

> >Please find below a MP-file that illustrates what i mean.
> >It compares the macro "uniformfilled" from my article with
> >your "refill".
> 
> btw, a real robust solution also takes fonts into account so i'll have a 
> look at that (fontpart and textpart)

you need more since fontpart and textpart do not include the
transformations applied to the text. But, since i in a
  for i within a_picture
is always a picture, text elements can be handled easily with
addto ... also i ; The test for textual and textpart/fontpart
is only needed if you really want to work with the text-information.

In order to rewrite all text in blue it should be enough to say:
if textual i:
  addto tmp_pic also i withcolor blue ;
fi;

Jens


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

* Re: MetaFun refill/do_repath bug
  2002-09-16 20:03   ` Jens-Uwe Morawski
@ 2002-09-17  7:57     ` Hans Hagen
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2002-09-17  7:57 UTC (permalink / raw)
  Cc: ConTeXt

At 10:03 PM 9/16/2002 +0200, Jens-Uwe Morawski wrote:

> > >Please find below a MP-file that illustrates what i mean.
> > >It compares the macro "uniformfilled" from my article with
> > >your "refill".
> >
> > btw, a real robust solution also takes fonts into account so i'll have a
> > look at that (fontpart and textpart)
>
>you need more since fontpart and textpart do not include the
>transformations applied to the text. But, since i in a
>   for i within a_picture
>is always a picture, text elements can be handled easily with
>addto ... also i ; The test for textual and textpart/fontpart
>is only needed if you really want to work with the text-information.

indeed, but it's a nice exercise to reconstruct the transform matrix -)

actually, i'm playing with font substitutes now, not that useful, but nice 
trickery anyway

>In order to rewrite all text in blue it should be enough to say:
>if textual i:
>   addto tmp_pic also i withcolor blue ;
>fi;

sure, unless tricky color signals are used,

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------


^ 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).