X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Finterval.tcc;h=7e773e2579c5829a758877f5532656067a998a6b;hb=ce521e79fd7669b45c8c1132e4b5693a03b5d90a;hp=32eec44580228b76f322b47d79a026c031a548d3;hpb=3f374e66968308461daa390a7aeed0b013bfe33d;p=lilypond.git diff --git a/flower/include/interval.tcc b/flower/include/interval.tcc index 32eec44580..7e773e2579 100644 --- a/flower/include/interval.tcc +++ b/flower/include/interval.tcc @@ -1,3 +1,15 @@ +/* + interval.tcc -- implement Interval_t + + source file of the Flower Library + + (c) 1996, 1997--2000 Han-Wen Nienhuys +*/ + + +#ifndef INTERVAL_TCC +#define INTERVAL_TCC + #include #include #include "interval.hh" @@ -6,101 +18,118 @@ template int -_Interval__compare(const Interval_t&a,Interval_t const&b) +_Interval__compare (const Interval_t&a,Interval_t const&b) { - if (a.left == b.left && a.right == b.right) - return 0; - - if (a.left <= b.left && a.right >= b.right) - return 1; + if (a.elem (LEFT) == b.elem (LEFT) && a.elem (RIGHT) == b.elem (RIGHT)) + return 0; + + if (a.elem (LEFT) <= b.elem (LEFT) && a.elem (RIGHT) >= b.elem (RIGHT)) + return 1; - if (a.left >= b.left && a.right <= b.right) - return -1; + if (a.elem (LEFT) >= b.elem (LEFT) && a.elem (RIGHT) <= b.elem (RIGHT)) + return -1; - return -2; + return -2; } +template +bool +Interval_t::contains_b (Interval_t const& a) const +{ + int c_i= _Interval__compare (*this, a); + if (c_i == -2) + return false; + return c_i >= 0; +} template int -Interval__compare(const Interval_t&a,Interval_t const&b) +Interval__compare (const Interval_t&a,Interval_t const&b) { - int i = _Interval__compare(a,b); - if (i < -1) - assert(false); - return i; + int i = _Interval__compare (a,b); + if (i < -1) + assert (false); + return i; } -#ifdef AIX -const Real INFTY = 1e8; // ARGh. AIX sucks -#else -const Real INFTY = HUGE_VAL; -#endif - template void -Interval_t::set_empty() +Interval_t::set_empty () { - left = INFTY; - right = -INFTY; + elem (LEFT) = (T) infinity (); + elem (RIGHT) = (T) -infinity (); } template T -Interval_t::length() const { - assert(right >= left); - return right-left; +Interval_t::length () const +{ + if (elem (RIGHT) <= elem (LEFT)) + return 0; + else + return elem (RIGHT)-elem (LEFT); } +/** + smallest Interval which includes *this and #h# + */ template void -Interval_t::unite(Interval_t h) +Interval_t::unite (Interval_t h) { - if (h.leftright) - right = h.right; + elem (LEFT) = h.elem (LEFT) ?elem (RIGHT); + +#if 0 + if (h.elem (LEFT)elem (RIGHT)) + elem (RIGHT) = h.elem (RIGHT); +#endif } -/** - smallest Interval which includes *this and #h# - */ template void -Interval_t::intersect(Interval_t h) +Interval_t::intersect (Interval_t h) { #if defined (__GNUG__) && ! defined (__STRICT_ANSI__) - left = h.left >? left; - right = h.right ? elem (LEFT); + elem (RIGHT) = h.elem (RIGHT) Interval_t -intersect(Interval_t x, Interval_t const &y) +intersect (Interval_t x, Interval_t const &y) { - x.intersect(y); - return x; + x.intersect (y); + return x; } template String -Interval_t::str() const +Interval_t::str () const { - if (empty_b()) - return "[empty]"; - String s("["); + if (empty_b ()) + return "[empty]"; + String s ("["); - return s + left + "," + right +"]"; + return s + T_to_str (elem (LEFT)) + String ("," ) + T_to_str (elem (RIGHT) ) + String ("]" ); } template bool -Interval_t::elt_b(T r) +Interval_t::elem_b (T r) { - return r >= left && r <= right; + return r >= elem (LEFT) && r <= elem (RIGHT); } + + +#define INTERVAL__INSTANTIATE(T) struct Interval_t;\ +template int Interval__compare (const Interval_t&,Interval_t const&) + +#endif // INTERVAL_TCC