Debian Codegraph @

texmf-dist/metapost/cmarrows/tgbx0001.mp

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