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);}
29 void translate (T t
) {
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
) {
75 Interval_t
<T
> &operator *=(T r
) {
91 inclusion ordering. Crash if not comparable.
94 int Interval__compare (const Interval_t
<T
>&,Interval_t
<T
> const&);
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
){
130 Interval_t
<T
> operator *(T a
,Interval_t
<T
> i
)
138 Interval_t
<T
> operator *(Interval_t
<T
> i
,T a
){
142 typedef Interval_t
<Real
> Interval
;
147 #endif // INTERVAL_HH