Debian Codegraph @

texmf-dist/fonts/source/public/mdsymbol/mdbase.mf

raw
1 %
2 % Copyright (c) 2011, 2012, Sebastian Schubert <[email protected]>
3 %
4 % This Font Software is licensed under the SIL Open Font License,
5 % Version 1.1. This license is in the accompanying file OFL.txt, and
6 % is also available with a FAQ at: http://scripts.sil.org/OFL
7 %
8
9 design_size := 10;
10 font_size design_size * pt#;
11
12 if known ps_output:
13 font_version := "2.000";
14 font_comment := "Copyright (c) 2012, Sebastian Schubert. This Font Software is licensed under the SIL Open Font License, Version 1.1.";
15 fi
16
17 u# := 0.57pt#;
18 cap_height# := 6.74pt#; %7.37pt#;
19 asc_height# := 7.10pt#; % 8.56pt#;
20 desc_depth# := 1.98pt#; % 2.94pt#;
21 x_height# := 4.84pt#;
22 math_axis# := 2.75pt#;
23 if weight_index = 0: % Light
24 line_thickness# := 0.40pt#;
25 letter_line_thickness# := 0.40pt#;
26 dot_size# := line_thickness#;
27 elseif weight_index = 1: % Regular
28 line_thickness# := 0.68pt#;
29 letter_line_thickness# := 0.73pt#;
30 dot_size# := line_thickness#;
31 elseif weight_index = 2: % Semibold
32 line_thickness# := 0.93pt#;
33 letter_line_thickness# := 1.01pt#;
34 dot_size# := 0.85pt#;
35 else: % Bold
36 line_thickness# := 1.14pt#;
37 letter_line_thickness# := 1.25pt#;
38 dot_size# := 1.0pt#;
39 fi;
40
41 side_bearing# := 1.u#;
42 small_op_size# := 8u#; % radius of small operators
43 med_op_size# := 12.5u#; % radius of medium operators
44 plus_size# := 9u#;
45 large_op_size# := 18u#; % radius of large operators
46 order_width# := 8u#; % width of equal sign
47 turnstile_width# := 11u#; % width of turnstile symbols
48 equal_spread# := .7math_axis#; % distance between the lines of the equal sign
49 greater_spread# := 10/4equal_spread#; % distance between the ends of the greater sign
50 arrow_horiz_len# := 12.5u#; % length of horizontal arrows
51 arrow_vert_len# := 12.5u#; % length of vertical arrows
52 arrow_diag_len# := 1/2(arrow_horiz_len# + arrow_vert_len#);
53 arrow_spread# := 1.6equal_spread#;
54 delim_height# := 4.9pt#; % half the height of normal delimiters
55 bigop_height# := 10.7pt#; % height of big operators
56 accent_height# := x_height# + 1.u#; % height of accents
57 accent_thickness# := 4/5line_thickness#;
58 rule_thickness# := line_thickness#;
59
60 mode_setup;
61
62 define_pixels(u, asc_height, cap_height, desc_depth, delim_height, bigop_height, x_height);
63 define_whole_pixels(dot_size, small_op_size, med_op_size, large_op_size, plus_size,
64 order_width, turnstile_width, equal_spread, greater_spread,
65 arrow_horiz_len, arrow_vert_len, arrow_diag_len, arrow_spread);
66
67 if known ps_output:
68 define_pixels(math_axis, line_thickness, letter_line_thickness, rule_thickness, side_bearing, accent_height, accent_thickness);
69 else:
70 math_axis := good.y(math_axis# * hppp);
71 line_thickness := ceiling(line_thickness# * hppp);
72 letter_line_thickness := ceiling(letter_line_thickness# * hppp);
73 rule_thickness := ceiling(rule_thickness# * hppp);
74 side_bearing := ceiling(side_bearing# * hppp);
75 accent_height := ceiling(accent_height# * hppp);
76 accent_thickness := ceiling(accent_thickness# * hppp);
77 fi
78
79 stroke_through_thickness := 4/5line_thickness;
80 bop_thickness_fac := 1.; % make big operators that much thicker
81 % (including sum and integral)
82
83 % Macros
84
85 def ppos_cut(suffix $)(expr a, b) =
86 ppos_cut_linethick($)(line_thickness, a, b);
87 enddef;
88
89 def ppos_cut_linethick(suffix $)(expr lt, a, b) =
90 if sind(a-b) = 0 :
91 penpos$(lt,0);
92 else:
93 penpos$(lt/abs(sind(a-b)),b);
94 fi
95 enddef;
96
97
98 % Redefine clockwise and counterclockwise (turningnumber seems more stable)
99 if known ps_output:
100 vardef counterclockwise primary p =
101 (if turningnumber p>0: p else: (reverse p) fi)
102 enddef;
103
104 vardef clockwise primary p =
105 (if turningnumber p<0: p else: (reverse p) fi)
106 enddef;
107 fi
108
109 % Selects the n-th element of a list
110 def select(expr n)(text values) =
111 begingroup;
112 i := 0;
113 for v = values:
114 result := v;
115 exitif i = n;
116 i := i + 1;
117 endfor;
118 result
119 endgroup
120 enddef;
121
122 % Splits a length at the math axis
123 def vcentre(expr size) =
124 size/2 + math_axis#, size/2 - math_axis#
125 enddef;
126
127 current_char := -1;
128
129 def beginsymbol(expr width, height, depth) =
130 current_char := current_char + 1;
131 beginchar(current_char, width, height, depth);
132 if not known ps_output:
133 proofrule((side_bearing, math_axis),(w - side_bearing, math_axis));
134 proofrule((side_bearing, h),(side_bearing, -d));
135 proofrule((w - side_bearing, h),(w - side_bearing, -d));
136 fi
137 enddef;
138
139 def beginoperator(expr size, ratio) =
140 beginsymbol(size + 2side_bearing#, vcentre(ratio * size));
141 pair centre;
142 centre := (w/2, (h-d)/2);
143 radius := w/2 - side_bearing - 1/2line_thickness;
144 enddef;
145
146 def beginbigop(expr xscale, yscale) =
147 beginsymbol(xscale * 3/2order_width# + 2side_bearing#, vcentre(yscale * bigop_height#));
148 pair centre;
149 centre := (w/2, (h-d)/2);
150 op_width := xscale * 3/2order_width;
151 op_height := yscale * bigop_height;
152 enddef;
153
154 def beginsquarebigop(expr xscale, yscale) =
155 beginsymbol(xscale * bigop_height# + 2side_bearing#, vcentre(yscale * bigop_height#));
156 pair centre;
157 centre := (w/2, (h-d)/2);
158 op_width := xscale * bigop_height;
159 op_height := yscale * bigop_height;
160 enddef;
161
162 def beginarrow(expr angle, scale, spread) =
163 arrow_len# := scale *
164 if angle mod 180 = 0: arrow_horiz_len#
165 elseif angle mod 180 = 90: arrow_vert_len#
166 else: arrow_diag_len#
167 fi;
168 arrow_len := scale *
169 if angle mod 180 = 0: arrow_horiz_len
170 elseif angle mod 180 = 90: arrow_vert_len
171 else: arrow_diag_len
172 fi;
173
174 beginsymbol(arrow_len# * abs(cosd(angle)) + (spread + line_thickness#) * abs(sind(angle)) + 2side_bearing#, vcentre(arrow_len# * abs(sind(angle)) + (spread + line_thickness#) * abs(cosd(angle))));
175 pair centre, head, head_ex, foot, foot_ex;
176
177 centre := (w/2, (h-d)/2);
178 head := centre + (arrow_len - line_thickness)/2 * dir angle;
179 head_ex := centre + arrow_len/2 * dir angle;
180 foot := centre - (arrow_len - line_thickness)/2 * dir angle;
181 foot_ex := centre - arrow_len/2 * dir angle;
182 enddef;
183
184 def beginorder(expr sign, width, spread) =
185 beginsymbol(width + 2side_bearing#, vcentre(spread + line_thickness#));
186 pair centre, left_ex, right_ex, left_point, right_point;
187 centre := (w/2, (h-d)/2);
188 left_ex := centre - sign * (w/2 - side_bearing) * right;
189 left_point := centre - sign * (w/2 - side_bearing - line_thickness/2) * right;
190 right_ex := centre + sign * (w/2 - side_bearing) * right;
191 right_point := centre + sign * (w/2 - side_bearing - line_thickness/2) * right;
192 enddef;
193
194 def beginturnstile(expr angle, scale) =
195 beginsymbol(abs(sind(angle) + scale * cosd(angle)) * turnstile_width# + 2side_bearing#, abs(min(scale, 1 + (scale - 1)/2) * sind(angle) + cosd(angle)) * cap_height#, abs(max(0, (scale - 1)/2) * sind(angle)) * cap_height#);
196 pair foot;
197
198 if angle mod 180 = 0:
199 len := scale * turnstile_width;
200 spread := cap_height - line_thickness;
201 else:
202 len := scale * cap_height;
203 spread := turnstile_width - line_thickness;;
204 fi
205 foot = (w/2, (h - d)/2) - (len - line_thickness)/2 * dir angle;
206 enddef;
207
208 def beginaccent(expr width, addheight) =
209 thick := accent_thickness;
210 beginsymbol(width, accent_height# + addheight, 0);
211 enddef;
212
213 % Strokes a pen path
214 vardef stroke text t =
215 forsuffixes e = l, r:
216 path_.e := t;
217 endfor
218 path_.r -- reverse path_.l -- cycle
219 enddef;
220
221 % Shapes
222
223 def circle(expr centre, radius) =
224 (centre + radius * right){up} ...
225 (centre + radius * dir 45){dir 135} ...
226 (centre + radius * up){left} ...
227 (centre + radius * dir 135){dir 225} ...
228 (centre + radius * left){down} ...
229 (centre + radius * dir 225){dir 315} ...
230 (centre + radius * down){right} ...
231 (centre + radius * dir 315){dir 45} ...
232 cycle
233 enddef;
234
235 def square(expr centre, radius, angle) =
236 (centre + sqrt(2) * radius * dir (angle + 45)) --
237 (centre + sqrt(2) * radius * dir (angle + 135)) --
238 (centre + sqrt(2) * radius * dir (angle + 225)) --
239 (centre + sqrt(2) * radius * dir (angle + 315)) --
240 cycle
241 enddef;
242
243 def triangle(expr centre, radius, angle) =
244 (centre + radius * dir angle) --
245 (centre + radius * dir (angle + 120)) --
246 (centre + radius * dir (angle + 240)) --
247 cycle
248 enddef;
249
250 def reg_poly_points(suffix $)(expr n, centre, radius, angle) =
251 for i = 0 upto n-1:
252 z$[i] = centre + radius * dir (angle + i/n * 360);
253 endfor;
254 enddef;
255
256 def dot(expr centre, radius) =
257 circle(centre, radius)
258 enddef;
259
260 % Draw macros
261
262 def draw_straight(expr orig, dest, thick, extend) =
263 begingroup;
264 pair p[].l, p[].r;
265
266 theta := angle (dest - orig);
267 if extend:
268 1/2[p1.l,p1.r] = orig - 1/2thick * dir theta;
269 1/2[p2.l,p2.r] = dest + 1/2thick * dir theta;
270 else:
271 1/2[p1.l,p1.r] = orig;
272 1/2[p2.l,p2.r] = dest;
273 fi
274 p1.l - p1.r = p2.l - p2.r = thick * dir (theta + 90);
275 fill stroke p1.e -- p2.e;
276 endgroup;
277 enddef;
278
279 def draw_line(expr orig, dest, extend) =
280 draw_straight(orig, dest, line_thickness, extend);
281 enddef;
282
283 def draw_line_linethick(expr orig, dest, lt, extend) =
284 draw_straight(orig, dest, lt, extend);
285 enddef;
286
287 def draw_line_cut_linethick(suffix $, $$)(expr lt)=
288 if (abs(angle(z$-z$$))<45) or (abs(angle(z$-z$$))>135) :
289 ppos_cut_linethick($)(lt,angle(z$-z$$),90);
290 ppos_cut_linethick($$)(lt,angle(z$-z$$),90);
291 else:
292 ppos_cut_linethick($)(lt,angle(z$-z$$),0);
293 ppos_cut_linethick($$)(lt,angle(z$-z$$),0);
294 fi
295 penstroke z$e .. z$$e;
296 penlabels($,$$);
297 enddef;
298
299 def draw_line_cut(suffix $, $$)=
300 draw_line_cut_linethick($,$$)(line_thickness);
301 enddef;
302
303 def draw_circle(expr centre, radius, thick) =
304 fill circle(centre, radius + 1/2thick);
305 unfill circle(centre, radius - 1/2thick);
306 enddef;
307
308 def filldraw_circle(expr centre, radius, thick) =
309 fill circle(centre, radius + 1/2thick);
310 enddef;
311
312 def draw_square(expr centre, radius, angle, thick) =
313 fill square(centre, radius + 1/2thick, angle);
314 unfill square(centre, radius - 1/2thick, angle);
315 enddef;
316
317 def filldraw_square(expr centre, radius, angle, thick) =
318 fill square(centre, radius + 1/2thick, angle);
319 enddef;
320
321 def draw_triangle(suffix $)(expr centre, radius, angle, thick) =
322 fill triangle(centre, radius + thick, angle);
323 unfill triangle(centre, radius - thick, angle);
324 enddef;
325
326 def filldraw_triangle(suffix $)(expr centre, radius, angle, thick) =
327 fill triangle(centre, radius + thick, angle);
328 enddef;
329
330 def draw_sim(suffix $)(expr lc, rc, spread, thick) =
331 theta := angle (length(rc - lc), 10spread);
332 signum := cosd (angle (rc - lc)) + sind (angle (lc - rc));
333
334 z0$.l = lc;
335 z4$.r = rc;
336 z2$ = 1/2[lc, rc];
337 z4$.r = rc;
338 1/2[z1$,z3$] = z2$;
339 z1$ = 1/4[lc, rc] + 1/6thick * dir (angle (rc - lc)) +
340 signum * spread * dir (angle (rc - lc) + 90);
341
342 penpos0$(thick, angle(rc - lc) - signum * (90 - theta));
343 penpos1$(thick, angle(rc - lc) - signum * 90);
344 penpos2$(thick, angle(rc - lc) - signum * (theta + 90 - 5));
345 penpos3$(thick, angle(rc - lc) - signum * 90);
346 penpos4$(thick, angle(rc - lc) - signum * (90 - theta));
347
348 fill stroke z0$.e{dir (angle(rc - lc) + signum * theta)} .. {dir angle(rc - lc)}z1$.e .. {dir (angle(rc - lc) - signum * (theta - 5))}z2$.e .. {dir angle(rc - lc)}z3$.e .. {dir (angle(rc - lc) + signum * theta)}z4$.e;
349
350 penlabels(0$,1$,3$,4$);
351 enddef;
352
353 def draw_bump(suffix $)(expr sign, lc, rc, rad, thick) =
354 z0$ = lc;
355 z1$ = rc;
356 z2$ = 1/2[lc, rc] + sign * rad * dir (angle (rc - lc) + 90);
357 z3$ = 1/2[lc, rc] - rad * dir (angle (rc - lc));
358 1/2[z3$,z4$] = 1/2[lc, rc];
359
360 penpos0$(thick, angle (rc - lc) + sign * 90);
361 penpos1$(thick, angle (rc - lc) + sign * 90);
362 penpos2$(thick, angle (rc - lc) + sign * 90);
363 penpos3$(thick, angle (rc - lc));
364 penpos4$(thick, angle (rc - lc));
365
366 z5$ = z3$.r;
367 z6$ = z4$.l;
368
369 penpos5$(thick, angle (rc - lc) + sign * 90);
370 penpos6$(thick, angle (rc - lc) + sign * 90);
371
372 path p$, q$;
373 numeric s$, t$;
374
375 p$ = z3$.l{dir (angle(rc - lc) + sign * 90)} .. {rc - lc}z2$.r;
376 q$ = z2$.r{rc - lc} .. {dir (angle(rc - lc) - sign * 90)}z4$.r;
377 s$ = xpart (p$ intersectiontimes (z0$.r -- z1$.r));
378 t$ = xpart (q$ intersectiontimes (z0$.r -- z1$.r));
379
380 fill z0$.r -- point s$ of p$ & subpath (s$,1) of p$ & subpath (0,t$) of q$ & point t$ of q$ -- z1$.r -- z1$.l -- z6$l. -- z6${dir (angle (rc - lc) + sign * 90)} .. z2$.l{lc - rc} .. {dir (angle (rc - lc) - sign * 90)}z5$ -- z5$.l -- z0$.l -- cycle;
381
382 penlabels(0$,1$,2$,3$,4$,5$,6$);
383 enddef;
384
385 def draw_less(suffix $)(expr lc, rc, spread, thick, closed, straight) =
386 put_less($)(lc, rc, spread, thick, closed, straight);
387 fill z0$.l -- z3$.l -- z4$.l -- z1$.l -- z1$.r -- z5$ -- z0$.r -- cycle;
388
389 if closed:
390 fill z0$.l -- z6$.l -- z7$.l -- z1$.l -- z7$.r -- z6$.r -- cycle;
391 fi;
392 enddef;
393
394 def put_less(suffix $)(expr lc, rc, spread, thick, closed, straight) =
395 theta := angle((length(rc - lc) - thick/2) * right + spread/2 * up);
396
397 z2$ = lc + 1/2thick * dir (angle (rc - lc));
398 1/2[z0$.r,z1$.r] = rc;
399 z0$ = z2$ + whatever * dir (angle (rc - lc) + theta);
400 z1$ = z2$ + whatever * dir (angle (rc - lc) - theta);
401
402 if straight:
403 penpos0$(thick/cosd(theta), angle(rc - lc) - 90);
404 penpos1$(thick/cosd(theta), angle(rc - lc) + 90);
405 else:
406 penpos0$(thick, angle(rc - lc) - 90 + theta);
407 penpos1$(thick, angle(rc - lc) + 90 - theta);
408 fi;
409 penpos3$(thick, angle(rc - lc) - 90 + theta);
410 penpos4$(thick, angle(rc - lc) + 90 - theta);
411
412 z3$.l = z0$.l + whatever * (z2$ - z0$);
413 z4$.l = z1$.l + whatever * (z2$ - z1$);
414 1/2[z3$.l,z4$.l] = lc;
415 z5$ = z0$.r + whatever * (z2$ - z0$);
416 z5$ = z1$.r + whatever * (z2$ - z1$);
417
418 if closed:
419 penpos6$(thick, angle(rc - lc));
420 penpos7$(thick, angle(rc - lc));
421 z6$.l = whatever[z0$.l,z3$.l];
422 z6$.r = whatever[z0$.r,z1$.r];
423 z7$.l = whatever[z1$.l,z4$.l];
424 z7$.r = whatever[z0$.r,z1$.r];
425 fi;
426
427 penlabels(0$,1$,3$,4$,5$,6$,7$);
428 enddef;
429
430 def draw_prec(suffix $)(expr lc, rc, spread, thick, closed) =
431 theta := 43;
432
433 z0$ - z1$ = spread * dir (angle (rc - lc) + 90);
434 1/2[z0$.r,z1$.l] = rc;
435 z2$ = lc;
436 z2$' = lc + 1/2thick * dir angle(rc - lc);
437
438 penpos0$(thick, angle(rc - lc) - theta);
439 penpos1$(thick, angle(rc - lc) + 180 + theta);
440 penpos2$(thick, angle(rc - lc) - 90);
441 penpos2$'(thick, angle(rc - lc) - 90);
442
443 fill stroke z2$.e -- z2$'.e{dir angle(rc - lc)} .. {dir (angle (rc - lc) + 90 - theta)}z0$.e;
444 fill stroke z2$.e -- z2$'.e{dir angle(rc - lc)} .. {dir (angle (rc - lc) - 90 + theta)}z1$.e;
445
446 if closed:
447 z3$ = point 1/2 of (z0${dir (angle (rc - lc) - 90 - theta + 10)}
448 .. {dir (angle (rc - lc) - 90 + theta - 10)}z1$);
449 penpos3$(thick, angle(rc - lc));
450
451 fill z0$.l .. z3$.l .. z1$.r -- z1$.l .. z3$.r .. z0$.r -- cycle;
452 fi;
453
454 penlabels(0$,1$,2$,3$);
455 enddef;
456
457 def draw_subset(suffix $)(expr lc, rc, spread, thick) =
458 1/2[z0$,z1$] = rc;
459 1/2[z2$,z3$] = (4spread / 9abs(rc - lc))[z4$, rc];
460 z0$ - z1$ = z2$ - z3$ = spread * dir (angle (rc - lc) + 90);
461 z4$ = lc + 1/2thick * dir (angle (rc - lc));
462
463 penpos0$(thick, angle(rc - lc) - 90);
464 penpos1$(thick, angle(rc - lc) + 90);
465 penpos2$(thick, angle(rc - lc) - 90);
466 penpos3$(thick, angle(rc - lc) + 90);
467 penpos4$(thick, angle(rc - lc));
468
469 fill stroke z0$.e -- z2$.e{lc - rc} .. z4$.e .. {rc - lc}z3$.e -- z1$.e;
470
471 penlabels(0$,1$,2$,3$,4$)
472 enddef;
473
474 def draw_smile(suffix $)(expr sign, lc, rc, spread, thick, round) =
475 z0$ = lc + sign * 1/2spread * dir (angle(rc - lc) + 90) +
476 whatever * (rc - lc);
477 z0$.l = lc + whatever * dir (angle(rc - lc) + 90);
478 z1$ = rc + sign * 1/2spread * dir (angle(rc - lc) + 90) +
479 whatever * (rc - lc);
480 z1$.l = rc + whatever * dir (angle(rc - lc) + 90);
481 z2$ = 1/2[lc,rc] - sign * 1/2spread * dir (angle(rc - lc) + 90);
482
483 if round:
484 theta := angle (length(lc - rc), 5spread);
485 else:
486 theta := angle (length(lc - rc), 2spread);
487 fi;
488
489 penpos0$(thick, angle(rc - lc) + sign * (90 - theta));
490 penpos1$(thick, angle(rc - lc) + sign * (90 + theta));
491
492 if round:
493 penpos2$(thick, angle(rc - lc) + sign * 90);
494
495 fill stroke z0$.e{dir (angle(rc - lc) - sign * theta)} ..
496 {rc - lc}z2$.e{rc - lc} .. {dir (angle(rc - lc) + sign * theta)}z1$.e;
497 else:
498 penpos2$(thick / cosd theta, angle(rc - lc) + sign * 90);
499
500 fill stroke z0$.e -- z2$.e -- z1$.e;
501 fi;
502
503 penlabels(0$, 1$, 2$);
504 enddef;
505
506 def stroke_through_angle(expr pos, spread, angle) =
507 begingroup;
508 stroke_len := 1/2spread / cosd (90 - angle);
509 z100 = pos + stroke_len * dir angle;
510 z101 = pos - stroke_len * dir angle;
511 draw_line_cut_linethick(100,101)(stroke_through_thickness);
512 endgroup;
513 enddef;
514
515 def stroke_through(expr pos, spread) =
516 stroke_through_angle(pos, spread, 75);
517 enddef;
518
519 def stroke_through_arrow(expr pos, alpha, spread)(text angles) =
520 begingroup;
521 stroke_dir := alpha + select(alpha / 45)(angles);
522 stroke_len := 1/2spread / sind (stroke_dir - alpha);
523
524 z102 = pos + stroke_len * dir stroke_dir;
525 z103 = pos - stroke_len * dir stroke_dir;
526 draw_line_cut_linethick(102,103)(stroke_through_thickness);
527 endgroup;
528 enddef;
529
530 def put_product_points(expr centre, width, height, sign, thick) =
531 thin := thick;
532
533 z1r - z0r = z3r - z2r = width * right;
534 z2r - z0r = sign * (height - thin) * up;
535 1/2[1/2[z0l,z1l], 1/2[z2r,z3r]] = centre;
536 z4 = z0 + min(5thin, 2/5width) * right;
537 z5 = z1 + min(5thin, 2/5width) * left;
538 z6 = 1/2[z0l,z4l];
539 z7 = 1/2[z1l,z5l];
540 x8 = 1/2[x0,x4];
541 x9 = 1/2[x1,x5];
542 y8 = y9 = y2l;
543
544 penpos0(thin, sign * 90);
545 penpos1(thin, sign * 90);
546 penpos2(thin, sign * 90);
547 penpos3(thin, sign * 90);
548 penpos4(thin, sign * 90);
549 penpos5(thin, sign * 90);
550 penpos6(thick, 0);
551 penpos7(thick, 0);
552 penpos8(thick, 0);
553 penpos9(thick, 0);
554
555 y10 = y11 = y2r - sign * 1/2[thin,thick];
556 x10 = x6r;
557 x11 = x7l;
558
559 penlabels(0,1,2,3,4,5,6,7,8,9,10,11);
560 enddef;
561
562
563 def draw_product(expr centre, width, height, sign, thick) =
564
565 put_product_points(centre, width, height, sign, thick)
566
567 fill z6r -- z8r -- z9l -- z7l -- z7r -- z9r -- z3l -- z3r -- z2r -- z2l -- z8l -- z6l --cycle;
568
569 enddef;
570
571 def draw_productintegral(expr centre, width, height, sign, thick) =
572
573 put_product_points(centre, width, height, sign, thick);
574
575 z8''=0.3[z2l,z3l];
576 z9''=0.7[z2l,z3l];
577
578 x6'=x6; y6'-y6=sign*(x6-x0+1/2thick);
579 penpos6'(sign*thick/sind(angle(z8''-z0)),0);
580 penpos8''(thick, 0);
581 penpos9''(thick, 0);
582
583 z0r = z0'r;
584 penpos0'(thick,sign*76);
585
586 z2 - z2' = sign* 1/35height * up;
587 penpos2'(thin,sign*90);
588 z8''l = z8'l;
589 penpos8'(thick,sign*90);
590
591 x7'=x7; y7'-y7=sign*(x1-x7+1/2thick);
592 penpos7'(sign*thick/sind(angle(z9''-z1)),0);
593
594 z7'' = z7' + whatever*(z1-z9'');
595 y7'' = y7;
596 penpos7''(sign*thick/sind(angle(z7'-z7'')),0);
597
598 fill z8''r -- z9''l{sign*down} .. {z1-z9''}z7'l -- z7''l -- z7''r -- z7'r{z9''-z1} .. {sign*up}z9''r -- z3l -- z3r -- z8'r{left} .. z2'r -- z2'l .. {right}z8''l{sign*down} ... {z0-z8''}z6'l{z0-z8''} ... {left}z0r -- z0'l{left} .. {right}z0l{right} ... {z8''-z0}z6'r{z8''-z0} ... {sign*up}cycle;
599
600 penlabels(0',2',6',7',7'',8',8'',9'');
601 enddef;
602
603 def draw_sum(suffix $)(expr centre, width, height, thick) =
604 thin := 4/5thick;
605
606 z1$l - z0$l = z3$l - z2$l = width * right;
607 z2$l - z0$l = height * up;
608 1/2[1/2[z0$l,z1$l], 1/2[z2$l,z3$l]] = centre = z4$;
609
610 penpos0$(thin, 90);
611 penpos1$(thick, 90);
612 penpos2$(thin, -90);
613 penpos3$(thick, -90);
614
615 penpos4$(thick/sind(angle(z4$-z0$)), 0);
616
617 y5$r = y0$l + thick; y6$r = y2$l - thick;
618 z5$r = whatever[z0$r,z4$l]; z6$r = whatever[z2$r,z4$l];
619
620 penpos5$(thick/sind(angle(z4$-z0$)), 180);
621 penpos6$(thick/sind(angle(z4$-z0$)), 180);
622
623 fill z1$r -- z1$l -- z0$l -- z0$r -- z4$l -- z2$r -- z2$l -- z3$l -- z3$r -- z6$l -- z4$r -- z5$l -- cycle;
624
625 penlabels(0$,1$,2$,3$,4$,5$,6$);
626 enddef;
627
628 def draw_integral(suffix $)(expr scale, centre, thick) =
629 penpos0$(thick, 0);
630 penpos1$(thick, 0);
631 penpos2$(6/7thick, -90);
632 penpos3$(thick, 0);
633 penpos4$(6/7thick, -90);
634
635 z0$ = 1/2[z1$,z3$] = 1/2[z2$,z4$];
636 z1$ - z3$ = whatever * dir 79;
637 z2$ - z4$ = whatever * dir 70;
638
639 x0$ = xpart centre;
640 y2$l = h;
641 y4$r = -d;
642 y1$ = 1/2[y0$,y2$];
643
644 penpos5$(1.05*6/7thick/sind 70,-105);
645 penpos6$(1.05*6/7thick/sind 70,-105);
646
647 y5$l = y2$l - 0.2thick;
648 x5$r = 5/4[x1$, x2$] + 0.2thick;
649 y6$r = y4$r + 0.2thick;
650 x6$r = 6/4[x3$, x4$] - 0.2thick;
651
652 ucorr := max (x2$r, x1$r + 1/4thick) - x2$r;
653 x2$ := x2$ + ucorr;
654 x2$l := x2$l + ucorr;
655 x2$r := x2$r + ucorr;
656 x5$ := x5$ + ucorr;
657 x5$r := x5$r + ucorr;
658 x5$l := x5$l + ucorr;
659
660 lcorr := min (x4$l, x1$l - 1/4thick) - x4$l;
661 x4$ := x4$ + lcorr;
662 x4$l := x4$l + lcorr;
663 x4$r := x4$r + lcorr;
664 x6$ := x6$ + lcorr;
665 x6$r := x6$r + lcorr;
666 x6$l := x6$l + lcorr;
667
668 fill z5$l .. {left}z2$l{left} .. {dir angle(z0$-z1$)}z1$l -- z3$l{dir angle(z0$-z1$)} ... z4$l{left} .. z6$l -- z6$r
669 .. {right}z4$r{right} .. {dir angle(z1$-z0$)}z3$r -- z1$r{dir angle(z1$-z0$)} ... z2$r{right} .. z5$r -- cycle;
670
671 penlabels(0$,1$,2$,3$,4$,5$,6$);
672 enddef;
673
674 def draw_arrowhead_left(expr pos, angle, spread, thick) =
675 begingroup;
676 pair p[], p[].l, p[].r;
677
678 p1 = pos;
679 p2 = pos + sqrt(2) * (spread + thick)/2 * dir (angle + 135);
680 1/2[p1.l, p1.r] = p1;
681 1/2[p2.l, p2.r] = p2;
682 p1.r - p1 = thick/(2 * sind 45) * dir angle;
683 p2.r - p2 = thick/(2 * sind 45) * dir angle;
684 p3.l = whatever[p2.l,p1.l];
685 p3.l = pos + 1/2thick * dir (angle - 90) + whatever * dir angle;
686 p3.r - p1.r = whatever * dir (angle - 90);
687 p3.r = pos + 1/2thick * dir (angle - 90) + whatever * dir angle;
688 fill p1.r -- p2.r -- p2.l -- p3.l -- p3.r -- cycle;
689 endgroup;
690 enddef;
691
692 def draw_arrowhead_right(expr pos, angle, spread, thick) =
693 begingroup;
694 pair p[], p[].l, p[].r;
695
696 p1 = pos;
697 p2 = pos + sqrt(2) * (spread + thick)/2 * dir (angle - 135);
698 1/2[p1.l, p1.r] = p1;
699 1/2[p2.l, p2.r] = p2;
700 p1.r - p1 = thick/(2 * sind 45) * dir angle;
701 p2.r - p2 = thick/(2 * sind 45) * dir angle;
702 p3.l = whatever[p2.l,p1.l];
703 p3.l = pos + 1/2thick * dir (angle + 90) + whatever * dir angle;
704 p3.r - p1.r = whatever * dir (angle + 90);
705 p3.r = pos + 1/2thick * dir (angle + 90) + whatever * dir angle;
706 fill p1.r -- p3.r -- p3.l -- p2.l -- p2.r -- cycle;
707 endgroup;
708 enddef;
709
710 def draw_arrowhead(expr pos, angle, spread, thick) =
711 begingroup;
712 pair p[], p[].l, p[].r;
713
714 p1 = pos;
715 p2 = pos + sqrt(2) * (spread+thick)/2 * dir (angle + 135);
716 p3 = pos + sqrt(2) * (spread+thick)/2 * dir (angle - 135);
717 1/2[p1.l, p1.r] = p1;
718 1/2[p2.l, p2.r] = p2;
719 1/2[p3.l, p3.r] = p3;
720 p1.r - p1 = thick/(2 * sind 45) * dir angle;
721 p2.r - p2 = thick/(2 * sind 45) * dir (angle);
722 p3.r - p3 = thick/(2 * sind 45) * dir (angle);
723
724 fill p1.r -- p2.r -- p2.l -- p1.l -- p3.l -- p3.r -- cycle;
725 endgroup;
726 enddef;
727
728 % intersect the arrowhead curve with a path
729 def arrowhead_intersection(expr pos, angle, spread, p) =
730 (p intersectionpoint
731 ((pos + sqrt(2) * spread/2 * dir (angle + 135)) --
732 pos -- (pos + sqrt(2) * spread/2 * dir (angle - 135)))
733 )
734 enddef;
735
736 def draw_bracket(expr sign, thick, draw_top, draw_mid, draw_bot, draw_double) =
737 penpos0(thick, 90 - sign * 90);
738 penpos1(thick, 90 - sign * 90);
739 penpos2(thick, 90);
740 penpos3(thick, 90);
741 penpos4(thick, 90);
742 penpos5(thick, 90);
743 penpos6(thick, 0);
744 penpos7(thick, 0);
745
746 x3 - x2 = x5 - x4 = sign * (w - 2side_bearing);
747 1/2[x2,x3] = w/2;
748
749 if draw_top:
750 y1 = h;
751 else:
752 y1 = h + 1/2line_thickness;
753 fi;
754
755 if draw_bot:
756 y0 = -d;
757 else:
758 y0 = -d - 1/2line_thickness;
759 fi;
760
761 x1 = x0;
762 z6 = 1/2[z2l,z3l] + sign * 1/2thick * right;
763 z7 = 1/2[z4r,z5r] + sign * 1/2thick * right;
764 y2l = y3l;
765 y4r = y5r;
766 z2l = z0l;
767 z4r = z1l;
768
769 if draw_mid:
770 fill stroke z0e -- z1e;
771 else:
772 if draw_bot: fill stroke z0e -- z0e + (w - 2side_bearing) * up; fi;
773 if draw_top: fill stroke z1e -- z1e + (w - 2side_bearing) * down; fi;
774 fi;
775 if draw_top: fill stroke z4e -- z5e; fi;
776 if draw_bot: fill stroke z2e -- z3e; fi;
777 if draw_double: fill stroke z6e -- z7e; fi;
778 enddef;
779
780 def draw_angle(suffix $)(expr shift, sign, thick) =
781 x0$ = x1$ = x2$ + sign * (w - 2side_bearing -2abs shift - thick);
782
783 top y1$ = h;
784 bot y0$ = -d;
785 1/2[y0$,y1$] = y2$;
786 1/2[x0$,x2$] = w/2 + shift;
787
788 theta := angle(z0$ - z2$);
789
790 penpos0$ (thick, 0);
791 penpos1$ (thick, 0);
792 penpos2$ (thick / abs(sind theta), 0);
793
794 fill stroke z0$e -- z2$e -- z1$e;
795
796 penlabels(0$, 1$, 2$);
797 enddef;
798
799 def draw_paren(expr sign, thick) =
800 penpos0(thick, 90 - sign * 90);
801 penpos1(thick, -90 + sign * 90);
802 penpos2(1.1thick, 90 - sign * 90);
803
804 if sign = 1:
805 x2l = side_bearing;
806 x1r = x0r = w - side_bearing;
807 else:
808 x1r = x0r = side_bearing;
809 x2l = w - side_bearing;
810 fi
811 y1.l = h;
812 y0.l = -d;
813 1/2[y0,y1] = y2;
814
815 fill stroke z0e .. z2e .. z1e;
816
817 penlabels(0,1,2);
818 enddef;
819
820 def draw_brace(expr centre, size, width, alpha, thick, top_size, mid_size, bot_size) =
821 penpos1(5/6thick, alpha + 90);
822 penpos2(thick, alpha);
823 penpos2'(thick,alpha);
824 penpos3(thick, alpha);
825 penpos3'(thick,alpha);
826 penpos4(11/12thick, alpha+90);
827 penpos5(thick, alpha+180);
828 penpos5'(thick, alpha+180);
829 penpos6(thick, alpha+180);
830 penpos6'(thick, alpha+180);
831 penpos7(5/6thick, alpha+90);
832
833 z1r - z7l = size * dir (alpha + 90);
834
835 centre - 1/2[z1,z7] = z4 - centre = width/2 * dir alpha;
836
837 z0 = centre;
838
839 z3 = z0 + (1/3width + 1/2thick) * dir (alpha + 90);
840 z5 = z0 - (1/3width + 1/2thick) * dir (alpha + 90);
841
842 z2 = z0 + (size/2 - 1/3width - thick) * dir (alpha + 90);
843 z6 = z0 - (size/2 - 1/3width - thick) * dir (alpha + 90);
844
845 z3' = z0 + (mid_size/2 + 1/2line_thickness) * dir (alpha + 90);
846 z5' = z0 - (mid_size/2 + 1/2line_thickness) * dir (alpha + 90);
847
848 z2' = z0 + (size/2 - top_size - 1/2line_thickness) * dir (alpha + 90);
849 z6' = z0 - (size/2 - bot_size - 1/2line_thickness) * dir (alpha + 90);
850
851 beta := 0;
852
853 if top_size > 0:
854 fill stroke z1e{dir alpha} .. {dir (alpha - 90)}z2e -- z2'e;
855 penlabels(1,2,2');
856 elseif bot_size > 0:
857 fill stroke z7e{dir alpha} .. {dir (alpha + 90)}z6e -- z6'e;
858 penlabels(6',6,7);
859 elseif mid_size > 0:
860 fill stroke z3'e -- z3e{dir (alpha - 90)} .. {dir alpha}z4e;
861 fill stroke z5'e -- z5e{dir (alpha + 90)} .. {dir alpha}z4e;
862 penlabels(3',3,4,5,5');
863 else:
864 fill stroke z1e{dir alpha} .. z2e{dir (alpha - 90)} -- z3e{dir (alpha - 90)} .. z4e{dir alpha};
865 fill stroke z7e{dir alpha} .. {dir (alpha + 90)}z6e -- z5e{dir (alpha + 90)} .. {dir alpha}z4e;
866 penlabels(1,2,3,4,5,6,7);
867 fi;
868 enddef;
869
870 def draw_root(expr thick) =
871 penpos0(rule_thickness, -90);
872 penpos0'(rule_thickness, -90);
873
874 y0l = h;
875 x0 = w;
876 z0' = z0 + 1/2line_thickness * right;
877 y1 = -d;
878 x1 = 4/9w;
879 x2r = 2/9w + 1/2thick;
880 y2r = 1/2[y0, y1];
881 z1' = z1 + thick * right;
882 y6 = h;
883 z6 = z0r + thick/sind(angle(z0r - z1')) * left + whatever * (z0r - z1');
884
885 penpos2(thick/abs(sind(angle(z1'-z2r))), 0);
886 penpos3(1/2thick, angle (z1 - z2l));
887
888 z1'' = z1' - thick/abs(sind(angle(z1' - z2r))) * right;
889
890 z3l = z2r + 3/2thick * dir (angle (z1 - z2l) - 90);
891 z4 = z6 + whatever * (z0r - z1') = z2r + whatever * (z2r - z1');
892 z5 = whatever[z2l, z1''] = z3r + whatever * dir (angle (z1'' - z2l) - 90);
893
894 fill z3r -- z5 -- z1'' -- z1' -- z0r -- z0'r -- z0'l -- z6 -- z4 -- z2r -- z3l -- cycle;
895
896 penlabels (0,0',1,1',1'',2,3,4,5,6);
897 enddef;
898
899 def draw_root_top(expr thick) =
900 y0 = h - 1/2rule_thickness;
901 x0 = w;
902 y1 = -d;
903 x1 = x2 = 4/9w + 1/2thick;
904 y2 = h - 1/2thick;
905
906 draw_straight(z1, z2, thick, true);
907 draw_straight((x1,y0), z0, rule_thickness, true);
908 enddef;
909
910 def draw_root_bot(expr thick) =
911 penpos0(thick, 0);
912 penpos0'(thick, -90);
913
914 y0 = h + 1/2thick;
915 x0l = x1;
916 y1 = -d;
917 x1 = 4/9w;
918 x2r = 2/9w + 1/2thick;
919 y2r = 1/2[y0, y1];
920 z1' = z1 + whatever * right;
921 x1' = x0r;
922
923 penpos2(thick/abs(sind(angle(z1'-z2r))), 0);
924 penpos3(1/2thick, angle (z1 - z2l));
925
926 z1'' = z1' - thick/abs(sind(angle(z1' - z2r))) * right;
927
928 z3l = z2r + 3/2thick * dir (angle (z1 - z2l) - 90);
929 z4 = z0l + whatever * up = z2r + whatever * (z2l - z1);
930 z5 = whatever[z2l, z1''] = z3r + whatever * dir (angle (z1'' - z2l) - 90);
931
932 fill z3r -- z5 -- z1 -- z1' -- z0r -- z0l -- z4 -- z2r -- z3l -- cycle;
933
934 penlabels (0,1,1',1'',2,3,4,5);
935 enddef;
936
937 % Weierstrass macros
938
939 def ellipse_set(suffix $,@,@@,$$) =
940 % given |z$,x@,z$$|, find |y@| and |z@@|
941 % such that the path |z${x@-x$,0}..z@{0,y@-y$}..{z$$-z@@}z@@|
942 % is consistent with an ellipse
943 % and such that the line |z@@--z$$| has a given |slope|
944 alpha_ := slope * (x@ - x$);
945 beta_ := y$$ - y$ - slope * (x$$ - x$);
946 gamma_ := alpha_ / beta_;
947 y@ - y$ = .5(beta_ - alpha_ * gamma_);
948 x@@ - x$ = -2gamma_ * (x@ - x$) / (1 + gamma_ * gamma_);
949 y@@ - y$$ = slope * (x@@ - x$$)
950 enddef;
951
952 vardef super_arc.r(suffix $,$$) =
953 % outside of super-ellipse
954
955 pair centre, corner;
956
957 if y$ = y$r:
958 centre = (x$$r, y$r);
959 corner = (x$r, y$$r);
960 else:
961 centre = (x$r, y$$r);
962 corner = (x$$r, y$r);
963 fi
964 z$.r{corner - z$.r} ... superness[centre,corner]{z$$.r - z$.r}
965 ... {z$$.r - corner}z$$.r
966 enddef;
967
968 vardef super_arc.l(suffix $,$$) =
969 % inside of super-ellipse
970
971 pair centre, corner;
972 if y$ = y$r:
973 centre = (x$$l, y$l);
974 corner = (x$l, y$$l);
975 else:
976 centre = (x$l, y$$l);
977 corner = (x$$l, y$l);
978 fi
979 z$l{corner - z$l} ... superness[centre,corner]{z$$l - z$l}
980 ... {z$$l - corner}z$$l
981 enddef;
982
983 vardef pulled_super_arc.r(suffix $,$$)(expr superpull) =
984 pair centre, corner;
985
986 if y$ = y$r:
987 centre = (x$$r, y$r);
988 corner = (x$r, y$$r);
989 else:
990 centre = (x$r, y$$r);
991 corner = (x$$r, y$r);
992 fi
993 z$r{corner - z$r} ... superness[centre,corner]{z$$r - z$r}
994 ... {z$$r - corner}z$$r
995 enddef;
996
997 vardef pulled_super_arc.l(suffix $,$$)(expr superpull) =
998 pair centre, corner, outer_point;
999
1000 if y$ = y$r:
1001 centre = (x$$l, y$l);
1002 corner = (x$l, y$$l);
1003 outer_point = superness[(x$$r, y$r), (x$r, y$$r)];
1004 else:
1005 centre = (x$l, y$$l);
1006 corner = (x$$l, y$l);
1007 outer_point = superness[(x$r, y$$r), (x$$r, y$r)];
1008 fi
1009 z$l{corner - z$l}
1010 ... superpull[superness[centre,corner], outer_point]{z$$l - z$l}
1011 ... {z$$l - corner}z$$l
1012 enddef;
1013
1014 vardef pulled_arc@#(suffix $,$$) =
1015 pulled_super_arc@#($,$$)(superpull)
1016 enddef;