2 misc.cc -- implement various stuff
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
32 return log (x) /log (2.0);
39 make more generic / templatise
42 get_lower_bound (Array<Real> const& positions, Real x)
46 for (int i = 1; i < positions.size (); i++)
49 return positions.size () - 1;
53 get_bounds_slice (Array<Real> const& positions, Real x)
55 int l = get_lower_bound (positions, x);
56 int u = positions.size () - 1 <? l + 1;
63 get_bounds_iv (Array<Real> const& positions, Real x)
65 Slice slice = get_bounds_slice (positions, x);
66 return Interval (positions[slice[SMALLER]], positions[slice[BIGGER]]);
71 quantise_iv (Array<Real> const& positions, Real period, Real x)
76 * positions are sorted,
77 * positions are nonnegative
78 * period starts at zero
81 int n = (int)(x / period);
82 Real frac = (x / period - n) * period;
89 Slice slice = get_bounds_slice (positions, frac);
90 Interval iv(positions[slice[SMALLER]], positions[slice[BIGGER]]);
92 if (slice[SMALLER] == slice[BIGGER])
94 if (slice[SMALLER] == 0)
95 iv[SMALLER] = - period + positions.top ();
97 iv[BIGGER] = period + positions[0];