2 interval.tcc -- implement Interval_t
4 source file of the Flower Library
6 (c) 1996, 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
15 #include "interval.hh"
17 #include "flower-debug.hh"
21 Interval_t<T>::print () const
28 _Interval__compare (const Interval_t<T>&a,Interval_t<T> const&b)
30 if (a.elem (LEFT) == b.elem (LEFT) && a.elem (RIGHT) == b.elem (RIGHT))
33 if (a.elem (LEFT) <= b.elem (LEFT) && a.elem (RIGHT) >= b.elem (RIGHT))
36 if (a.elem (LEFT) >= b.elem (LEFT) && a.elem (RIGHT) <= b.elem (RIGHT))
44 Interval_t<T>::contains_b (Interval_t<T> const& a) const
46 int c_i= _Interval__compare (*this, a);
54 Interval__compare (const Interval_t<T>&a,Interval_t<T> const&b)
56 int i = _Interval__compare (a,b);
64 Interval_t<T>::set_empty()
66 elem (LEFT) = (T) infinity();
67 elem (RIGHT) = (T) -infinity();
72 Interval_t<T>::length() const
74 if (elem (RIGHT) < elem (LEFT))
77 return elem (RIGHT)-elem (LEFT);
81 smallest Interval which includes *this and #h#
85 Interval_t<T>::unite (Interval_t<T> h)
87 elem (LEFT) = h.elem (LEFT) <? elem (LEFT);
88 elem (RIGHT) = h.elem (RIGHT) >?elem (RIGHT);
91 if (h.elem (LEFT)<elem (LEFT))
92 elem (LEFT) = h.elem (LEFT);
93 if (h.elem (RIGHT)>elem (RIGHT))
94 elem (RIGHT) = h.elem (RIGHT);
101 Interval_t<T>::intersect (Interval_t<T> h)
103 #if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
104 elem (LEFT) = h.elem (LEFT) >? elem (LEFT);
105 elem (RIGHT) = h.elem (RIGHT) <?elem (RIGHT);
107 elem (LEFT) = max (h.elem (LEFT), elem (LEFT));
108 elem (RIGHT) = min (h.elem (RIGHT), elem (RIGHT));
114 intersect (Interval_t<T> x, Interval_t<T> const &y)
122 Interval_t<T>::str() const
128 return s + T_to_str (elem (LEFT)) + String ("," ) + T_to_str (elem (RIGHT) ) + String ("]" );
133 Interval_t<T>::elem_b (T r)
135 return r >= elem (LEFT) && r <= elem (RIGHT);
139 #define INTERVAL__INSTANTIATE(T) struct Interval_t<T>;\
140 template int Interval__compare(const Interval_t<T>&,Interval_t<T> const&)
142 #endif // INTERVAL_TCC