summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/cmarrows/tgbx0004.mp
blob: ec0b4d7d70066c14f9df9123c2ae9332606db1c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
%% tgbx0004.mp
%% Copyright 2006 Tommy Ekola <tek@kth.se>
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
% or (at your option) any later version.  The latest version of this
% license is in http://www.latex-project.org/lppl.txt
%
% This work has the LPPL maintenance status `maintained'.  The Current
% Maintainer of this work is Tommy Ekola.  The Base Interpreter is
% MetaPost.

vardef setup_biggbrace (expr source_file, cmdname) =

  scantokens ("input tgbx0000");

  scantokens ("input " & source_file);

  expandafter def scantokens cmdname expr p =
    scantokens (cmdname & "__tgbxww")(p)
  enddef;

  expandafter vardef scantokens (cmdname & "__tgbxww " & "(expr apth) " &
    "text text_ = " &

    "save u, designsize, curve, stem, hair, rule_thickness, eps, fine, " &
          "fudge;" &

    "u#              := " & decimal u# & ";" &
    "designsize      := " & decimal designsize & ";" &
    "curve#          := " & decimal curve# & ";" &
    "stem#           := " & decimal stem# & ";" &
    "hair#           := " & decimal hair# & ";" &
    "rule_thickness# := " & decimal rule_thickness# & ";" &
    "eps             := " & decimal eps & ";" &
    "fine#           := " & decimal fine# & ";" &
    "fudge           := " & decimal fudge & ";" &
  
    % Time for middle piece

    "save st; numeric st;" &
    "if unknown " & cmdname & "_middle_time:" &
    "  st := arctime (arclength apth)/2 of apth;" &
    "else: st:=" & cmdname & "_middle_time; fi")

    save prevpen;
    prevpen:=savepen;

    save w; numeric w;  w:=11u#;
    save h; numeric h;  h:=rule_thickness#;
    save dh; numeric dh; dh:=0.6designsize;
    save dw; numeric dw; dw:=curve#-stem#;
    save d; numeric d;  d :=4dh-rule_thickness#;
    save bold; numeric bold; bold:=curve#;
    save min_breadth; numeric min_breadth; 
           min_breadth:=rule_thickness#+.2dw;
    save max_breadth; numeric max_breadth;
           max_breadth:=bold;

    save x,y;
    numeric x[],x[]',x[]l,x[]'l,x[]r,x[]'r,
            y[],y[]',y[]l,y[]'l,y[]r,y[]'r;

    if fine#>fudge*hair#:
      fine#:=fudge*hair#;
    fi
    pickup if fine#=0: nullpen else: pencircle scaled fine# fi;

    forsuffixes $ = 1,1',4,4',7,7': penpos$(min_breadth,0); endfor
    forsuffixes $ = 2,3,5,6: penpos$(max_breadth,0); endfor
    x2=x3=x5=x6; x1=x1'=x7=x7'=w-x4=w-x4';
    lft x4l=1.5u#-.5min_breadth; lft x2l=.5w-.5max_breadth;
    top y1=h; bot y7=1-d; .5[y4,y4']=.5[y1,y7]=.5[y2,y6]=.5[y3,y5];
    y1-y2=y3-y4=(y1-y4)/4;
    y1-y1'=y4-y4'=y7'-y7=min_breadth-fine#;

    save mapto, n;
    vardef mapto(text t) =
      hide(numeric n; n:=0;
           numeric x,x_[],y,y_[];
           for z=t: z_[incr n]:=z; endfor;
           transform T;
           z_2 = z_1 transformed T;
           z_4 = z_3 transformed T;
           z_6 = z_5 transformed T;)
      T
    enddef;

    % The bottom part of the brace

    save bottom_part;
    vardef bottom_part(expr T) =
      filldraw (z6l{down}...{3(x7l-x6l),y7-y6}z7l
                --z7r--z7'r{3(x6r-x7r),y6-y7'}...{up}z6r--z6l & cycle)
               transformed T text_;
    enddef;

    save f;
    vardef f(expr s) =
      abs(point 0 of apth - (point s of apth + abs(x7-x6)
                             *(unitvector (direction s of apth) rotated 90)))
      < abs(z7 - z6)
    enddef;
  
    save tolerence; tolerence := epsilon;
    save s; numeric s; 

    save T; transform T; % transform for the bottom part
    if arclength apth = 0:
      T:=identity shifted (point (length apth) of apth - z7r);
    elseif arclength apth < y1-y2+y3-y5+y6-y7:
      T:=mapto(z6l,
	       .25[point 0 of apth, point (length apth) of apth]+
	       +abs(x7r-x6l)*(unitvector (point (length apth) of apth -
		                          point 0 of apth) rotated 90),
               z6r,
	       .25[point 0 of apth, point (length apth) of apth]+
	       +abs(x7r-x6r)*(unitvector (point (length apth) of apth -
		                          point 0 of apth) rotated 90),
               z7r,
               point 0 of apth);		      
    else:
      s := solve f(0,length apth);
      T := mapto(z6l,
                 point s of apth 
                             +abs(x7r-x6l)
                                *(unitvector (direction s of apth) rotated 90),
                 z6r,
                 point s of apth 
                             +abs(x7r-x6r)
                                *(unitvector (direction s of apth) rotated 90),
                 z7r,
                 point 0 of apth);
    fi
    bottom_part(T);
  
    % The top part of the brace

    save top_part;  
    vardef top_part(expr T) =
      filldraw (z1l{3(x2l-x1l),y2-y1}...{down}z2l
                --z2r{up}...{3(x1r-x2r),y1'-y2}z1'r--z1r--cycle)
               transformed T text_;
    enddef;

    save g;
    vardef g(expr t) =
      abs(point (length apth) of apth 
                            - (point t of apth + abs(x1r-x2)
                             *(unitvector (direction t of apth) rotated 90)))
      < abs(z1r-z2)
    enddef;
  
    save t; numeric t; 
  
    transform T; % transform the top part
    if arclength apth = 0:
      T:=identity shifted (point (length apth) of apth - z1r);
    elseif arclength apth < y1-y2+y3-y5+y6-y7:
      T := mapto(z2l,
                 .75[point 0 of apth, point (length apth) of apth] +
                 abs(x1r-x2l)*(unitvector (point (length apth) of apth -
		                           point 0 of apth) rotated 90),
                 z2r,
                 .75[point 0 of apth, point (length apth) of apth] +
                 abs(x1r-x2r)*(unitvector (point (length apth) of apth -
		                           point 0 of apth) rotated 90),
                 z1r,
                 point (length apth) of apth);
    else:    
      t := solve g(length apth,0);
      T := mapto(z2l,
                 point t of apth 
                         +abs(x1r-x2l)
                             *(unitvector (direction t of apth) rotated 90),
                 z2r,
                 point t of apth 
                         +abs(x1r-x2r)
                             *(unitvector (direction t of apth) rotated 90),
                 z1r,
                 point (length apth) of apth);
    fi
    top_part(T);

    % The lower part of the middle piece

    save middle_part_bottom;
    vardef middle_part_bottom(expr T) =
      (.5[z4r,z4'r]{3(x5r-x4r),y5-.5[y4,y4']}...{down}z5r
        --z5l{up}...{3(x4l-x5l),y4'-y5}z4'l) transformed T
    enddef;

    save ff;
    vardef ff(expr ss) =
      abs(point st of apth
           +abs(x7r-x4)*(unitvector (direction st of apth) rotated 90)
           -(point ss of apth + abs(x7r-x5)
                             *(unitvector (direction ss of apth) rotated 90)))
      > abs(z4-z5)
    enddef;
  
    save ss; numeric ss; 

    if arclength apth = 0:
      T:=identity shifted (point (length apth) of apth - z4'l);
    elseif arclength apth < y1-y2+y3-y5+y6-y7:
      T:=mapto(.5[z4r,z4'r],
	       .5[point 0 of apth, point (length apth) of apth]+
               abs(x1r-.5[x4r,x4'r])
	       *(unitvector (point (length apth) of apth -
		             point 0 of apth) rotated 90),
              z5l,
              .25[point 0 of apth, point (length apth) of apth]+
              abs(x1r-x5l)*(unitvector (point (length apth) of apth -
		                        point 0 of apth) rotated 90),
              z5r,          
              .25[point 0 of apth, point (length apth) of apth]+
              abs(x1r-x5r)*(unitvector (point (length apth) of apth -
		                        point 0 of apth) rotated 90));
    else:
      ss := solve ff(0,st);
      T:=mapto(.5[z4r,z4'r],
               point st of apth
               +abs(x1r-.5[x4r,x4'r])
                   *(unitvector (direction st of apth) rotated 90),
              z5l,
              point ss of apth 
                        +abs(x1r-x5l)
                            *(unitvector (direction ss of apth) rotated 90),
              z5r,          
              point ss of apth 
                        +abs(x1r-x5r)
                              *(unitvector (direction ss of apth) rotated 90));
    fi
			    
    save pb; path pb;
    pb:=middle_part_bottom(T);
  
    % The upper part of the middle piece

    save middle_part_top;
    vardef middle_part_top(expr T) =
      (z4l{3(x3l-x4l),y3-y4}...{up}z3l--z3r{down}
       ...{3(x4r-x3r),.5[y4,y4']-y3}.5[z4r,z4'r]) transformed T
    enddef;

    save gg;
    vardef gg(expr tt) =
      abs(point st of apth
           +abs(x1r-x4)*(unitvector (direction st of apth) rotated 90)
           -(point tt of apth + abs(x1r-x3)
                             *(unitvector (direction tt of apth) rotated 90)))
      > abs(z3-z4)
    enddef;
  
    save tt; numeric tt; 
    if arclength apth = 0:
      T:=identity shifted (point (length apth) of apth - z4l);
    elseif arclength apth < y1-y2+y3-y5+y6-y7:
      T:=mapto(.5[z4r,z4'r],
	       .5[point 0 of apth, point (length apth) of apth]+
               abs(x1r-.5[x4r,x4'r])
	       *(unitvector (point (length apth) of apth -
		             point 0 of apth) rotated 90),
              z3l,
              .75[point 0 of apth, point (length apth) of apth]+
              abs(x1r-x3l)*(unitvector (point (length apth) of apth -
		                        point 0 of apth) rotated 90),
              z3r,          
              .75[point 0 of apth, point (length apth) of apth]+
              abs(x1r-x3r)*(unitvector (point (length apth) of apth -
		                        point 0 of apth) rotated 90));
    else:
      tt := solve gg(length apth, st);
      T := mapto(.5[z4r,z4'r],
                 point st of apth
                 +abs(x1r-.5[x4r,x4'r])
                     *(unitvector (direction st of apth) rotated 90),
                 z3l,
                 point tt of apth 
                         +abs(x1r-x3l)
                              *(unitvector (direction tt of apth) rotated 90),
                z3r,
                point tt of apth 
                         +abs(x1r-x3r)
                              *(unitvector (direction tt of apth) rotated 90));
    fi
			    
    save ptt; path ptt;
    ptt:=middle_part_top(T);
  
    filldraw pb--ptt--cycle text_;
  
    % The extension parts

    save extension_part, stp;  
    vardef extension_part(expr ss,tt) =
      numeric    stp; stp:=(ss-tt) div 5pt;
                      if stp=0: stp:=1; fi
                      stp:=(ss-tt)/stp;
  
      pickup pencircle scaled (x5r-x5l+fine#);
  
      if stp > 0:
      draw for uu=ss step stp until tt-stp:
        point uu of apth + abs(x1r-x6)
                             *(unitvector (direction uu of apth) rotated 90)
        {direction uu of apth} ..
      endfor
      {direction tt of apth}
      point tt of apth + abs(x1r-x6)
                         *(unitvector (direction tt of apth) rotated 90) text_;
      fi
    enddef;
  
    if arclength apth > y1-y2+y3-y5+y6-y7:
      extension_part(s,ss); extension_part(tt,t);
    fi
    
    pickup prevpen;
  
  enddef;
  
enddef;