Debian Codegraph @

texmf-dist/metapost/cmarrows/rgbx0020.mp

raw
1 %% rgbx0020.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_paralleloppositelefthalfarrows (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, 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(rule_thickness#, 0); penpos4(rule_thickness#, 0);
62 y0=y1=y2=math_axis#; x1-.5rule_thickness#=u#; rt x0=w-u#;
63 y3-y0=y0-y4=.36asc_height#+eps;
64 x3=x4=x0-4u#-eps;
65 penpos5(rule_thickness#, angle(z4-z0)); z5l=z0;
66 penpos6(rule_thickness#, angle(z3-z0)); z6l=z0;
67 save t; numeric t;
68 save pq; path pq; pq = z4l..{2(x0-x4),y0-y4}z6r;
69 t=xpart(pq intersectiontimes ((0,y2l)--(w,y2l))); x2=xpart point t of pq;
70 z9=.2[.5[z3,z4],z0];
71
72 % Path macros
73
74 save parallellineright;
75 vardef parallellineright expr pppp =
76 save s, stp;
77 numeric s, stp; stp:=(arclength pppp) div 5pt;
78 if stp=0: stp:=1; fi
79 stp:=(arclength pppp)/stp;
80
81 if stp > 0:
82 for s=0 step stp until arclength pppp - stp:
83 point (arctime s of pppp) of pppp +
84 spread/2*(unitvector direction (arctime s of pppp)
85 of pppp rotated -90)
86 {direction (arctime s of pppp) of pppp}..
87 endfor
88 {direction (length pppp) of pppp}
89 point (length pppp) of pppp +
90 spread/2*(unitvector direction (length pppp)
91 of pppp rotated -90)
92 fi
93 enddef;
94
95 save parallellineleft;
96 vardef parallellineleft expr pppp =
97 save s, stp;
98 numeric s, stp; stp:=(arclength pppp) div 5pt;
99 if stp=0: stp:=1; fi
100 stp:=(arclength pppp)/stp;
101
102 if stp > 0:
103 for s=0 step stp until arclength pppp - stp:
104 point (arctime s of pppp) of pppp +
105 spread/2*(unitvector direction (arctime s of pppp)
106 of pppp rotated 90)
107 {direction (arctime s of pppp) of pppp}..
108 endfor
109 {direction (length pppp) of pppp}
110 point (length pppp) of pppp +
111 spread/2*(unitvector direction (length pppp)
112 of pppp rotated 90)
113 fi
114 enddef;
115
116 save mapto, n;
117 vardef mapto(text t) =
118 hide(numeric n; n:=0;
119 numeric x,x_[],y,y_[];
120 for z=t: z_[incr n]:=z; endfor;
121 transform T;
122 z_2 = z_1 transformed T;
123 z_4 = z_3 transformed T;
124 z_6 = z_5 transformed T;)
125 T
126 enddef;
127
128 % Macro for drawing the half arrow head
129
130 save pp; path pp; pp := (z3l..{2(x0-x3),y0-y3}z5r);
131 save pq; path pq; pq := (z3r..{2(x0-x3),y0-y3}z5l);
132
133 save halfarrowhead;
134 vardef halfarrowhead(expr T, s) =
135 (z0--(x0,y2l)--z2l--z2r
136 ..subpath(t,s) of pp
137 --subpath(xpart( pq intersectiontimes
138 (point s of pp -- point s of pp +(2rule_thickness#,0))),
139 length (z3r..{2(x0-x3),y0-y3}z5l)) of pq --cycle)
140 transformed T
141 enddef;
142
143 % Draw the half arrows
144
145 save pa, pb, T, tt, ttt;
146
147 save p_left; path p_left; p_left = parallellineleft apth;
148 save p_right; path p_right; p_right = parallellineright apth;
149
150 for ppp = p_left, reverse p_right:
151
152 transform T;
153 numeric tt; tt = arctime(arclength ppp - (x0-x9)) of ppp;
154 numeric ttt; ttt = arctime(arclength ppp - (x0-x2)) of ppp;
155
156 if arclength ppp = 0:
157 T:=identity shifted (point (length ppp) of ppp - z0);
158 elseif arclength ppp < x0-x3l:
159 T:=identity rotatedaround(z0,angle (direction (length ppp) of ppp))
160 shifted (point (length ppp) of ppp -z0);
161 else:
162 T:=mapto(z0,
163 point (length ppp) of ppp,
164 z2,
165 point ttt of ppp,
166 z9+(0,3rule_thickness#),
167 point tt of ppp + 3rule_thickness#*
168 (unitvector (direction tt of ppp) rotated 90));
169
170 fi
171
172 save f,s;
173 vardef f(expr s) =
174 length(point s of (pp transformed T) - point tt of ppp)
175 < length(point 0 of pp - z9)
176 enddef;
177
178 if f(0) or (arclength ppp < x0-x3l): s := 0;
179 else: s := solve f(length pp, 0);
180 fi
181
182 filldraw halfarrowhead(T,s) text_;
183
184 % Draw the path
185
186 if arclength ppp > x0-x2: draw subpath(0,ttt) of ppp
187 withpen pencircle scaled rule_thickness# text_;
188 fi
189
190 endfor;
191
192 pickup prevpen;
193
194 enddef;
195
196 enddef;