Debian Codegraph @

texmf-dist/metapost/cmarrows/tgbx0003.mp

raw
1 %% tgbx0003.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_bigbrace (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 u, designsize, curve, stem, hair, rule_thickness, eps, fine, " &
27 "fudge;" &
28
29 "u# := " & decimal u# & ";" &
30 "designsize := " & decimal designsize & ";" &
31 "curve# := " & decimal curve# & ";" &
32 "stem# := " & decimal stem# & ";" &
33 "hair# := " & decimal hair# & ";" &
34 "rule_thickness# := " & decimal rule_thickness# & ";" &
35 "eps := " & decimal eps & ";" &
36 "fine# := " & decimal fine# & ";" &
37 "fudge := " & decimal fudge & ";" &
38
39 % Time for middle piece
40
41 "save st; numeric st;" &
42 "if unknown " & cmdname & "_middle_time:" &
43 " st := arctime (arclength apth)/2 of apth;" &
44 "else: st:=" & cmdname & "_middle_time; fi")
45
46 save prevpen;
47 prevpen:=savepen;
48
49 save w; numeric w; w:=9u#;
50 save h; numeric h; h:=rule_thickness#;
51 save dh; numeric dh; dh:=0.6designsize;
52 save dw; numeric dw; dw:=curve#-stem#;
53 save d; numeric d; d :=2dh-rule_thickness#;
54 save min_breadth; numeric min_breadth;
55 min_breadth:=hair#;
56 save max_breadth; numeric max_breadth;
57 max_breadth:=stem#;
58
59 save x,y;
60 numeric x[],x[]',x[]l,x[]'l,x[]r,x[]'r,
61 y[],y[]',y[]l,y[]'l,y[]r,y[]'r;
62
63 if fine#>fudge*hair#:
64 fine# := fudge*hair#;
65 fi
66 pickup if fine#=0: nullpen else: pencircle scaled fine# fi;
67
68 forsuffixes $ = 1,1',4,4',7,7': penpos$(min_breadth,0); endfor
69 forsuffixes $ = 2,3,5,6: penpos$(max_breadth,0); endfor
70 x2=x3=x5=x6; x1=x1'=x7=x7'=w-x4=w-x4';
71 lft x4l=1.5u#-.5min_breadth; lft x2l=.5w-.5max_breadth;
72 top y1=h; bot y7=1-d; .5[y4,y4']=.5[y1,y7]=.5[y2,y6]=.5[y3,y5];
73 y1-y2=y3-y4=(y1-y4)/4;
74 y1-y1'=y4-y4'=y7'-y7=min_breadth-fine#;
75
76 save mapto, n;
77 vardef mapto(text t) =
78 hide(numeric n; n:=0;
79 numeric x,x_[],y,y_[];
80 for z=t: z_[incr n]:=z; endfor;
81 transform T;
82 z_2 = z_1 transformed T;
83 z_4 = z_3 transformed T;
84 z_6 = z_5 transformed T;)
85 T
86 enddef;
87
88 % The bottom part of the brace
89
90 save bottom_part;
91 vardef bottom_part(expr T) =
92 filldraw (z6l{down}...{3(x7l-x6l),y7-y6}z7l
93 --z7r--z7'r{3(x6r-x7r),y6-y7'}...{up}z6r--z6l & cycle)
94 transformed T text_;
95 enddef;
96
97 save f;
98 vardef f(expr s) =
99 abs(point 0 of apth - (point s of apth + abs(x7-x6)
100 *(unitvector (direction s of apth) rotated 90)))
101 < abs(z7 - z6)
102 enddef;
103
104 save tolerence; tolerence := epsilon;
105 save s; numeric s;
106
107 save T; transform T; % transform for the bottom part
108 if arclength apth = 0:
109 T:=identity shifted (point (length apth) of apth - z7r);
110 elseif arclength apth < y1-y2+y3-y5+y6-y7:
111 T:=mapto(z6l,
112 .25[point 0 of apth, point (length apth) of apth]+
113 +abs(x7r-x6l)*(unitvector (point (length apth) of apth -
114 point 0 of apth) rotated 90),
115 z6r,
116 .25[point 0 of apth, point (length apth) of apth]+
117 +abs(x7r-x6r)*(unitvector (point (length apth) of apth -
118 point 0 of apth) rotated 90),
119 z7r,
120 point 0 of apth);
121 else:
122 s := solve f(0,length apth);
123 T := mapto(z6l,
124 point s of apth
125 +abs(x7r-x6l)
126 *(unitvector (direction s of apth) rotated 90),
127 z6r,
128 point s of apth
129 +abs(x7r-x6r)
130 *(unitvector (direction s of apth) rotated 90),
131 z7r,
132 point 0 of apth);
133 fi
134 bottom_part(T);
135
136 % The top part of the brace
137
138 save top_part;
139 vardef top_part(expr T) =
140 filldraw (z1l{3(x2l-x1l),y2-y1}...{down}z2l
141 --z2r{up}...{3(x1r-x2r),y1'-y2}z1'r--z1r--cycle)
142 transformed T text_;
143 enddef;
144
145 save g;
146 vardef g(expr t) =
147 abs(point (length apth) of apth
148 - (point t of apth + abs(x1r-x2)
149 *(unitvector (direction t of apth) rotated 90)))
150 < abs(z1r-z2)
151 enddef;
152
153 save t; numeric t;
154
155 transform T; % transform the top part
156 if arclength apth = 0:
157 T:=identity shifted (point (length apth) of apth - z1r);
158 elseif arclength apth < y1-y2+y3-y5+y6-y7:
159 T := mapto(z2l,
160 .75[point 0 of apth, point (length apth) of apth] +
161 abs(x1r-x2l)*(unitvector (point (length apth) of apth -
162 point 0 of apth) rotated 90),
163 z2r,
164 .75[point 0 of apth, point (length apth) of apth] +
165 abs(x1r-x2r)*(unitvector (point (length apth) of apth -
166 point 0 of apth) rotated 90),
167 z1r,
168 point (length apth) of apth);
169 else:
170 t := solve g(length apth,0);
171 T := mapto(z2l,
172 point t of apth
173 +abs(x1r-x2l)
174 *(unitvector (direction t of apth) rotated 90),
175 z2r,
176 point t of apth
177 +abs(x1r-x2r)
178 *(unitvector (direction t of apth) rotated 90),
179 z1r,
180 point (length apth) of apth);
181 fi
182 top_part(T);
183
184 % The lower part of the middle piece
185
186 save middle_part_bottom;
187 vardef middle_part_bottom(expr T) =
188 (.5[z4r,z4'r]{3(x5r-x4r),y5-.5[y4,y4']}...{down}z5r
189 --z5l{up}...{3(x4l-x5l),y4'-y5}z4'l) transformed T
190 enddef;
191
192 save ff;
193 vardef ff(expr ss) =
194 abs(point st of apth
195 +abs(x7r-x4)*(unitvector (direction st of apth) rotated 90)
196 -(point ss of apth + abs(x7r-x5)
197 *(unitvector (direction ss of apth) rotated 90)))
198 > abs(z4-z5)
199 enddef;
200
201 save ss; numeric ss;
202
203 if arclength apth = 0:
204 T:=identity shifted (point (length apth) of apth - z4'l);
205 elseif arclength apth < y1-y2+y3-y5+y6-y7:
206 T:=mapto(.5[z4r,z4'r],
207 .5[point 0 of apth, point (length apth) of apth]+
208 abs(x1r-.5[x4r,x4'r])
209 *(unitvector (point (length apth) of apth -
210 point 0 of apth) rotated 90),
211 z5l,
212 .25[point 0 of apth, point (length apth) of apth]+
213 abs(x1r-x5l)*(unitvector (point (length apth) of apth -
214 point 0 of apth) rotated 90),
215 z5r,
216 .25[point 0 of apth, point (length apth) of apth]+
217 abs(x1r-x5r)*(unitvector (point (length apth) of apth -
218 point 0 of apth) rotated 90));
219 else:
220 ss := solve ff(0,st);
221 T:=mapto(.5[z4r,z4'r],
222 point st of apth
223 +abs(x1r-.5[x4r,x4'r])
224 *(unitvector (direction st of apth) rotated 90),
225 z5l,
226 point ss of apth
227 +abs(x1r-x5l)
228 *(unitvector (direction ss of apth) rotated 90),
229 z5r,
230 point ss of apth
231 +abs(x1r-x5r)
232 *(unitvector (direction ss of apth) rotated 90));
233 fi
234
235 save pb; path pb;
236 pb:=middle_part_bottom(T);
237
238 % The upper part of the middle piece
239
240 save middle_part_top;
241 vardef middle_part_top(expr T) =
242 (z4l{3(x3l-x4l),y3-y4}...{up}z3l--z3r{down}
243 ...{3(x4r-x3r),.5[y4,y4']-y3}.5[z4r,z4'r]) transformed T
244 enddef;
245
246 save gg;
247 vardef gg(expr tt) =
248 abs(point st of apth
249 +abs(x1r-x4)*(unitvector (direction st of apth) rotated 90)
250 -(point tt of apth + abs(x1r-x3)
251 *(unitvector (direction tt of apth) rotated 90)))
252 > abs(z3-z4)
253 enddef;
254
255 save tt; numeric tt;
256
257 if arclength apth = 0:
258 T:=identity shifted (point (length apth) of apth - z4l);
259 elseif arclength apth < y1-y2+y3-y5+y6-y7:
260 T:=mapto(.5[z4r,z4'r],
261 .5[point 0 of apth, point (length apth) of apth]+
262 abs(x1r-.5[x4r,x4'r])
263 *(unitvector (point (length apth) of apth -
264 point 0 of apth) rotated 90),
265 z3l,
266 .75[point 0 of apth, point (length apth) of apth]+
267 abs(x1r-x3l)*(unitvector (point (length apth) of apth -
268 point 0 of apth) rotated 90),
269 z3r,
270 .75[point 0 of apth, point (length apth) of apth]+
271 abs(x1r-x3r)*(unitvector (point (length apth) of apth -
272 point 0 of apth) rotated 90));
273 else:
274 tt := solve gg(length apth, st);
275 T := mapto(.5[z4r,z4'r],
276 point st of apth
277 +abs(x1r-.5[x4r,x4'r])
278 *(unitvector (direction st of apth) rotated 90),
279 z3l,
280 point tt of apth
281 +abs(x1r-x3l)
282 *(unitvector (direction tt of apth) rotated 90),
283 z3r,
284 point tt of apth
285 +abs(x1r-x3r)
286 *(unitvector (direction tt of apth) rotated 90));
287 fi
288
289 save ptt; path ptt;
290 ptt:=middle_part_top(T);
291
292 filldraw pb--ptt--cycle text_;
293
294 % The extension parts
295
296 save extension_part, stp;
297 vardef extension_part(expr ss,tt) =
298 numeric stp; stp:=(ss-tt) div 5pt;
299 if stp=0: stp:=1; fi
300 stp:=(ss-tt)/stp;
301
302 pickup pencircle scaled (x5r-x5l+fine#);
303
304 if stp > 0:
305 draw for uu=ss step stp until tt-stp:
306 point uu of apth + abs(x1r-x6)
307 *(unitvector (direction uu of apth) rotated 90)
308 {direction uu of apth} ..
309 endfor
310 {direction tt of apth}
311 point tt of apth + abs(x1r-x6)
312 *(unitvector (direction tt of apth) rotated 90) text_;
313 fi
314 enddef;
315
316 if arclength apth > y1-y2+y3-y5+y6-y7:
317 extension_part(s,ss); extension_part(tt,t);
318 fi
319
320 pickup prevpen;
321
322 enddef;
323
324 enddef;
325