Debian Codegraph @

texmf-dist/metapost/cmarrows/sgbx0015.mp

raw
1 %% sgbx0015.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_lefthalfarrow (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(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 mapto, n;
73 vardef mapto(text t) =
74 hide(numeric n; n:=0;
75 numeric x,x_[],y,y_[];
76 for z=t: z_[incr n]:=z; endfor;
77 transform T;
78 z_2 = z_1 transformed T;
79 z_4 = z_3 transformed T;
80 z_6 = z_5 transformed T;)
81 T
82 enddef;
83
84 save T; transform T;
85 save tt; numeric tt; tt = arctime(arclength apth - (x0-x9)) of apth;
86 save ttt; numeric ttt; ttt = arctime(arclength apth - (x0-x2)) of apth;
87
88 % Draw the arrow head
89
90 save pp; path pp; pp := (z3l..{2(x0-x3),y0-y3}z5r);
91 save pq; path pq; pq := (z3r..{2(x0-x3),y0-y3}z5l);
92
93 save halfarrowhead, pa;
94 vardef halfarrowhead(expr T, s) =
95 (z0--(x0,y2l)--z2l--z2r
96 ..subpath(t,s) of pp
97 --subpath(xpart( pq intersectiontimes
98 (point s of pp -- point s of pp +(2rule_thickness#,0))),
99 length (z3r..{2(x0-x3),y0-y3}z5l)) of pq --cycle)
100 transformed T
101 enddef;
102
103 if arclength apth = 0:
104 T:=identity shifted (point (length apth) of apth - z0);
105 elseif arclength apth < x0-x3l:
106 T:=identity rotatedaround(z0,angle (direction (length apth) of apth))
107 shifted (point (length apth) of apth -z0);
108 else:
109 T:=mapto(z0,
110 point (length apth) of apth,
111 z2,
112 point ttt of apth,
113 z9+(0,3rule_thickness#),
114 point tt of apth + 3rule_thickness#*
115 (unitvector (direction tt of apth) rotated 90));
116
117 fi
118
119 save f,s;
120 vardef f(expr s) =
121 length(point s of (pp transformed T) - point tt of apth)
122 < length(point 0 of pp - z9)
123 enddef;
124
125 if f(0) or (arclength apth < x0-x3l): s := 0;
126 else: s := solve f(length pp, 0);
127 fi
128
129 filldraw halfarrowhead(T,s) text_;
130
131 % Draw the path
132
133 if arclength apth > x0-x2: draw subpath(0,ttt) of apth
134 withpen pencircle scaled rule_thickness# text_;
135 fi
136
137 pickup prevpen;
138
139 enddef;
140
141 enddef;