2 interval.hh -- part of flowerlib
4 (c) 1996 Han-Wen Nienhuys
15 /** a T interval. this represents the closed interval [left,right].
16 No invariants. T must be a totally ordered ring (with division, anyway ..)
17 At instantiation, the function infinity() has to be defined explicitely.
28 T center() { return (left + right) / T(2);}
42 T& operator[](int j) {
45 T operator[](int j) const {
46 return ((Interval_t<T> *)this)->idx(j);
48 T &max() { return right;}
49 T max()const { return right;}
50 T min()const{ return left; }
51 T &min(){ return left; }
54 *this and h are comparable
56 void unite(Interval_t<T> h);
57 void intersect(Interval_t<T> h);
61 bool empty_b() const { return left > right; }
62 bool contains_b(Interval_t<T> const&) const;
66 Interval_t(T m, T M) {
70 Interval_t<T> &operator += (T r) {
81 inclusion ordering. Crash if not comparable.
84 int Interval__compare(const Interval_t<T>&,Interval_t<T> const&);
92 template_instantiate_compare(Interval_t<T>&, Interval__compare, template<class T>);
97 intersection(Interval_t<T> a, Interval_t<T> const&b)
107 Interval_t<T> operator +(T a,Interval_t<T> i )
115 Interval_t<T> operator +(Interval_t<T> i,T a ){
119 typedef Interval_t<Real> Interval;
122 #define Interval__instantiate(T) template struct Interval_t<T>;\
123 template int Interval__compare(const Interval_t<T>&,Interval_t<T> const&)
126 #endif // INTERVAL_HH