1 % -%-Fundamental-%- -*-Metafont-*-
2 % parmesan-macros.mf -- macros for parmesan font
4 % source file of LilyPond's pretty-but-neat music font
6 % (c) 2001--2007 Juergen Reuter <reuter@ipd.uka.de>
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'
17 def find_tangent (expr p, curve, p_in, p_out) =
19 save mid, t, t_good, in, out;
27 exitif abs (out - mid) <= eps;
28 t := xpart (curve intersectiontimes (p -- mid));
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.
48 def find_tangent_shift (expr line, curve, p_in, p_out) =
58 exitif abs (out - mid) <= eps;
59 t := xpart ((curve shifted mid) intersectiontimes line);
73 % Get subpath specified by `dir_in' and `dir_out' of `curve'
74 % which is then shifted by `offset'. Assure that result has
75 % the same orientation as `curve'.
77 def get_subpath (expr curve, dir_in, dir_out, offset) =
81 t_in := directiontime dir_in of curve;
82 t_out := directiontime dir_out of curve;
85 t_out := t_out + length curve;
88 (subpath (t_in, t_out) of curve) shifted offset
94 % Get point specified by `dir_' of `curve' which is then
95 % shifted by `offset'.
97 def get_subpoint (expr curve, dir_, offset) =
98 (directionpoint dir_ of curve) shifted offset
103 % This is the same as `get_subpath', except that the time values
104 % used to construct the resulting subpath are rounded to integers.
106 def get_subpath_i (expr curve, dir_in, dir_out, offset) =
110 t_in := directiontime dir_in of curve;
111 t_out := directiontime dir_out of curve;
114 t_out := t_out + length curve;
117 (subpath (floor (t_in + 0.5), floor (t_out + 0.5)) of curve)
124 % Find envelope cusp created by `object' moved along `curve', using
125 % step value `s' for initial intermediate points. `s' must be small
126 % enough so that this macro finds at least one point on the envelope
127 % between the `entrance' and `exit' points of the cusp which has
128 % a significantly different direction vector.
130 % This function returns a time value on `curve'; if there is no
131 % cusp, it returns -1.
133 def find_envelope_cusp (expr object, curve, s) =
135 save mid, p, t, t_good, delta, start, stop, do_exit;
139 p0 := (directionpoint (direction 0 of curve) of object)
140 shifted (point 0 of curve);
141 p1 := (directionpoint (direction s of curve) of object)
142 shifted (point s of curve);
148 exitif t >= length curve;
150 p2 := (directionpoint (direction t of curve) of object)
151 shifted (point t of curve);
153 delta := angle (p2 - p1) - angle (p1 - p0);
155 delta := delta - 360;
158 % we check for a direction change by more than
160 if abs (delta) >= 45:
170 % having `exitif' within an if-clause doesn't work
174 if t >= length curve:
177 % the wanted point lies between `t - s' and `t'
183 mid := 0.5 [start, stop];
184 exitif abs (stop - mid) <= eps;
186 p0 := (directionpoint (direction start of curve)
187 of object) shifted (point start of curve);
188 p1 := (directionpoint (direction mid of curve)
189 of object) shifted (point mid of curve);
190 p2 := (directionpoint (direction stop of curve)
191 of object) shifted (point stop of curve);
193 exitif (length (p1 - p0) = 0)
194 or (length (p2 - p1) = 0);
196 delta := angle (p2 - p1) - angle (p1 - p0);
198 delta := delta - 360;
201 if abs (delta) >= 45: