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 T center() { return (left + right) / T(2);}
30 void translate (T t) {
43 T& operator[](int j) {
46 T operator[](int j) const {
47 return ((Interval_t<T> *)this)->idx (j);
49 T &max() { return right;}
50 T max() const { return right;}
51 T min() const{ return left; }
52 T &min(){ return left; }
55 *this and h are comparable
57 void unite (Interval_t<T> h);
58 void intersect (Interval_t<T> h);
62 bool empty_b() const { return left > right; }
63 bool contains_b (Interval_t<T> const&) const;
67 Interval_t (T m, T M) {
71 Interval_t<T> &operator += (T r) {
76 Interval_t<T> &operator *=(T r) {
99 inclusion ordering. Crash if not comparable.
102 int Interval__compare (const Interval_t<T>&,Interval_t<T> const&);
108 #include "compare.hh"
110 TEMPLATE_INSTANTIATE_COMPARE(Interval_t<T>&, Interval__compare, template<class T>);
115 intersection (Interval_t<T> a, Interval_t<T> const&b)
124 Interval_t<T> operator +(T a,Interval_t<T> i)
132 Interval_t<T> operator - (Interval_t<T> i, T a)
140 Interval_t<T> operator - (T a,Interval_t<T> i)
149 Interval_t<T> operator +(Interval_t<T> i,T a){
155 Interval_t<T> operator *(T a,Interval_t<T> i)
163 Interval_t<T> operator *(Interval_t<T> i,T a){
167 typedef Interval_t<Real> Interval;
172 #endif // INTERVAL_HH