Debian Codegraph @

texmf-dist/metapost/cmarrows/sgbx0021.mp

raw
1 %% sgbx0021.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_shortaxisarrow(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;" &
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
40 save prevpen;
41 prevpen:=savepen;
42
43 save x,y;
44 numeric x[], x[]', x[]l, x[]'l, x[]r, x[]'r,
45 y[], y[]', y[]l, y[]'l, y[]r, y[]'r;
46 save spread, w;
47 numeric spread, w;
48
49 pickup pencircle scaled rule_thickness#;
50
51 spread = math_spread[.45x_height#, .55x_height#];
52 w = 9u#;
53
54 penpos1(.25rule_thickness#, 90); penpos2(.25rule_thickness#, 90);
55 penpos3(bar#, 0); penpos4(bar#, 0);
56 y0=y1=y2=math_axis#;
57 x1=1.5u#-eps;
58 rt x0=w-x1;
59 y3-y0=y0-y4=.24asc_height#+eps; x3=x4=x0-3u#-eps;
60 penpos5(bar#, angle(z4-z0)); z5l=z0; penpos6(bar#, angle(z3-z0)); z6l=z0;
61 z9=.381966[.5[z3,z4],z0];
62 save pp; path pp; pp=z4l{z9-z4}..z6r;
63 save t; numeric t;
64 t=xpart(pp intersectiontimes ((0,y2l)--(w,y2l))); x2=xpart point t of pp;
65
66 save mapto, n;
67 vardef mapto(text t) =
68 hide(numeric n; n:=0;
69 numeric x,x_[],y,y_[];
70 for z=t: z_[incr n]:=z; endfor;
71 transform T;
72 z_2 = z_1 transformed T;
73 z_4 = z_3 transformed T;
74 z_6 = z_5 transformed T;)
75 T
76 enddef;
77
78 save T; transform T;
79 save tt; numeric tt; tt = arctime(arclength apth - (x5l-x2)) of apth;
80 save ttt; numeric ttt; ttt = arctime(arclength apth - (x5l-x3)) of apth;
81
82 % Draw the right half of the arrow head
83
84 save right_arrowhead, pa;
85 vardef right_arrowhead(expr T,s) =
86 (subpath(0, xpart ((z0..{z4-z9}z4r) intersectiontimes
87 (point s of pp -- point s of pp + (2rule_thickness#,0))))
88 of (z0..{z4-z9}z4r)--subpath(s,t) of pp--z2l) transformed T
89 enddef;
90
91 if arclength apth = 0:
92 T:=identity shifted (point (length apth) of apth - z0);
93 elseif arclength apth < x0-x3l:
94 T:=identity rotatedaround(z0,angle (direction (length apth) of apth))
95 shifted (point (length apth) of apth - z0);
96 else:
97 T:=mapto(z0,
98 point (length apth) of apth,
99 z2,
100 point tt of apth,
101 (x3,y9)-(0,3rule_thickness#),
102 point ttt of apth -
103 3rule_thickness#*(unitvector (direction tt of apth)
104 rotated 90));
105 fi
106
107 save f,s;
108 vardef f(expr s) =
109 length(point s of (pp transformed T) - point tt of apth)
110 < length(point 0 of pp - z2)
111 enddef;
112
113 if f(0) or (arclength apth < x0-x3l): s := 0;
114 else: s := solve f(length pp, 0);
115 fi
116
117 path pa;
118 pa := right_arrowhead(T,s);
119
120 % Draw the left part of the arrow head
121
122 pp := (z3l{z9-z3}..z5r);
123 save pq; path pq; pq := (z3r{z9-z3}..z0);
124
125 save left_texarrowhead, pb;
126 vardef left_texarrowhead(expr T, s) =
127 (z2r--subpath(t,s) of pp
128 --subpath(xpart ( pq intersectiontimes
129 (point s of pp -- point s of pp + (2rule_thickness#,0)))
130 ,length pq) of pq) transformed T
131 enddef;
132
133 if arclength apth = 0:
134 T:=identity shifted (point (length apth) of apth - z0);
135 elseif arclength apth < x0-x3l:
136 T:=identity rotatedaround(z0,angle (direction (length apth) of apth))
137 shifted (point (length apth) of apth - z0);
138 else:
139 T:=mapto(z0,
140 point (length apth) of apth,
141 z2,
142 point tt of apth,
143 (x3,y9)+(0,3rule_thickness#),
144 point ttt of apth +
145 3rule_thickness#*(unitvector (direction tt of apth)
146 rotated 90));
147 fi
148
149 vardef f(expr s) =
150 length(point s of (pp transformed T) - point tt of apth)
151 < length(point 0 of pp - z2)
152 enddef;
153
154 if f(0) or (arclength apth < x0-x3l): s := 0;
155 else: s := solve f(length pp, 0);
156 fi
157
158 path pb;
159 pb := left_texarrowhead(T,s);
160
161 filldraw pa--pb--cycle text_;
162
163 % Draw the path
164
165 if arclength apth > x0-x2:
166 draw subpath(0,tt) of apth withpen pencircle scaled 1.25rule_thickness#
167 text_;
168 fi
169
170 pickup prevpen;
171
172 enddef;
173
174 enddef;