1 % Feta (not the Font-En-Tja) music font -- macros for parmesan font
2 % This file is part of LilyPond, the GNU music typesetter.
4 % Copyright (C) 2001--2012 Juergen Reuter <reuter@ipd.uka.de>
7 % The LilyPond font is free software: you can redistribute it and/or modify
8 % it under the terms of the GNU General Public License as published by
9 % the Free Software Foundation, either version 3 of the License, or
10 % (at your option) any later version, or under the SIL Open Font License.
12 % LilyPond is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
17 % You should have received a copy of the GNU General Public License
18 % along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 % Find point on `curve' which gives the tangent between point `p'
23 % and `curve'. To guide the search, two auxiliary points must be
24 % specified, `p_in' and `p_out'. The line between `p' and `p_in'
25 % must intersect `curve', while the line between `p' and `p_out'
28 def find_tangent (expr p, curve, p_in, p_out) =
30 save mid, t, t_good, in, out;
38 exitif abs (out - mid) <= eps;
39 t := xpart (curve intersectiontimes (p -- mid));
54 % Shift `curve' along the line given by the auxiliary points `p_in'
55 % and `p_out' until `line' is a tangent, and return the shift.
56 % If `curve' is shifted to position `p_in', it must intersect
57 % `line', while shifted to `p_out' it must not.
59 def find_tangent_shift (expr line, curve, p_in, p_out) =
69 exitif abs (out - mid) <= eps;
70 t := xpart ((curve shifted mid) intersectiontimes line);
84 % Get subpath specified by `dir_in' and `dir_out' of `curve'
85 % which is then shifted by `offset'. Assure that result has
86 % the same orientation as `curve'.
88 def get_subpath (expr curve, dir_in, dir_out, offset) =
92 t_in := directiontime dir_in of curve;
93 t_out := directiontime dir_out of curve;
96 t_out := t_out + length curve;
99 (subpath (t_in, t_out) of curve) shifted offset
105 % Get point specified by `dir_' of `curve' which is then
106 % shifted by `offset'.
108 def get_subpoint (expr curve, dir_, offset) =
109 (directionpoint dir_ of curve) shifted offset
114 % This is the same as `get_subpath', except that the time values
115 % used to construct the resulting subpath are rounded to integers.
117 def get_subpath_i (expr curve, dir_in, dir_out, offset) =
121 t_in := directiontime dir_in of curve;
122 t_out := directiontime dir_out of curve;
125 t_out := t_out + length curve;
128 (subpath (floor (t_in + 0.5), floor (t_out + 0.5)) of curve)
135 % Find envelope cusp created by `object' moved along `curve', using
136 % step value `s' for initial intermediate points. `s' must be small
137 % enough so that this macro finds at least one point on the envelope
138 % between the `entrance' and `exit' points of the cusp which has
139 % a significantly different direction vector.
141 % This function returns a time value on `curve'; if there is no
142 % cusp, it returns -1.
144 def find_envelope_cusp (expr object, curve, s) =
146 save mid, p, t, t_good, delta, start, stop, do_exit;
150 p0 := (directionpoint (direction 0 of curve) of object)
151 shifted (point 0 of curve);
152 p1 := (directionpoint (direction s of curve) of object)
153 shifted (point s of curve);
159 exitif t >= length curve;
161 p2 := (directionpoint (direction t of curve) of object)
162 shifted (point t of curve);
164 delta := angle (p2 - p1) - angle (p1 - p0);
166 delta := delta - 360;
169 % we check for a direction change by more than
171 if abs (delta) >= 45:
181 % having `exitif' within an if-clause doesn't work
185 if t >= length curve:
188 % the wanted point lies between `t - s' and `t'
194 mid := 0.5 [start, stop];
195 exitif abs (stop - mid) <= eps;
197 p0 := (directionpoint (direction start of curve)
198 of object) shifted (point start of curve);
199 p1 := (directionpoint (direction mid of curve)
200 of object) shifted (point mid of curve);
201 p2 := (directionpoint (direction stop of curve)
202 of object) shifted (point stop of curve);
204 exitif (length (p1 - p0) = 0)
205 or (length (p2 - p1) = 0);
207 delta := angle (p2 - p1) - angle (p1 - p0);
209 delta := delta - 360;
212 if abs (delta) >= 45: