29.11.2012 Views

MetaFun - Pragma ADE

MetaFun - Pragma ADE

MetaFun - Pragma ADE

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

106<br />

also i<br />

fi<br />

withcolor white-(redpart i, greenpart i, bluepart i) ;<br />

endfor ;<br />

pp<br />

enddef ;<br />

We probably need to handle a few more border cases, but for general purposes, this macro works<br />

as expected.<br />

From the previous examples it may be clear that each picture has some associated data stored<br />

with it. From the bounded boolean test we can conclude that the bounding box is part of this data<br />

Internally METAPOST keeps track of two bounding boxes: the natural one, and the forced one. The<br />

forced one is actually a component of the picture which applies to all previously added graphics.<br />

You can calculate the bounding box from the llcorner and urcorner or if you like ulcorner and<br />

lrcorner and the METAFUN command boundingbox does so.<br />

The four corners that make up the bounding box are either the natural ones, or the ones forced by<br />

setbounds. You can force METAPOST to report the natural ones by setting truecorners to 1. The<br />

next example demonstrates this feature.<br />

pickup pencircle scaled 2mm ; path p, q ;<br />

draw fullcircle<br />

scaled 4cm slanted .5 withcolor .625white ;<br />

setbounds currentpicture to<br />

boundingbox currentpicture enlarged -5mm ;<br />

interim truecorners := 0 ; p := boundingbox currentpicture ;<br />

interim truecorners := 1 ; q := boundingbox currentpicture ;<br />

pickup pencircle scaled 1mm ;<br />

draw p withcolor .625red ;<br />

draw q withcolor .625yellow ;<br />

We use interim because truecorners is an internal METAPOST variable.<br />

2.11 Pitfalls<br />

When writing macros, you need to be careful in what operations apply to what object. There is for<br />

instance a difference between the following code:<br />

A few more details Pitfalls

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!