X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Finterval.tcc;h=5ff1e416657d57bc781ca944a75471074000776d;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=45d754abd3b50bd862f65516653c279ff58e349b;hpb=068b30ff4bfe81e6dd41ac3736bbc52980e79a1f;p=lilypond.git diff --git a/flower/include/interval.tcc b/flower/include/interval.tcc index 45d754abd3..5ff1e41665 100644 --- a/flower/include/interval.tcc +++ b/flower/include/interval.tcc @@ -3,47 +3,42 @@ source file of the Flower Library - (c) 1996, 1997--1998 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 "flower-debug.hh" +#include "std-string.hh" -template -void -Interval_t::print () const -{ - fdebug << str (); -} +// 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) + if (a.at (LEFT) == b.at (LEFT) && a.at (RIGHT) == b.at (RIGHT)) return 0; - - if (a.left <= b.left && a.right >= b.right) + + if (a.at (LEFT) <= b.at (LEFT) && a.at (RIGHT) >= b.at (RIGHT)) return 1; - if (a.left >= b.left && a.right <= b.right) + if (a.at (LEFT) >= b.at (LEFT) && a.at (RIGHT) <= b.at (RIGHT)) return -1; 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); + int c_i = _Interval__compare (*this, a); if (c_i == -2) return false; return c_i >= 0; @@ -51,9 +46,9 @@ Interval_t::contains_b (Interval_t const& a) const 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); + int i = _Interval__compare (a, b); if (i < -1) assert (false); return i; @@ -61,77 +56,74 @@ Interval__compare (const Interval_t&a,Interval_t const&b) 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 +void +Interval_t::set_full () +{ + at (LEFT) = (T) -infinity (); + at (RIGHT) = (T) infinity (); } template T -Interval_t::length() const +Interval_t::length () const { - if (right < left) + if (at (RIGHT) <= at (LEFT)) return 0; - else - return right-left; + else + return at (RIGHT) - at (LEFT); } template -void -Interval_t::unite (Interval_t h) +T +Interval_t::delta () const { - if (h.leftright) - right = h.right; + return at (RIGHT) - at (LEFT); } -/** - smallest Interval which includes *this and #h# - */ - +/* 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()) + if (is_empty ()) return "[empty]"; - String s ("["); - - return s + T_to_str (left) + String ("," ) + T_to_str (right ) + String ("]" ); + string s ("["); + + return (s + T_to_string (at (LEFT)) + string (",") + + T_to_string (at (RIGHT)) + string ("]")); } template bool -Interval_t::elem_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