29.11.2012 Views

MetaFun - Pragma ADE

MetaFun - Pragma ADE

MetaFun - Pragma ADE

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

276<br />

Now, what happens when we want to place labels in other positions? In the worst case, given<br />

that we place the labels manually, we end up in vague arguments in favour for one or the other<br />

placement.<br />

upper left<br />

left<br />

top<br />

lower left bottom<br />

upper right<br />

right<br />

lower right<br />

Although any automatic mechanism will be sub--optimal, we can give it a try to write a macro that<br />

deals with arbitrary locations. This macro will accept three arguments and return a picture.<br />

thefreelabel("some string or picture",a position,the origin)<br />

Our testcase is just a simple for loop that places a series of labels. The freedotlabel macro is<br />

derived from thefreelabel.<br />

pickup pencircle scaled 1mm ;<br />

path p ; p := fullcircle scaled 3cm ;<br />

draw p withcolor .625yellow ;<br />

for i=0 step .5 until 7.5 :<br />

freedotlabel ("text" , point i of p, center p) ;<br />

endfor ;<br />

As a first step we will simply place the labels without any correction. We also visualize the bounding<br />

box.<br />

vardef thefreelabel (expr str, loc, ori) =<br />

save s ; picture s ; s := thelabel(str,loc) ;<br />

draw boundingbox s withpen pencircle scaled .5pt ;<br />

s<br />

enddef ;<br />

To make our lives more easy, we also define a macro that draws the dot as well as a macro that<br />

draws the label.<br />

vardef freedotlabel (expr str, loc, ori) =<br />

drawdot loc ; draw thefreelabel(str,loc,ori) ;<br />

enddef ;<br />

vardef freelabel (expr str, loc, ori) =<br />

draw thefreelabel(str,loc,ori) ;<br />

enddef ;<br />

Now we get:<br />

A few applications Free labels

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

Saved successfully!

Ooh no, something went wrong!