Debian Codegraph @

texmf-dist/metapost/cmarrows/rgbx0016.mp

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