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);
37 itemlist_width (const Array
<Item
*> &its
)
42 for (int j
=0; j
< its
.size(); j
++)
44 iv
.unite (its
[j
]->extent (X_AXIS
));
56 make more generic / templatise
59 get_lower_bound (Array
<Real
> const& positions
, Real x
)
63 for (int i
= 1; i
< positions
.size (); i
++)
66 return positions
.size () - 1;
70 get_bounds_slice (Array
<Real
> const& positions
, Real x
)
72 int l
= get_lower_bound (positions
, x
);
73 int u
= positions
.size () - 1 <? l
+ 1;
80 get_bounds_iv (Array
<Real
> const& positions
, Real x
)
82 Slice slice
= get_bounds_slice (positions
, x
);
83 return Interval (positions
[slice
[SMALLER
]], positions
[slice
[BIGGER
]]);
88 quantise_iv (Array
<Real
> const& positions
, Real period
, Real x
)
93 * positions are sorted,
94 * positions are nonnegative
95 * period starts at zero
98 int n
= (int)(x
/ period
);
99 Real frac
= (x
/ period
- n
) * period
;
106 Slice slice
= get_bounds_slice (positions
, frac
);
107 Interval
iv(positions
[slice
[SMALLER
]], positions
[slice
[BIGGER
]]);
109 if (slice
[SMALLER
] == slice
[BIGGER
])
111 if (slice
[SMALLER
] == 0)
112 iv
[SMALLER
] = - period
+ positions
.top ();
114 iv
[BIGGER
] = period
+ positions
[0];