| 1 |
%% sgbx0014.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_doublearrow (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, 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 |
lft x1 = u#-eps; x2=x1; x7=x8=w-x1; |
| 61 |
y1=y7; y2=y8; y1-y2=spread; .5[y1,y2]=math_axis#; |
| 62 |
|
| 63 |
rt x0 = w-u#+eps; y0 = math_axis#; |
| 64 |
penpos3(rule_thickness#,0); penpos4(rule_thickness#,0); |
| 65 |
y3-y1 = y2-y4 = .24asc_height#+eps; x3=x4=x0-6u#-eps; |
| 66 |
penpos5(rule_thickness#, angle(z4-z0)); z5l=z0; |
| 67 |
penpos6(rule_thickness#, angle(z3-z0)); z6l=z0; |
| 68 |
z9 = .381966[.5[z3,z4],z0]; |
| 69 |
|
| 70 |
save pp; |
| 71 |
path pp; pp = z4l{z9-z4}..z6r; |
| 72 |
save t; |
| 73 |
numeric t; t = xpart(pp intersectiontimes ((0,y0)--(w,y0))); |
| 74 |
numeric t[]; t1 = xpart(pp intersectiontimes ( (0,y2-rule_thickness#/2) |
| 75 |
--(w,y2-rule_thickness#/2))); |
| 76 |
t2 = xpart(pp intersectiontimes ( (0,y2+rule_thickness#/2) |
| 77 |
--(w,y2+rule_thickness#/2))); |
| 78 |
save qq; |
| 79 |
path qq; qq = z3l{z9-z3}..z5r; |
| 80 |
|
| 81 |
save parallelline; |
| 82 |
vardef parallelline expr ppp = |
| 83 |
save s, stp; |
| 84 |
numeric s, stp; stp:=(arclength ppp) div 5pt; |
| 85 |
if stp=0: stp:=1; fi |
| 86 |
stp:=(arclength ppp)/stp; |
| 87 |
|
| 88 |
if stp > 0: |
| 89 |
draw for s=0 step stp until arclength ppp - stp: |
| 90 |
point (arctime s of ppp) of ppp + |
| 91 |
spread/2* |
| 92 |
(unitvector direction (arctime s of ppp) of ppp rotated 90) |
| 93 |
{direction (arctime s of ppp) of ppp}.. |
| 94 |
endfor |
| 95 |
{direction (length ppp) of ppp} |
| 96 |
point (length ppp) of ppp + |
| 97 |
spread/2* |
| 98 |
(unitvector direction (length ppp) of ppp rotated 90) |
| 99 |
withpen pencircle scaled rule_thickness# text_; |
| 100 |
|
| 101 |
draw for s=0 step stp until arclength ppp - stp: |
| 102 |
point (arctime s of ppp) of ppp - |
| 103 |
spread/2* |
| 104 |
(unitvector direction (arctime s of ppp) of ppp rotated 90) |
| 105 |
{direction (arctime s of ppp) of ppp}.. |
| 106 |
endfor |
| 107 |
{direction (length ppp) of ppp} |
| 108 |
point (length ppp) of ppp - |
| 109 |
spread/2* |
| 110 |
(unitvector direction (length ppp) of ppp rotated 90) |
| 111 |
withpen pencircle scaled rule_thickness# text_; |
| 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 |
% Draw the arrow head |
| 128 |
|
| 129 |
save doublearrowhead; |
| 130 |
vardef doublearrowhead(expr T, s, ss) = |
| 131 |
(subpath(0, xpart((z0..{z4-z9}z4r) intersectiontimes |
| 132 |
(point s of pp -- point s of pp + (2rule_thickness#,0)))) |
| 133 |
of (z0..{z4-z9}z4r) |
| 134 |
--subpath(s,t1) of pp |
| 135 |
--(xpart point t1 of pp, ypart point t2 of pp) |
| 136 |
--subpath(t2,t) of pp |
| 137 |
--subpath(t,t2) of qq |
| 138 |
--(xpart point t1 of qq, ypart point t2 of qq) |
| 139 |
--subpath(t1,ss) of qq |
| 140 |
--subpath(xpart ((z3r{z9-z3}..z0) intersectiontimes |
| 141 |
(point ss of qq -- point ss of qq + (2rule_thickness#,0))),1) |
| 142 |
of (z3r{z9-z3}..z0) |
| 143 |
& cycle) transformed T |
| 144 |
enddef; |
| 145 |
|
| 146 |
save T; transform T; |
| 147 |
save tt; |
| 148 |
tt = arctime (arclength apth - (x0 - xpart point t1 of pp)) of apth; |
| 149 |
|
| 150 |
if arclength apth = 0: |
| 151 |
T:=identity shifted (point (length apth) of apth - z0); |
| 152 |
elseif arclength apth < x0-xpart(point t2 of pp): |
| 153 |
T:=identity rotatedaround(z0,angle (direction (length apth) of apth)) |
| 154 |
shifted (point (length apth) of apth - z0); |
| 155 |
else: |
| 156 |
T := mapto( |
| 157 |
z0, |
| 158 |
point (length apth) of apth, |
| 159 |
point t1 of pp + (0,rule_thickness#/2), |
| 160 |
point tt of apth + |
| 161 |
spread/2*(unitvector direction tt of apth rotated 90), |
| 162 |
point t1 of qq - (0,rule_thickness#/2), |
| 163 |
point tt of apth - |
| 164 |
spread/2*(unitvector direction tt of apth rotated 90)); |
| 165 |
fi |
| 166 |
|
| 167 |
save f,s,ss,ttt; |
| 168 |
ttt = arctime(arclength apth - (x0-x9)) of apth; |
| 169 |
vardef f(expr s) = |
| 170 |
length(point s of (pp transformed T) - point ttt of apth) |
| 171 |
< length(point 0 of pp - z9) |
| 172 |
enddef; |
| 173 |
|
| 174 |
if f(0) or (arclength apth < x0-x3l): s := 0; |
| 175 |
else: s := solve f(length pp, 0); |
| 176 |
fi |
| 177 |
|
| 178 |
vardef f(expr ss) = |
| 179 |
length(point ss of (qq transformed T) - point ttt of apth) |
| 180 |
< length(point 0 of qq - z9) |
| 181 |
enddef; |
| 182 |
|
| 183 |
if f(0) or (arclength apth < x0-x3l): ss := 0; |
| 184 |
else: ss := solve f(length qq, 0); |
| 185 |
fi |
| 186 |
|
| 187 |
filldraw doublearrowhead(T,s,ss) text_; |
| 188 |
|
| 189 |
% Draw the path |
| 190 |
|
| 191 |
if arclength apth > (x0-xpart(point t1 of pp)): |
| 192 |
parallelline (subpath(0,tt) of apth); |
| 193 |
fi |
| 194 |
|
| 195 |
pickup prevpen; |
| 196 |
|
| 197 |
enddef; |
| 198 |
|
| 199 |
enddef; |