2 interval.tcc -- implement Interval_t
4 source file of the Flower Library
6 (c) 1996, 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
15 #include "interval.hh"
17 #include "flower-debug.hh"
21 Interval_t<T>::print () const
24 *flower_dstream << str ();
29 _Interval__compare (const Interval_t<T>&a,Interval_t<T> const&b)
31 if (a.elem (LEFT) == b.elem (LEFT) && a.elem (RIGHT) == b.elem (RIGHT))
34 if (a.elem (LEFT) <= b.elem (LEFT) && a.elem (RIGHT) >= b.elem (RIGHT))
37 if (a.elem (LEFT) >= b.elem (LEFT) && a.elem (RIGHT) <= b.elem (RIGHT))
45 Interval_t<T>::contains_b (Interval_t<T> const& a) const
47 int c_i= _Interval__compare (*this, a);
55 Interval__compare (const Interval_t<T>&a,Interval_t<T> const&b)
57 int i = _Interval__compare (a,b);
65 Interval_t<T>::set_empty ()
67 elem (LEFT) = (T) infinity ();
68 elem (RIGHT) = (T) -infinity ();
73 Interval_t<T>::length () const
75 if (elem (RIGHT) < elem (LEFT))
78 return elem (RIGHT)-elem (LEFT);
82 smallest Interval which includes *this and #h#
86 Interval_t<T>::unite (Interval_t<T> h)
88 elem (LEFT) = h.elem (LEFT) <? elem (LEFT);
89 elem (RIGHT) = h.elem (RIGHT) >?elem (RIGHT);
92 if (h.elem (LEFT)<elem (LEFT))
93 elem (LEFT) = h.elem (LEFT);
94 if (h.elem (RIGHT)>elem (RIGHT))
95 elem (RIGHT) = h.elem (RIGHT);
102 Interval_t<T>::intersect (Interval_t<T> h)
104 #if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
105 elem (LEFT) = h.elem (LEFT) >? elem (LEFT);
106 elem (RIGHT) = h.elem (RIGHT) <?elem (RIGHT);
108 elem (LEFT) = max (h.elem (LEFT), elem (LEFT));
109 elem (RIGHT) = min (h.elem (RIGHT), elem (RIGHT));
115 intersect (Interval_t<T> x, Interval_t<T> const &y)
123 Interval_t<T>::str () const
129 return s + T_to_str (elem (LEFT)) + String ("," ) + T_to_str (elem (RIGHT) ) + String ("]" );
134 Interval_t<T>::elem_b (T r)
136 return r >= elem (LEFT) && r <= elem (RIGHT);
140 #define INTERVAL__INSTANTIATE(T) struct Interval_t<T>;\
141 template int Interval__compare (const Interval_t<T>&,Interval_t<T> const&)
143 #endif // INTERVAL_TCC