% My MetaPost macros % % labeling lengths (as in drafting), e.g. |<---- 2 in ---->| def drawopaque(expr p)= drawopaqueraw(p,0); enddef; def drawopaquecolor(expr p, c)= begingroup interim bboxmargin := 0; fill if path p: else: bbox fi p withcolor white; draw p withcolor c; endgroup enddef; def drawopaqueusebox (expr p, b) = fill b withcolor white; draw p; enddef; % draw a picture, but first erase what's underneath it (for perspecives) def drawopaqueraw(expr p, margin)= begingroup interim bboxmargin := margin; fill if path p: else: bbox fi p withcolor white; draw p; endgroup enddef; def endpoint(expr p)= begingroup save len; numeric len; len:=length(p); point len of p endgroup enddef; def drawbound(expr where, ldir)= begingroup save a,b; pair a,b; a := where + ldir*5pt; where = 0.5[a,b]; draw a--b; endgroup enddef; def draftlabel(expr g, ex)= begingroup save ldir; pair ldir; ldir = direction 0 of g; ldir := ldir/length(ldir); draftlabelraw(g, ex,(ldir rotated 90)); endgroup enddef; def draftlabelraw(expr g, ex, tdir) = begingroup save magic; numeric magic; save pict; magic := angle(tdir); drawdblarrow g; drawbound((point 0 of g), tdir); drawbound((endpoint(g)), tdir); picture pict; pict := nullpicture; save where; pair where; where = 0.5[point 0 of g,endpoint(g)]; pict := thelabel(ex, where); drawopaqueraw(pict, 2pt); endgroup enddef; % % labeling angles % howwide=30; tall=2in; marksize=4pt; angle_radius=tall/4; bobradius=tall/10; path lastarrow; def draw_mark(expr p, a, x) = begingroup save t, dm; pair dm; t = arctime a of p; label.bot(x, point t of p); endgroup enddef; def draw_mark_outside(expr p, a, x) = begingroup save t, dm; pair dm; t = arctime a of p; label.top(x, point t of p); endgroup enddef; def draw_marked(expr p, x) = begingroup save amid; amid = .5*arclength p; draw_mark(p, amid, x); draw p thinpen; endgroup enddef; def draw_marked_outside(expr p, x) = begingroup save amid; amid = .5*arclength p; draw_mark_outside(p, amid, x); draw p thinpen; endgroup enddef; def mark_angle(expr a, b, c, x) = begingroup save s, p; path p; p = unitvector(a-b){(a-b)rotated 90}..{(c-b)rotated 90}unitvector(c-b); s = .9marksize/length(point 1 of p - point 0 of p); if s