Debian Codegraph @

texmf-dist/metapost/minim-mp/minim.mp

raw
1
2 if known minim.mp:
3 expandafter endinput fi
4 minim.mp := 1.6;
5
6 % This file only contains code that is not specific to the minim metapost
7 % processor. See minim-mp.mp for the wireup of minim-mp’s extensions.
8
9 message "Loading general minim extension macros";
10
11 % redefine some constants to work with the new numerical engines
12 numeric mm, cm, pt, pc, dd, cc;
13 pc = 12 pt; cc = 12 dd; cm = 10 mm;
14 803 pt = 800; 127 mm = 360; 1157 dd = 1238 pt;
15 eps := 1/2048; infinity := 64*64-epsilon;
16
17 % constants
18 pi := 355/113;
19
20 % shorthands
21 primarydef p xshifted x = p shifted (x,0) enddef;
22 primarydef p yshifted y = p shifted (0,y) enddef;
23
24 % reverse paths to allow „p & vflip p”
25 def hflip primary p = if path p: reverse fi p xscaled -1 enddef;
26 def vflip primary p = if path p: reverse fi p yscaled -1 enddef;
27
28 % missing definitions
29 path fullsquare, unitcircle ;
30 fullsquare := unitsquare shifted - center unitsquare ;
31 unitcircle := fullcircle shifted urcorner fullcircle ;
32
33 % complement counterclockwise
34 vardef clockwise primary c =
35 if turningnumber c > 0: reverse fi c enddef;
36
37 % clipping
38 vardef clipout text t =
39 clip currentpicture to bbox currentpicture
40 for c = t: -- c -- cycle endfor -- cycle enddef;
41 vardef clipto text t =
42 clip currentpicture to
43 for c = t: c -- cycle -- endfor cycle enddef;
44 vardef getbounds primary p = % without bboxmargin
45 llcorner p -- lrcorner p -- urcorner p -- ulcorner p -- cycle
46 enddef;
47
48 % cmyk colours
49 cmykcolor cyan, magenta, yellow, key;
50 cyan = (1,0,0,0);
51 magenta = (0,1,0,0);
52 yellow = (0,0,1,0);
53 key = (0,0,0,1);
54
55 vardef rgb_to_gray expr c =
56 0.2126*redpart c + 0.7152*greenpart c + 0.0722*bluepart c
57 enddef;
58
59 % shorthands
60 def save_pen text t = save t; pen t; enddef;
61 def save_pair text t = save t; pair t; enddef;
62 def save_path text t = save t; path t; enddef;
63 def save_color text t = save t; color t; enddef;
64 def save_cmykcolor text t = save t; cmykcolor t; enddef;
65 def save_transform text t = save t; transform t; enddef;
66 def save_picture text t = save t; picture t; enddef;
67 def save_boolean text t = save t; boolean t; enddef;
68 def save_string text t = save t; string t; enddef;
69
70 % missing trigonometric functions
71 vardef tand primary x = sind(x)/cosd(x) enddef;
72 vardef arcsind primary x = angle(1+-+x, x) enddef;
73 vardef arccosd primary x = angle(x, 1+-+x) enddef;
74 vardef arctand primary x = angle(1, x) enddef;
75
76 % segments of the circle (counterclockwise)
77 vardef arc (expr thetafrom, thetalen) =
78 save n, d, l, theta; save_path a; save_pair p, c;
79 n = ceiling(thetalen / 45); % number of segments (45° is max segment length)
80 d = thetalen / n; % angle of each segment
81 l = 4/3 * tand(d/4); % length of control points
82 theta := thetafrom;
83 p := (cosd theta, sind theta);
84 c := l * (-sind theta, cosd theta);
85 a := p for _ = 1 upto n:
86 .. controls (p + c)
87 hide(theta := theta + d;
88 p := (cosd theta, sind theta);
89 c := l * (-sind theta, cosd theta);)
90 and (p - c) .. p
91 endfor; a enddef;
92
93 % some linear algebra
94 primarydef v extprod w = begingroup
95 xpart v * ypart w - ypart v * xpart w
96 endgroup enddef;
97
98 vardef collinear(expr p,q,r) =
99 (p <> q) and (q <> r) and (p <> r)
100 and (eps > abs( (p-q) extprod (q-r) ))
101 enddef;
102
103 % type helpers
104 def typeof (expr v) =
105 if numeric v: numeric
106 elseif pair v: pair
107 elseif color v: color
108 elseif cmykcolor v: cmykcolor
109 elseif boolean v: boolean
110 elseif path v: path
111 elseif picture v: picture
112 elseif transform v: transform
113 elseif string v: string
114 elseif pen v: pen
115 fi enddef;
116
117 vardef empty suffix s = save_boolean b;
118 b := string _EMPTY_ s; b enddef;
119 string _EMPTY_;
120