Debian Codegraph @

texmf-dist/metapost/cmarrows/tgbx0007.mp

raw
1 %% tgbx0007.mp
2 %% Copyright 2006 Tommy Ekola <[email protected]>
3 %
4 % This work may be distributed and/or modified under the conditions of
5 % the LaTeX Project Public License, either version 1.3 of this license
6 % or (at your option) any later version. The latest version of this
7 % license is in http://www.latex-project.org/lppl.txt
8 %
9 % This work has the LPPL maintenance status `maintained'. The Current
10 % Maintainer of this work is Tommy Ekola. The Base Interpreter is
11 % MetaPost.
12
13 vardef setup_twoheadarrow (expr source_file, cmdname) =
14
15 scantokens ("input tgbx0000");
16
17 scantokens ("input " & source_file);
18
19 expandafter def scantokens cmdname expr p =
20 scantokens (cmdname & "__tgbxww")(p)
21 enddef;
22
23 expandafter vardef scantokens (cmdname & "__tgbxww " & "(expr apth) " &
24 "text text_ = " &
25
26 "save math_spread, x_height, u, rule_thickness, bar, math_axis," &
27 " asc_height, eps, fudge, crisp, hair;" &
28
29 "math_spread :=" & decimal math_spread & ";" &
30 "x_height# :=" & decimal x_height# & ";" &
31 "u# :=" & decimal u# & ";" &
32 "rule_thickness# :=" & decimal rule_thickness# & ";" &
33 "bar# :=" & decimal bar# & ";" &
34 "math_axis# :=" & decimal math_axis# & ";" &
35 "asc_height# :=" & decimal asc_height# & ";" &
36 "eps :=" & decimal eps & ";" &
37 "fudge :=" & decimal fudge & ";" &
38 "crisp# :=" & decimal crisp# & ";" &
39 "hair# :=" & decimal hair# & ";")
40
41 save prevpen;
42 prevpen:=savepen;
43
44 save x,y;
45 numeric x[], x[]', x[]l, x[]'l, x[]r, x[]'r,
46 y[], y[]', y[]l, y[]'l, y[]r, y[]'r;
47 save spread, w;
48 numeric spread, w;
49
50 if crisp#>fudge*hair#:
51 crisp#:=fudge*hair#;
52 fi
53 pickup if crisp#=0: nullpen else: pencircle scaled crisp# fi;
54
55 spread = math_spread[.45x_height#, .55x_height#];
56 w = 18u#;
57
58 penpos1(rule_thickness#, 90); penpos2(rule_thickness#, 90);
59 penpos3(bar#, 0); penpos4(bar#, 0);
60 y0=y1=y2=math_axis#; x1-.5rule_thickness#=u#; rt x0=w-u#;
61 y3-y0=y0-y4=.24asc_height#+eps;
62 x3=x4=x0-3u#-eps;
63 penpos5(bar#, angle(z4-z0)); z5l=z0;
64 penpos6(bar#, angle(z3-z0)); z6l=z0;
65 z9=.381966[.5[z3,z4],z0];
66
67 save pp; path pp; pp = z4l{z9-z4}..z6r;
68 save t; numeric t; t = xpart(pp intersectiontimes ((0,y2l)--(w,y2l)));
69 x2=xpart point t of pp;
70
71 save texarrowhead;
72 vardef texarrowhead(expr T) =
73 filldraw (z0..{z4-z9}z4r--subpath(0,t) of pp
74 --z2l--z2r--subpath(t,0) of (z3l{z9-z3}..z5r)
75 --z3r{z9-z3}..z0 & cycle) transformed T text_;
76 enddef;
77
78 save mapto, n;
79 vardef mapto(text t) =
80 hide(numeric n; n:=0;
81 numeric x,x_[],y,y_[];
82 for z=t: z_[incr n]:=z; endfor;
83 transform T;
84 z_2 = z_1 transformed T;
85 z_4 = z_3 transformed T;
86 z_6 = z_5 transformed T;)
87 T
88 enddef;
89
90 save T; transform T;
91 save tt; numeric tt; tt = arctime(arclength apth - (x0-x9)) of apth;
92 save ttt; numeric ttt; ttt = arctime(arclength apth - (x0-x2)) of apth;
93
94 if arclength apth > x0-x2:
95 draw subpath(0,ttt) of apth
96 withpen pencircle scaled rule_thickness# text_;
97 fi
98
99 if arclength apth = 0:
100 T:=identity shifted (point (length apth) of apth - z0);
101 elseif arclength apth < x0-x3l:
102 T:=identity rotatedaround(z0,angle (direction (length apth) of apth))
103 shifted (point (length apth) of apth - z0);
104 else:
105 T:=mapto(z0,
106 point (length apth) of apth,
107 z2,
108 point ttt of apth,
109 z9+(0,3rule_thickness#),
110 point tt of apth + 3rule_thickness#*
111 (unitvector (direction tt of apth) rotated 90));
112 fi
113 texarrowhead(T);
114
115 tt :=arctime(arclength apth - (x0-x9) + (x3l-x0)) of apth;
116 ttt:=arctime(arclength apth - (x0-x2) + (x3l-x0)) of apth;
117 if arclength apth = 0:
118 T:=identity shifted (point 0 of apth - z0)
119 shifted (x3l-x0,0);
120 elseif arclength apth < x0-x3l+x0-x9:
121 T:=identity rotatedaround(z0,angle direction 0 of apth)
122 shifted ((x0-x3l)*
123 unitvector (point 0 of apth - point (length apth) of apth))
124 shifted ((point (length apth) of apth) - z0);
125 else:
126 T:=mapto(z0,
127 point (arctime((arclength apth)+(x3l-x0)) of apth) of apth,
128 z2,
129 point ttt of apth,
130 z9+(0,3rule_thickness#),
131 point tt of apth + 3rule_thickness#*
132 (unitvector (direction tt of apth) rotated 90));
133 fi
134 texarrowhead(T);
135
136 pickup prevpen;
137
138 enddef;
139
140 enddef;