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