Debian Codegraph @

texmf-dist/metapost/cmarrows/rgbx0009.mp

raw
1 %% rgbx0009.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_paralleloppositearrows (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 & "__rgbxww")(p)
21 enddef;
22
23 expandafter vardef scantokens (cmdname & "__rgbxww " & "(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 % Path macros
72
73 save parallellineright;
74 vardef parallellineright expr pppp =
75 save s, stp;
76 numeric s, stp; stp:=(arclength pppp) div 5pt;
77 if stp=0: stp:=1; fi
78 stp:=(arclength pppp)/stp;
79
80 if stp>0:
81 for s=0 step stp until arclength pppp - stp:
82 point (arctime s of pppp) of pppp +
83 (.24asc_height#+eps)*(unitvector direction (arctime s of pppp)
84 of pppp rotated 90)
85 {direction (arctime s of pppp) of pppp}..
86 endfor
87 {direction (length pppp) of pppp}
88 point (length pppp) of pppp +
89 (.24asc_height#+eps)*(unitvector direction (length pppp)
90 of pppp rotated 90)
91 fi
92 enddef;
93
94 save parallellineleft;
95 vardef parallellineleft expr pppp =
96 save s, stp;
97 numeric s, stp; stp:=(arclength pppp) div 5pt;
98 if stp=0: stp:=1; fi
99 stp:=(arclength pppp)/stp;
100
101 if stp>0:
102 for s=0 step stp until arclength pppp - stp:
103 point (arctime s of pppp) of pppp -
104 (.24asc_height#+eps)*(unitvector direction (arctime s of pppp)
105 of pppp rotated 90)
106 {direction (arctime s of pppp) of pppp}..
107 endfor
108 {direction (length pppp) of pppp}
109 point (length pppp) of pppp -
110 (.24asc_height#+eps)*(unitvector direction (length pppp)
111 of pppp rotated 90)
112 fi
113 enddef;
114
115 save mapto, n;
116 vardef mapto(text t) =
117 hide(numeric n; n:=0;
118 numeric x,x_[],y,y_[];
119 for z=t: z_[incr n]:=z; endfor;
120 transform T;
121 z_2 = z_1 transformed T;
122 z_4 = z_3 transformed T;
123 z_6 = z_5 transformed T;)
124 T
125 enddef;
126
127 % Macros for drawing the arrow head
128
129 save pp; path pp; pp = z4l{z9-z4}..z6r;
130 save pq; path pq; pq = z0..{z4-z9}z4r;
131 save right_texarrowhead;
132 vardef right_texarrowhead(expr T,s) =
133 (subpath(0, xpart (pq intersectiontimes
134 (point s of pp -- point s of pp + (2rule_thickness#,0))))
135 of pq--subpath(s,t) of pp--z2l) transformed T
136 enddef;
137
138 save qq; path qq; qq = z3l{z9-z3}..z5r;
139 save qp; path qp; qp = z3r{z9-z3}..z0;
140 save left_texarrowhead;
141 vardef left_texarrowhead(expr T, s) =
142 (z2r--subpath(t,s) of qq
143 --subpath(xpart ( qp intersectiontimes
144 (point s of qq -- point s of qq + (2rule_thickness#,0)))
145 ,length qp) of qp) transformed T
146 enddef;
147
148 % Draw the arrows. First the left arrow and then the right arrow
149
150 save pa, pb, T, tt, ttt;
151 save f,s;
152
153 save p_left; path p_left; p_left := parallellineleft apth;
154 save p_right; path p_right; p_right := parallellineright apth;
155
156 for ppp = reverse p_left, p_right:
157 transform T;
158 numeric tt; tt := arctime(arclength ppp - (x0-x9)) of ppp;
159 numeric ttt; ttt := arctime(arclength ppp - (x0-x2)) of ppp;
160
161 % Draw the right half of the arrow head
162
163 if arclength ppp = 0:
164 T:=identity shifted (point (length ppp) of ppp - z0);
165 elseif arclength ppp < x0-x3l:
166 T:=identity rotatedaround(z0,angle (direction (length ppp) of ppp))
167 shifted (point (length ppp) of ppp - z0);
168 else:
169 T:=mapto(z0,
170 point (length ppp) of ppp,
171 z2,
172 point ttt of ppp,
173 z9-(0,3rule_thickness#),
174 point tt of ppp - 3rule_thickness#
175 *(unitvector (direction tt of ppp)
176 rotated 90));
177 fi
178
179 vardef f(expr s) =
180 length(point s of (pp transformed T) - point tt of ppp)
181 < length(point 0 of pp - z9)
182 enddef;
183
184 if f(0) or (arclength ppp < x0-x3l): s := 0;
185 else: s := solve f(length pp, 0);
186 fi
187
188 path pa;
189 pa := right_texarrowhead(T,s);
190
191 % Draw the left part of the arrow head
192
193 if arclength ppp = 0:
194 T:=identity shifted (point (length ppp) of ppp - z0);
195 elseif arclength ppp < x0-x3l:
196 T:=identity rotatedaround(z0,angle (direction (length ppp) of ppp))
197 shifted (point (length ppp) of ppp - z0);
198 else:
199 T:=mapto(z0,
200 point (length ppp) of ppp,
201 z2,
202 point ttt of ppp,
203 z9+(0,3rule_thickness#),
204 point tt of ppp + 3rule_thickness#
205 *(unitvector (direction tt of ppp)
206 rotated 90));
207 fi
208
209 vardef f(expr s) =
210 length(point s of (qq transformed T) - point tt of ppp)
211 < length(point 0 of qq - z9)
212 enddef;
213
214 if f(0) or (arclength ppp < x0-x3l): s := 0;
215 else: s := solve f(length qq, 0);
216 fi
217
218 path pb;
219 pb := left_texarrowhead(T,s);
220
221 filldraw pa--pb--cycle withpen nullpen text_;
222
223 % Draw the path
224
225 if arclength ppp > x0-x2:
226 draw subpath(0,ttt) of ppp withpen pencircle scaled rule_thickness#
227 text_;
228 fi
229
230 endfor
231
232 pickup prevpen;
233
234 enddef;
235
236 enddef;