2 interval.tcc -- implement Interval_t
4 source file of the Flower Library
6 (c) 1996--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
15 #include "interval.hh"
20 _Interval__compare (const Interval_t<T> &a, Interval_t<T> const &b)
22 if (a.elem (LEFT) == b.elem (LEFT) && a.elem (RIGHT) == b.elem (RIGHT))
25 if (a.elem (LEFT) <= b.elem (LEFT) && a.elem (RIGHT) >= b.elem (RIGHT))
28 if (a.elem (LEFT) >= b.elem (LEFT) && a.elem (RIGHT) <= b.elem (RIGHT))
36 Interval_t<T>::superset (Interval_t<T> const &a) const
38 int c_i = _Interval__compare (*this, a);
46 Interval__compare (Interval_t<T> const &a, Interval_t<T> const &b)
48 int i = _Interval__compare (a, b);
56 Interval_t<T>::set_empty ()
58 elem_ref (LEFT) = (T) infinity ();
59 elem_ref (RIGHT) = (T) -infinity ();
64 Interval_t<T>::set_full ()
66 elem_ref (LEFT) = (T) -infinity ();
67 elem_ref (RIGHT) = (T) infinity ();
72 Interval_t<T>::length () const
74 if (elem (RIGHT) <= elem (LEFT))
77 return elem (RIGHT) - elem (LEFT);
82 Interval_t<T>::delta () const
84 return elem (RIGHT) - elem (LEFT);
87 /* smallest Interval which includes *this and #h# */
90 Interval_t<T>::unite (Interval_t<T> h)
92 elem_ref (LEFT) = min (h.elem (LEFT), elem (LEFT));
93 elem_ref (RIGHT) = max (h.elem (RIGHT), elem (RIGHT));
98 Interval_t<T>::intersect (Interval_t<T> h)
100 elem_ref (LEFT) = max (h.elem (LEFT), elem (LEFT));
101 elem_ref (RIGHT) = min (h.elem (RIGHT), elem (RIGHT));
106 Interval_t<T>::to_string () const
112 return (s + T_to_string (elem (LEFT)) + String (",")
113 + T_to_string (elem (RIGHT)) + String ("]"));
118 Interval_t<T>::contains (T r)
120 return r >= elem (LEFT) && r <= elem (RIGHT);
123 #define INTERVAL__INSTANTIATE(T) struct Interval_t<T>; \
124 template int Interval__compare (const Interval_t<T> &, Interval_t<T> const &)
126 #endif // INTERVAL_TCC