Debian Codegraph @

texmf-dist/metapost/cmarrows/sgbx0011.mp

raw
1 %% sgbx0011.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_twowaydoublearrow (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, 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 lft x1 = u#-eps; x2=x1; x7=x8=w-x1;
59 y1=y7; y2=y8; y1-y2=spread; .5[y1,y2]=math_axis#;
60
61 rt x0 = w-u#+eps; y0 = math_axis#;
62 penpos3(rule_thickness#,0); penpos4(rule_thickness#,0);
63 y3-y1 = y2-y4 = .24asc_height#+eps; x3=x4=x0-6u#-eps;
64 penpos5(rule_thickness#, angle(z4-z0)); z5l=z0;
65 penpos6(rule_thickness#, angle(z3-z0)); z6l=z0;
66 z9 = .381966[.5[z3,z4],z0];
67
68 save pp;
69 path pp; pp = z4l{z9-z4}..z6r;
70 save t;
71 numeric t; t = xpart(pp intersectiontimes ((0,y0)--(w,y0)));
72 numeric t[]; t1 = xpart(pp intersectiontimes ( (0,y2-rule_thickness#/2)
73 --(w,y2-rule_thickness#/2)));
74 t2 = xpart(pp intersectiontimes ( (0,y2+rule_thickness#/2)
75 --(w,y2+rule_thickness#/2)));
76 save qq;
77 path qq; qq = z3l{z9-z3}..z5r;
78
79 save parallelline;
80 vardef parallelline expr ppp =
81 save s, stp;
82 numeric s, stp; stp:=(arclength ppp) div 5pt;
83 if stp=0: stp:=1; fi
84 stp:=(arclength ppp)/stp;
85
86 if arclength apth > 0:
87 draw for s=0 step stp until arclength ppp - stp:
88 point (arctime s of ppp) of ppp +
89 spread/2*(unitvector direction (arctime s of ppp)
90 of ppp rotated 90)
91 {direction (arctime s of ppp) of ppp}..
92 endfor
93 {direction (length ppp) of ppp}
94 point (length ppp) of ppp +
95 spread/2*(unitvector direction (length ppp) of ppp rotated 90)
96 withpen pencircle scaled rule_thickness#
97 text_;
98
99 draw for s=0 step stp until arclength ppp - stp:
100 point (arctime s of ppp) of ppp -
101 spread/2*(unitvector direction (arctime s of ppp)
102 of ppp rotated 90)
103 {direction (arctime s of ppp) of ppp}..
104 endfor
105 {direction (length ppp) of ppp}
106 point (length ppp) of ppp -
107 spread/2*(unitvector direction (length ppp) of ppp rotated 90)
108 withpen pencircle scaled rule_thickness#
109 text_;
110 fi
111 enddef;
112
113 save mapto, n;
114 vardef mapto(text t) =
115 hide(numeric n; n:=0;
116 numeric x,x_[],y,y_[];
117 for z=t: z_[incr n]:=z; endfor;
118 transform T;
119 z_2 = z_1 transformed T;
120 z_4 = z_3 transformed T;
121 z_6 = z_5 transformed T;)
122 T
123 enddef;
124
125 % Draw the front arrow head
126
127 save doublearrowhead;
128 vardef doublearrowhead(expr T, s, ss) =
129 (subpath(0, xpart((z0..{z4-z9}z4r) intersectiontimes
130 (point s of pp -- point s of pp + (2rule_thickness#,0))))
131 of (z0..{z4-z9}z4r)
132 --subpath(s,t1) of pp
133 --(xpart point t1 of pp, ypart point t2 of pp)
134 --subpath(t2,t) of pp
135 --subpath(t,t2) of qq
136 --(xpart point t1 of qq, ypart point t2 of qq)
137 --subpath(t1,ss) of qq
138 --subpath(xpart ((z3r{z9-z3}..z0) intersectiontimes
139 (point ss of qq -- point ss of qq + (2rule_thickness#,0))),1)
140 of (z3r{z9-z3}..z0)
141 & cycle) transformed T
142 enddef;
143
144 save T; transform T;
145 save tt; numeric tt;
146 tt = arctime (arclength apth - (x0 - xpart point t1 of pp)) of apth;
147
148 if arclength apth = 0:
149 T:=identity shifted (point (length apth) of apth - z0);
150 elseif arclength apth < x0-xpart(point t2 of pp):
151 T:=identity rotatedaround(z0,angle (direction (length apth) of apth))
152 shifted (point (length apth) of apth - z0);
153 else:
154 T := mapto(
155 z0,
156 point (length apth) of apth,
157 point t1 of pp + (0,rule_thickness#/2),
158 point tt of apth +
159 spread/2*(unitvector direction tt of apth rotated 90),
160 point t1 of qq - (0,rule_thickness#/2),
161 point tt of apth -
162 spread/2*(unitvector direction tt of apth rotated 90));
163 fi
164
165 save f,s,ss,ttt;
166 ttt = arctime(arclength apth - (x0-x9)) of apth;
167 vardef f(expr s) =
168 length(point s of (pp transformed T) - point ttt of apth)
169 < length(point 0 of pp - z9)
170 enddef;
171
172 if f(0) or (arclength apth < x0-x3l): s := 0;
173 else: s := solve f(length pp, 0);
174 fi
175
176 vardef f(expr ss) =
177 length(point ss of (qq transformed T) - point ttt of apth)
178 < length(point 0 of qq - z9)
179 enddef;
180
181 if f(0) or (arclength apth < x0-x3l): ss := 0;
182 else: ss := solve f(length qq, 0);
183 fi
184
185 filldraw doublearrowhead(T,s,ss) text_;
186
187 % Draw the back arrow head
188
189 save ttt; numeric ttt;
190 ttt = arctime (x0 - xpart point t1 of pp) of apth;
191
192 if arclength apth = 0:
193 T:=identity rotatedaround(z0, 180)
194 shifted (point (length apth) of apth - z0);
195 elseif arclength apth < x0-xpart(point t2 of pp):
196 T:=identity rotatedaround(z0,angle (direction 0 of apth)+180)
197 shifted (point 0 of apth - z0);
198 else:
199 T := mapto(
200 z0,
201 point 0 of apth,
202 point t1 of pp + (0,rule_thickness#/2),
203 point ttt of apth +
204 spread/2*(unitvector direction ttt of apth rotated 90),
205 point t1 of qq - (0,rule_thickness#/2),
206 point ttt of apth -
207 spread/2*(unitvector direction ttt of apth rotated 90));
208 fi
209
210
211 ttt := arctime(x0-x9) of apth;
212 vardef f(expr s) =
213 length(point s of (pp transformed T) - point ttt of apth)
214 < length(point 0 of pp - z9)
215 enddef;
216
217 if f(0) or (arclength apth < x0-x3l): s := 0;
218 else: s := solve f(length pp, 0);
219 fi
220
221 vardef f(expr ss) =
222 length(point ss of (qq transformed T) - point ttt of apth)
223 < length(point 0 of qq - z9)
224 enddef;
225
226 if f(0) or (arclength apth < x0-x3l): ss := 0;
227 else: ss := solve f(length qq, 0);
228 fi
229
230 filldraw doublearrowhead(T,s,ss) text_;
231
232 % Draw the path
233
234 if arclength apth > 2(x0-xpart(point t1 of pp)):
235 parallelline (subpath(ttt,tt) of apth);
236 fi
237
238 pickup prevpen;
239
240 enddef;
241
242 enddef;