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.
27 static String T_to_str (T arg);
29 // ugh, egcs 1.02 ices on this
30 // T center() { return (left + right) / T(2);}
31 // and can't handle this either
32 // anyone want to make a bug report?
35 return (left + right) / two;
37 void translate (T t) {
50 T& operator[](int j) {
53 T operator[](int j) const {
54 return ((Interval_t<T> *)this)->idx (j);
56 T &max() { return right;}
57 T max() const { return right;}
58 T min() const{ return left; }
59 T &min(){ return left; }
62 *this and h are comparable
64 void unite (Interval_t<T> h);
65 void intersect (Interval_t<T> h);
69 bool empty_b() const { return left > right; }
70 bool contains_b (Interval_t<T> const&) const;
74 Interval_t (T m, T M) {
78 Interval_t<T> &operator += (T r) {
83 Interval_t<T> &operator *=(T r) {
106 inclusion ordering. Crash if not comparable.
109 int Interval__compare (const Interval_t<T>&,Interval_t<T> const&);
115 #include "compare.hh"
117 TEMPLATE_INSTANTIATE_COMPARE(Interval_t<T>&, Interval__compare, template<class T>);
122 intersection (Interval_t<T> a, Interval_t<T> const&b)
131 Interval_t<T> operator +(T a,Interval_t<T> i)
139 Interval_t<T> operator - (Interval_t<T> i, T a)
147 Interval_t<T> operator - (T a,Interval_t<T> i)
156 Interval_t<T> operator +(Interval_t<T> i,T a){
162 Interval_t<T> operator *(T a,Interval_t<T> i)
170 Interval_t<T> operator *(Interval_t<T> i,T a){
174 typedef Interval_t<Real> Interval;
179 #endif // INTERVAL_HH