2 interval.hh -- part of flowerlib
4 (c) 1996 Han-Wen Nienhuys
13 #include "drul-array.hh"
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.
21 struct Interval_t : public Drul_array<T> {
26 static String T_to_str (T arg);
27 T center() { return (elem (LEFT) + elem (RIGHT)) / T(2);}
36 *this and h are comparable
38 void unite (Interval_t<T> h);
39 void intersect (Interval_t<T> h);
43 bool empty_b() const { return elem (LEFT) > elem (RIGHT); }
44 bool contains_b (Interval_t<T> const&) const;
48 Interval_t (T m, T M) : Drul_array<T> (m,M)
50 Interval_t<T> &operator -= (T r) {
55 Interval_t<T> &operator += (T r) {
60 Interval_t<T> &operator *=(T r) {
65 elem (LEFT) = elem (RIGHT);
83 inclusion ordering. Crash if not comparable.
86 int Interval__compare (const Interval_t<T>&,Interval_t<T> const&);
89 Inclusion ordering. return -2 if not comparable
93 _Interval__compare (const Interval_t<T>&a,Interval_t<T> const&b);
100 #include "compare.hh"
102 TEMPLATE_INSTANTIATE_COMPARE(Interval_t<T>&, Interval__compare, template<class T>);
107 intersection (Interval_t<T> a, Interval_t<T> const&b)
116 Interval_t<T> operator +(T a,Interval_t<T> i)
124 Interval_t<T> operator - (Interval_t<T> i, T a)
132 Interval_t<T> operator - (T a,Interval_t<T> i)
141 Interval_t<T> operator +(Interval_t<T> i,T a){
147 Interval_t<T> operator *(T a,Interval_t<T> i)
155 Interval_t<T> operator *(Interval_t<T> i,T a){
159 // again? see fproto.hh
160 typedef Interval_t<Real> Interval;
161 typedef Interval_t<int> Slice; // weird name
164 #endif // INTERVAL_HH