X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Finterval.tcc;h=5ff1e416657d57bc781ca944a75471074000776d;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=efb7644133f4203dd8a9d5e4fca81868587ffb7d;hpb=1a66290a98e7de8d6d41485b5b71a9f7e1fe35c7;p=lilypond.git diff --git a/flower/include/interval.tcc b/flower/include/interval.tcc index efb7644133..5ff1e41665 100644 --- a/flower/include/interval.tcc +++ b/flower/include/interval.tcc @@ -3,125 +3,127 @@ source file of the Flower Library - (c) 1996,1997 Han-Wen Nienhuys + (c) 1996--2008 Han-Wen Nienhuys */ - #ifndef INTERVAL_TCC #define INTERVAL_TCC -#include -#include +#include + #include "interval.hh" -#include "string.hh" +#include "std-string.hh" +// MacOS 10.3 problems: +// #include +using namespace std; 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.at (LEFT) == b.at (LEFT) && a.at (RIGHT) == b.at (RIGHT)) + return 0; + + if (a.at (LEFT) <= b.at (LEFT) && a.at (RIGHT) >= b.at (RIGHT)) + return 1; - if (a.left >= b.left && a.right <= b.right) - return -1; + if (a.at (LEFT) >= b.at (LEFT) && a.at (RIGHT) <= b.at (RIGHT)) + return -1; - return -2; + return -2; } template -bool -Interval_t::contains_b (Interval_t const& a)const +bool +Interval_t::superset (Interval_t const &a) const { - int c_i= _Interval__compare (*this, a); - if (c_i == -2) - return false; - return c_i >= 0; + 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 (Interval_t const &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; } template void -Interval_t::set_empty() +Interval_t::set_empty () { - left = (T) infinity(); - right = (T) -infinity(); + at (LEFT) = (T) infinity (); + at (RIGHT) = (T) -infinity (); } template -T -Interval_t::length() const { - assert (right >= left); - return right-left; +void +Interval_t::set_full () +{ + at (LEFT) = (T) -infinity (); + at (RIGHT) = (T) infinity (); } template -void -Interval_t::unite (Interval_t h) +T +Interval_t::length () const { - if (h.leftright) - right = h.right; + if (at (RIGHT) <= at (LEFT)) + return 0; + else + return at (RIGHT) - at (LEFT); } -/** - smallest Interval which includes *this and #h# - */ +template +T +Interval_t::delta () const +{ + return at (RIGHT) - at (LEFT); +} +/* smallest Interval which includes *this and #h# */ template void -Interval_t::intersect (Interval_t h) +Interval_t::unite (Interval_t h) { -#if defined (__GNUG__) && ! defined (__STRICT_ANSI__) - left = h.left >? left; - right = h.right -Interval_t -intersect (Interval_t x, Interval_t const &y) +void +Interval_t::intersect (Interval_t h) { - x.intersect (y); - return x; + at (LEFT) = max (h.at (LEFT), at (LEFT)); + at (RIGHT) = min (h.at (RIGHT), at (RIGHT)); } template -String -Interval_t::str() const +string +Interval_t::to_string () const { - if (empty_b()) - return "[empty]"; - String s ("["); - - return s + String (left) + String ("," ) + String (right ) + String ("]" ); + if (is_empty ()) + return "[empty]"; + string s ("["); + + return (s + T_to_string (at (LEFT)) + string (",") + + T_to_string (at (RIGHT)) + string ("]")); } template bool -Interval_t::elt_b (T r) +Interval_t::contains (T r) const { - return r >= left && r <= right; + return r >= at (LEFT) && r <= at (RIGHT); } - -#define INTERVAL__INSTANTIATE(T) struct Interval_t;\ - template int Interval__compare(const Interval_t&,Interval_t const&) +#define INTERVAL__INSTANTIATE(T) struct Interval_t; \ + template int Interval__compare (const Interval_t &, Interval_t const &) #endif // INTERVAL_TCC