From f0509409825b38bc618713e476beef3f666930f1 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 22 Dec 1996 22:13:21 +0000 Subject: [PATCH] flower-1.0.17 --- flower/interval.hh | 96 ++++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/flower/interval.hh b/flower/interval.hh index 5331c1d125..4184451701 100644 --- a/flower/interval.hh +++ b/flower/interval.hh @@ -12,82 +12,104 @@ #include "real.hh" -/// a Real interval -struct Interval { - Real min, max; +/// a T interval +template +struct Interval_t { + T left, right; /****************/ - Real center() { return (min + max) /2;} - void translate(Real t) { - min += t; - max += t; + T center() { return (left + right) /2;} + void translate(T t) { + left += t; + right += t; } - Real operator[](int j) { + T operator[](int j) { if (j==-1) - return min; + return left; else if (j==1) - return max; + return right; else assert(false); - return 0.0; - + return 0; } - void unite(Interval h) ; + void unite(Interval_t h); /** PRE *this and h are comparable */ - void intersect(Interval h); + void intersect(Interval_t h); - Real length() const; + T length() const; void set_empty() ; - bool empty() const { return min > max; } - Interval() { + bool empty() const { return left > right; } + Interval_t() { set_empty(); } - Interval(Real m, Real M) { - min =m; - max = M; + Interval_t(T m, T M) { + left =m; + right = M; } - Interval &operator += (Real r) { - min += r; - max +=r; + Interval_t &operator += (T r) { + left += r; + right +=r; return *this; } - bool elt_q(Real r); - String str() const; - - /// partial ordering - static compare(const Interval&,Interval const&); - /** - inclusion ordering. Crash if not comparable. - */ + String str() const; + bool elt_q(T r); }; /** - this represents the closed interval [min,max]. - No invariants + this represents the closed interval [left,right]. + No invariants. T must be a totally ordered ring + */ + +/// partial ordering +template +int Interval__compare(const Interval_t&,Interval_t const&); +/** + inclusion ordering. Crash if not comparable. */ -Interval intersection(Interval, Interval const&); +/**************************************************************** + INLINE + ****************************************************************/ #include "compare.hh" -instantiate_compare(Interval&, Interval::compare); +template_instantiate_compare(Interval_t&, Interval__compare, template); +template +inline Interval_t +intersection(Interval_t a, Interval_t const&b) +{ + a.intersect(b); + return a; + +} + + +template inline -Interval operator +(double a,Interval i ) +Interval_t operator +(T a,Interval_t i ) { i += a; return i; } +template inline -Interval operator +(Interval i,double a ){ +Interval_t operator +(Interval_t i,T a ){ return a+i; } +typedef Interval_t Interval; + + +#define Interval__instantiate(T) template struct Interval_t;\ + template int Interval__compare(const Interval_t&,Interval_t const&) + + #endif // INTERVAL_HH -- 2.39.5