| 1 |
%% tgbx0006.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_parallelarrows (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 & "__tgbxww")(p) |
| 21 |
enddef; |
| 22 |
|
| 23 |
expandafter vardef scantokens (cmdname & "__tgbxww " & "(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 |
|
| 48 |
save spread, w; |
| 49 |
numeric spread, w; |
| 50 |
|
| 51 |
if crisp#>fudge*hair#: |
| 52 |
crisp#:=fudge*hair#; |
| 53 |
fi |
| 54 |
pickup if crisp#=0: nullpen else: pencircle scaled crisp# fi; |
| 55 |
|
| 56 |
spread = math_spread[.45x_height#, .55x_height#]; |
| 57 |
w = 18u#; |
| 58 |
|
| 59 |
penpos1(rule_thickness#, 90); penpos2(rule_thickness#, 90); |
| 60 |
penpos3(bar#, 0); penpos4(bar#, 0); |
| 61 |
y0=y1=y2=math_axis#; x1-.5rule_thickness#=u#; rt x0=w-u#; |
| 62 |
y3-y0=y0-y4=.24asc_height#+eps; |
| 63 |
x3=x4=x0-3u#-eps; |
| 64 |
penpos5(bar#, angle(z4-z0)); z5l=z0; |
| 65 |
penpos6(bar#, angle(z3-z0)); z6l=z0; |
| 66 |
z9=.381966[.5[z3,z4],z0]; |
| 67 |
|
| 68 |
save pp; path pp; pp = z4l{z9-z4}..z6r; |
| 69 |
save t; numeric t; t = xpart(pp intersectiontimes ((0,y2l)--(w,y2l))); |
| 70 |
x2=xpart point t of pp; |
| 71 |
|
| 72 |
save texarrowhead; |
| 73 |
vardef texarrowhead(expr T) = |
| 74 |
filldraw (z0..{z4-z9}z4r--subpath(0,t) of pp |
| 75 |
--z2l--z2r--subpath(t,0) of (z3l{z9-z3}..z5r) |
| 76 |
--z3r{z9-z3}..z0 & cycle) transformed T text_; |
| 77 |
enddef; |
| 78 |
|
| 79 |
save mapto, n; |
| 80 |
vardef mapto(text t) = |
| 81 |
hide(numeric n; n:=0; |
| 82 |
numeric x,x_[],y,y_[]; |
| 83 |
for z=t: z_[incr n]:=z; endfor; |
| 84 |
transform T; |
| 85 |
z_2 = z_1 transformed T; |
| 86 |
z_4 = z_3 transformed T; |
| 87 |
z_6 = z_5 transformed T;) |
| 88 |
T |
| 89 |
enddef; |
| 90 |
|
| 91 |
save tt; numeric tt; tt = arctime(arclength apth - (x0-x3l)) of apth; |
| 92 |
save ttt; numeric ttt; ttt = arctime(arclength apth - (x0-x2)) of apth; |
| 93 |
|
| 94 |
save parallelline; |
| 95 |
vardef parallelline expr ppp = |
| 96 |
save s, stp; |
| 97 |
numeric s, stp; stp:=(arclength ppp) div 5pt; |
| 98 |
if stp=0: stp:=1; fi |
| 99 |
stp:=(arclength ppp)/stp; |
| 100 |
|
| 101 |
if stp>0: |
| 102 |
draw for s=0 step stp until arclength ppp - stp: |
| 103 |
point (arctime s of ppp) of ppp + |
| 104 |
(.24asc_height#+eps)*(unitvector direction (arctime s of ppp) |
| 105 |
of ppp rotated 90) |
| 106 |
{direction (arctime s of ppp) of ppp}.. |
| 107 |
endfor |
| 108 |
{direction (length ppp) of ppp} |
| 109 |
point (length ppp) of ppp + |
| 110 |
(.24asc_height#+eps)*(unitvector direction (length ppp) |
| 111 |
of ppp rotated 90) |
| 112 |
withpen pencircle scaled rule_thickness# text_; |
| 113 |
|
| 114 |
draw for s=0 step stp until arclength ppp - stp: |
| 115 |
point (arctime s of ppp) of ppp - |
| 116 |
(.24asc_height#+eps)*(unitvector direction (arctime s of ppp) |
| 117 |
of ppp rotated 90) |
| 118 |
{direction (arctime s of ppp) of ppp}.. |
| 119 |
endfor |
| 120 |
{direction (length ppp) of ppp} |
| 121 |
point (length ppp) of ppp - |
| 122 |
(.24asc_height#+eps)*(unitvector direction (length ppp) |
| 123 |
of ppp rotated 90) |
| 124 |
withpen pencircle scaled rule_thickness# text_; |
| 125 |
fi |
| 126 |
enddef; |
| 127 |
|
| 128 |
if arclength apth > x0-x2: parallelline subpath(0,ttt) of apth; fi |
| 129 |
|
| 130 |
save T; transform T; |
| 131 |
if arclength apth = 0: |
| 132 |
T:=identity shifted (point (length apth) of apth - z0) |
| 133 |
shifted (0,.24asc_height#+eps); |
| 134 |
elseif arclength apth < x0-x3l: |
| 135 |
T:=identity rotatedaround(z0,angle (direction (length apth) of apth)) |
| 136 |
shifted (point (length apth) of apth - z0) |
| 137 |
shifted ((.24asc_height#+eps)* |
| 138 |
(unitvector (direction (length apth) of apth) rotated 90)); |
| 139 |
else: |
| 140 |
T:=mapto(z0, |
| 141 |
point (length apth) of apth + |
| 142 |
(.24asc_height#+eps)* |
| 143 |
(unitvector (direction (length apth) of apth) rotated 90), |
| 144 |
z2, |
| 145 |
point ttt of apth + |
| 146 |
(.24asc_height#+eps)* |
| 147 |
(unitvector (direction (length apth) of apth) rotated 90), |
| 148 |
z3l, |
| 149 |
point tt of apth); |
| 150 |
fi |
| 151 |
texarrowhead(T); |
| 152 |
|
| 153 |
if arclength apth = 0: |
| 154 |
T:=identity shifted (point (length apth) of apth - z0) |
| 155 |
shifted (0,-.24asc_height#+eps); |
| 156 |
elseif arclength apth < x0-x3l: |
| 157 |
T:=identity rotatedaround(z0,angle (direction (length apth) of apth)) |
| 158 |
shifted (point (length apth) of apth - z0) |
| 159 |
shifted ((.24asc_height#+eps)* |
| 160 |
(unitvector (direction (length apth) of apth) rotated -90)); |
| 161 |
else: |
| 162 |
T:=mapto(z0, |
| 163 |
point (length apth) of apth - |
| 164 |
(.24asc_height#+eps)* |
| 165 |
(unitvector (direction (length apth) of apth) rotated 90), |
| 166 |
z2, |
| 167 |
point ttt of apth - |
| 168 |
(.24asc_height#+eps)* |
| 169 |
(unitvector (direction (length apth) of apth) rotated 90), |
| 170 |
z4l, |
| 171 |
point tt of apth); |
| 172 |
fi |
| 173 |
texarrowhead(T); |
| 174 |
|
| 175 |
pickup prevpen; |
| 176 |
|
| 177 |
enddef; |
| 178 |
|
| 179 |
enddef; |