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