Debian Codegraph @

texmf-dist/metapost/cmarrows/sgbx0023.mp

raw
1 %% sgbx0023.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_tailarrow (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 & "__sgbxww")(p)
21 enddef;
22
23 expandafter vardef scantokens (cmdname & "__sgbxww " & "(expr apth) " &
24 "text text_ = " &
25
26 "save math_spread, x_height, u, rule_thickness, bar, math_axis," &
27 " asc_height, eps, monospace, fudge, crisp, hair;" &
28 "boolean monospace;" &
29
30 "math_spread :=" & decimal math_spread & ";" &
31 "x_height# :=" & decimal x_height# & ";" &
32 "u# :=" & decimal u# & ";" &
33 "rule_thickness# :=" & decimal rule_thickness# & ";" &
34 "bar# :=" & decimal bar# & ";" &
35 "math_axis# :=" & decimal math_axis# & ";" &
36 "asc_height# :=" & decimal asc_height# & ";" &
37 "eps :=" & decimal eps & ";" &
38 "monospace :=" & if monospace: "true" else: "false" fi & ";" &
39 "fudge :=" & decimal fudge & ";" &
40 "crisp# :=" & decimal crisp# & ";" &
41 "hair# :=" & decimal hair# & ";")
42
43 save prevpen;
44 prevpen:=savepen;
45
46 save x,y;
47 numeric x[], x[]', x[]l, x[]'l, x[]r, x[]'r,
48 y[], y[]', y[]l, y[]'l, y[]r, y[]'r;
49 save spread, w;
50 numeric spread, w;
51
52 if crisp#>fudge*hair#:
53 crisp#:=fudge*hair#;
54 fi
55 pickup if crisp#=0: nullpen else: pencircle scaled crisp# fi;
56
57 spread = math_spread[.45x_height#, .55x_height#];
58 w = 18u#;
59
60 penpos1(rule_thickness#, 90); penpos2(rule_thickness#, 90);
61 penpos3(bar#, 0); penpos4(bar#, 0);
62 y0=y1=y2=math_axis#; x1-.5rule_thickness#=u#; rt x0=w-u#;
63 y3-y0=y0-y4=.24asc_height#+eps;
64 x3=x4=x0-3u#-eps;
65 penpos5(bar#, angle(z4-z0)); z5l=z0;
66 penpos6(bar#, angle(z3-z0)); z6l=z0;
67 z9=.381966[.5[z3,z4],z0];
68
69 save pp; path pp; pp = z4l{z9-z4}..z6r;
70 save t; numeric t; t = xpart(pp intersectiontimes ((0,y2l)--(w,y2l)));
71 x2=xpart point t of pp;
72
73 save mapto, n;
74 vardef mapto(text t) =
75 hide(numeric n; n:=0;
76 numeric x,x_[],y,y_[];
77 for z=t: z_[incr n]:=z; endfor;
78 transform T;
79 z_2 = z_1 transformed T;
80 z_4 = z_3 transformed T;
81 z_6 = z_5 transformed T;)
82 T
83 enddef;
84
85 save T; transform T;
86 save tt; numeric tt; tt = arctime(arclength apth - (x0-x9)) of apth;
87 save ttt; numeric ttt; ttt = arctime(arclength apth - (x0-x2)) of apth;
88 save ssss; numeric ssss; ssss = arctime(x0-x3l) of apth;
89
90 % Draw the right half of the arrowhead
91
92 save right_texarrowhead, pa;
93 vardef right_texarrowhead(expr T,s) =
94 (subpath(0, xpart ((z0..{z4-z9}z4r) intersectiontimes
95 (point s of pp -- point s of pp + (2rule_thickness#,0))))
96 of (z0..{z4-z9}z4r)--subpath(s,t) of pp--z2l) transformed T
97 enddef;
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 +
111 3rule_thickness#*(unitvector (direction tt of apth)
112 rotated 90));
113 fi
114
115 save f,s;
116 vardef f(expr s) =
117 length(point s of (pp transformed T) - point tt of apth)
118 < length(point 0 of pp - z9)
119 enddef;
120
121 if f(0) or (arclength apth < x0-x3l): s := 0;
122 else: s := solve f(length pp, 0);
123 fi
124
125 path pa;
126 pa := right_texarrowhead(T,s);
127
128 % Draw the left half of the arrow head
129
130 pp := (z3l{z9-z3}..z5r);
131 save pq; path pq; pq := (z3r{z9-z3}..z0);
132
133 save left_texarrowhead, pb;
134 vardef left_texarrowhead(expr T, s) =
135 (z2r--subpath(t,s) of pp
136 --subpath(xpart ( pq intersectiontimes
137 (point s of pp -- point s of pp + (2rule_thickness#,0)))
138 ,length pq) of pq) transformed T
139 enddef;
140
141 if arclength apth = 0:
142 T:=identity shifted (point (length apth) of apth - z0);
143 elseif arclength apth < x0-x3l:
144 T:=identity rotatedaround(z0,angle (direction (length apth) of apth))
145 shifted (point (length apth) of apth - z0);
146 else:
147 T:=mapto(z0,
148 point (length apth) of apth,
149 z2,
150 point ttt of apth,
151 z9+(0,3rule_thickness#),
152 point tt of apth + 3rule_thickness#
153 *(unitvector (direction tt of apth)
154 rotated 90));
155 fi
156
157 vardef f(expr s) =
158 length(point s of (pp transformed T) - point tt of apth)
159 < length(point 0 of pp - z9)
160 enddef;
161
162 if f(0) or (arclength apth < x0-x3l): s := 0;
163 else: s := solve f(length pp, 0);
164 fi
165
166 path pb;
167 pb := left_texarrowhead(T,s);
168
169 filldraw pa--pb--cycle text_;
170
171 % Draw the right half of the tail
172
173 save ss; ss := arctime(x9-x3l) of apth;
174 save sss; sss := arctime(x2-x3l) of apth;
175
176 if arclength apth = 0:
177 T:=identity shifted (point 0 of apth - z0);
178 elseif arclength apth < x0-x3l:
179 T:=identity rotatedaround(z0,angle (direction 0 of apth))
180 shifted (point 0 of apth - z0);
181 else:
182 T:=mapto(z0,
183 point ssss of apth,
184 z2,
185 point sss of apth,
186 z9+(0,3rule_thickness#),
187 point ss of apth +
188 3rule_thickness#*(unitvector (direction ss of apth)
189 rotated 90));
190 fi
191
192 pp := z4l{z9-z4}..z6r;
193 vardef f(expr s) =
194 length(point s of (pp transformed T) - point ss of apth)
195 < length(point 0 of pp - z9)
196 enddef;
197
198 if f(0) or (arclength apth < x0-x3l): s := 0;
199 else: s := solve f(length pp, 0);
200 fi
201
202 pa := right_texarrowhead(T,s);
203
204 % Draw the left half of the tail
205
206 if arclength apth = 0:
207 T:=identity shifted (point 0 of apth - z0);
208 elseif arclength apth < x0-x3l:
209 T:=identity rotatedaround(z0,angle (direction 0 of apth))
210 shifted (point 0 of apth - z0);
211 else:
212 T:=mapto(z0,
213 point ssss of apth,
214 z2,
215 point sss of apth,
216 z9-(0,3rule_thickness#),
217 point ss of apth -
218 3rule_thickness#*(unitvector (direction ss of apth)
219 rotated 90));
220 fi
221
222 pp := (z3l{z9-z3}..z5r);
223 pq := (z3r{z9-z3}..z0);
224
225 vardef f(expr s) =
226 length(point s of (pp transformed T) - point ss of apth)
227 < length(point 0 of pp - z9)
228 enddef;
229
230 if f(0) or (arclength apth < x0-x3l): s := 0;
231 else: s := solve f(length pp, 0);
232 fi
233
234 pb := left_texarrowhead(T,s);
235
236 filldraw pa--pb--cycle text_;
237
238 % Draw the path
239
240 if arclength apth > 2(x0-x2):
241 save stt; stt := arctime(.5(x0+x2)-x3l) of apth;
242 draw subpath(stt,ttt) of apth withpen pencircle scaled rule_thickness#
243 text_;
244 fi
245
246 pickup prevpen;
247
248 enddef;
249
250 enddef;