]> git.donarmstrong.com Git - lilypond.git/blob - mf/parmesan-macros.mf
Merge branch 'master' of ssh+git://git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / mf / parmesan-macros.mf
1 % -%-Fundamental-%- -*-Metafont-*-
2 % parmesan-macros.mf -- macros for parmesan font
3
4 % source file of LilyPond's pretty-but-neat music font
5
6 % (c) 2001--2006 Juergen Reuter <reuter@ipd.uka.de>
7
8
9
10 %
11 % Find point on `curve' which gives the tangent between point `p'
12 % and `curve'.  To guide the search, two auxiliary points must be
13 % specified, `p_in' and `p_out'.  The line between `p' and `p_in'
14 % must intersect `curve', while the line between `p' and `p_out'
15 % must not.
16 %
17 def find_tangent (expr p, curve, p_in, p_out) =
18         begingroup;
19         save mid, t, t_good, in, out;
20         pair mid, in, out;
21
22         in := p_in;
23         out := p_out;
24
25         forever:
26                 mid := 0.5 [in, out];
27                 exitif abs (out - mid) <= eps;
28                 t := xpart (curve intersectiontimes (p -- mid));
29                 if (t > 0):
30                         in := mid;
31                         t_good := t;
32                 else:
33                         out := mid;
34                 fi;
35         endfor;
36
37         point t_good of curve
38         endgroup
39 enddef;
40
41
42 %
43 % Shift `curve' along the line given by the auxiliary points `p_in'
44 % and `p_out' until `line' is a tangent, and return the shift.
45 % If `curve' is shifted to position `p_in', it must intersect
46 % `line', while shifted to `p_out' it must not.
47 %
48 def find_tangent_shift (expr line, curve, p_in, p_out) =
49         begingroup;
50         save mid, t, t_good, in, out;
51         pair mid, in, out;
52
53         in := p_in;
54         out := p_out;
55
56         forever:
57                 mid := 0.5 [in, out];
58                 exitif abs (out - mid) <= eps;
59                 t := xpart ((curve shifted mid) intersectiontimes line);
60                 if (t > 0):
61                         in := mid;
62                         t_good := t;
63                 else:
64                         out := mid;
65                 fi;
66         endfor;
67
68         mid
69         endgroup
70 enddef;
71
72
73 %
74 % Get subpath specified by `dir_in' and `dir_out' of `curve'
75 % which is then shifted by `offset'.  Assure that result has
76 % the same orientation as `curve'.
77 %
78 def get_subpath (expr curve, dir_in, dir_out, offset) =
79         begingroup;
80         save t_in, t_out;
81
82         t_in := directiontime dir_in of curve;
83         t_out := directiontime dir_out of curve;
84
85         if t_in > t_out:
86                 t_out := t_out + length curve;
87         fi;
88
89         (subpath (t_in, t_out) of curve) shifted offset
90         endgroup
91 enddef;
92
93
94 %
95 % This is the same as `get_subpath', except that the time values
96 % used to construct the resulting subpath are rounded to integers.
97 %
98 def get_subpath_i (expr curve, dir_in, dir_out, offset) =
99         begingroup;
100         save t_in, t_out;
101
102         t_in := directiontime dir_in of curve;
103         t_out := directiontime dir_out of curve;
104
105         if t_in > t_out:
106                 t_out := t_out + length curve;
107         fi;
108
109         (subpath (floor (t_in + 0.5), floor (t_out + 0.5)) of curve)
110           shifted offset
111         endgroup
112 enddef;
113
114 % EOF