[metapost] reverse clip operation

lfinsto1 at gwdg.de lfinsto1 at gwdg.de
Wed Sep 20 08:28:14 CEST 2006

Dan Luecking wrote:

> This was discussed before, I think. An eoclip operation would
> yield what you want (if MP had such a thing): provide two paths,
> one around the border of the figure and the one in question.

Nice code sample.  While I appreciate the beauty of solutions to puzzles
and problems using MP alone, I think the problem may become unmanageable,
if the outer border of the desired region of the drawing is made up of
fragments of several paths.  It would be even harder if these paths were
non-contiguous, and the algorithm had to determine the "right" way to
connect them, in order to create a closed region.

> There also
> exist post-processing techniques (context's texexec, I think)
> that can do it.

If using external tools is allowed, I'm pretty sure it can be done using
the ImageMagick programs:  `mogrify', `composite', and perhaps others. 
The problem can be defined as an application of layers and masking.  It
would also be helpful to have transparency.  It's often helpful to use
"color replacement", i.e., make the pixels of an otherwised unused color
in an image transparent with `mogrify'.  This subject has come up before. 
TeX text can be handled by converting the EPS file to PS before passing
the latter to the ImageMagick functions.  If necessary, the resulting
files can be converted to EPS or some other format.
I've written more about this here: 

Using GIMP would also be a possibility.

Laurence Finston

More information about the metapost mailing list