-struct Interval_t {
- T left, right;
-
- /* ************** */
-
- static T infinity() ;
-
- T center() { return (left + right) / T(2);}
- void translate(T t) {
- left += t;
- right += t;
- }
- T& idx(int j) {
- if (j==-1)
- return left;
- else if (j==1)
- return right;
- else
- assert(false);
- return left;
- }
- T& operator[](int j) {
- return idx(j);
- }
- T operator[](int j) const {
- return ((Interval_t<T> *)this)->idx(j);
- }
- T &max() { return right;}
- T max()const { return right;}
- T min()const{ return left; }
- T &min(){ return left; }
- /**
- PRE
- *this and h are comparable
- */
- void unite(Interval_t<T> h);
- void intersect(Interval_t<T> h);
-
- T length() const;
- void set_empty() ;
- bool empty_b() const { return left > right; }
- bool contains_b(Interval_t<T> const&) const;
- Interval_t() {
- set_empty();
- }
- Interval_t(T m, T M) {
- left =m;
- right = M;
- }
- Interval_t<T> &operator += (T r) {
- left += r;
- right +=r;
- return *this;
- }
- String str() const;
- bool elt_b(T r);
+struct Interval_t : public Drul_array<T>
+{
+ Drul_array<T>::at;
+
+ static T infinity ();
+ static string T_to_string (T arg);
+ T center () const;
+ void translate (T t)
+ {
+ at (LEFT) += t;
+ at (RIGHT) += t;
+ }
+ void widen (T t)
+ {
+ at (LEFT) -= t;
+ at (RIGHT) += t;
+ }
+
+ T distance (T t) const
+ {
+ if (t > at (RIGHT))
+ return T (t - at (RIGHT));
+ else if (t < at (LEFT))
+ return T (at (LEFT) - t);
+ else
+ return T (0);
+ }
+ /**
+ PRE
+ *this and h are comparable
+ */
+ void unite (Interval_t<T> h);
+ void intersect (Interval_t<T> h);
+ void add_point (T p)
+ {
+ at (LEFT) = min (at (LEFT), p);
+ at (RIGHT) = max (at (RIGHT), p);
+ }
+ T length () const;
+ T delta () const;
+ void set_empty ();
+ void set_full ();
+
+ bool is_empty () const
+ {
+ return at (LEFT) > at (RIGHT);
+ }
+ bool superset (Interval_t<T> const &) const;
+ Interval_t ()
+ {
+ set_empty ();
+ }
+ Interval_t (Drul_array<T> const &src)
+ : Drul_array<T> (src)
+ {
+ }
+
+ Interval_t (T m, T M) : Drul_array<T> (m, M)
+ {
+ }
+ Interval_t<T> &operator -= (T r)
+ {
+ *this += -r;
+ return *this;
+ }
+
+ Interval_t<T> &operator += (T r)
+ {
+ at (LEFT) += r;
+ at (RIGHT) += r;
+ return *this;
+ }
+ Interval_t<T> &operator *= (T r)
+ {
+ if (!is_empty ())
+ {
+ at (LEFT) *= r;
+ at (RIGHT) *= r;
+ if (r < T (0))
+ swap ();
+ }
+ return *this;
+ }
+
+ Real linear_combination (Real x) const;
+ string to_string () const;
+
+ bool contains (T r) const;
+ void negate ()
+ {
+ T r = -at (LEFT);
+ T l = -at (RIGHT);
+ at (LEFT) = l;
+ at (RIGHT) = r;
+ }
+
+ void swap ()
+ {
+ T t = at (LEFT);
+ at (LEFT) = at (RIGHT);
+ at (RIGHT) = t;
+ }
+
+ static bool left_less (Interval_t<T> const &a, Interval_t<T> const &b)
+ {
+ return a[LEFT] < b[RIGHT];
+ }