#include <assert.h>
-#include "interval.hh"
#include <math.h>
+#include "interval.hh"
+#include "string.hh"
+
const Real INFTY = HUGE;
assert(max >= min);
return max-min;
}
+void
+Interval::unite(Interval h)
+{
+ if (h.min<min)
+ min = h.min;
+ if (h.max>max)
+ max = h.max;
+}
+void
+Interval::intersect(Interval h)
+{
+ min = MAX(h.min, min);
+ max = MIN(h.max, max);
+}
+Interval
+intersect(Interval x, Interval const &y)
+{
+ x.intersect(y);
+ return x;
+}
+
+
+Interval::operator String() const
+{
+ if (empty())
+ return "[empty]";
+ String s("[");
+
+ return s + min + "," + max +"]";
+}
#define INTERVAL_HH
#include <assert.h>
+#include "fproto.hh"
#include "real.hh"
return 0.0;
}
- void unite(Interval h) {
- if (h.min<min)
- min = h.min;
- if (h.max>max)
- max = h.max;
- }
+ void unite(Interval h) ;
+ void intersect(Interval h);
+
Real length() const;
void set_empty() ;
- bool empty() { return min > max; }
+ bool empty() const { return min > max; }
Interval() {
set_empty();
}
max +=r;
return *this;
}
+
+ operator String() const;
};
+Interval intersection(Interval, Interval const&);
+
#endif // INTERVAL_HH