2 interval.hh -- part of flowerlib
4 (c) 1996 Han-Wen Nienhuys
16 this represents the closed interval [left,right].
17 No invariants. T must be a totally ordered ring
25 T
center() { return (left
+ right
) / T(2);}
39 T
& operator[](int j
) {
42 T
operator[](int j
) const {
43 return ((Interval_t
<T
> *)this)->idx(j
);
45 T
&max() { return right
;}
46 T
max()const { return right
;}
47 T
min()const{ return left
; }
48 T
&min(){ return left
; }
51 *this and h are comparable
53 void unite(Interval_t
<T
> h
);
54 void intersect(Interval_t
<T
> h
);
58 bool empty() const { return left
> right
; }
62 Interval_t(T m
, T M
) {
66 Interval_t
<T
> &operator += (T r
) {
77 inclusion ordering. Crash if not comparable.
80 int Interval__compare(const Interval_t
<T
>&,Interval_t
<T
> const&);
88 template_instantiate_compare(Interval_t
<T
>&, Interval__compare
, template<class T
>);
93 intersection(Interval_t
<T
> a
, Interval_t
<T
> const&b
)
103 Interval_t
<T
> operator +(T a
,Interval_t
<T
> i
)
111 Interval_t
<T
> operator +(Interval_t
<T
> i
,T a
){
115 typedef Interval_t
<Real
> Interval
;
118 #define Interval__instantiate(T) template struct Interval_t<T>;\
119 template int Interval__compare(const Interval_t<T>&,Interval_t<T> const&)
122 #endif // INTERVAL_HH