From 1375ebe39a77e603fd511b6318cd47d5335f377a Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 22 Dec 1996 22:54:38 +0000 Subject: [PATCH] flower-1.0.18 --- flower/interval.tcc | 93 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 flower/interval.tcc diff --git a/flower/interval.tcc b/flower/interval.tcc new file mode 100644 index 0000000000..46b4fc7e16 --- /dev/null +++ b/flower/interval.tcc @@ -0,0 +1,93 @@ +#include +#include +#include "interval.hh" +#include "string.hh" + + + +template +int +Interval__compare(const Interval_t&a,Interval_t const&b) +{ + if (a.left == b.left && a.right == b.right) + return 0; + + if (a.left <= b.left && a.right >= b.right) + return 1; + + if (a.left >= b.left && a.right <= b.right) + return -1; + + assert(false); // not comparable + + return 0; +} + +const Real INFTY = HUGE; + +template +void +Interval_t::set_empty() { + left = INFTY; + right = -INFTY; +} + +template +T +Interval_t::length() const { + assert(right >= left); + return right-left; +} + +template +void +Interval_t::unite(Interval_t h) +{ + if (h.leftright) + right = h.right; +} + +/** + smallest Interval which includes *this and #h# + */ + +template +void +Interval_t::intersect(Interval_t h) +{ +#if defined (__GNUG__) && ! defined (__STRICT_ANSI__) + left = h.left >? left; + right = h.right +Interval_t +intersect(Interval_t x, Interval_t const &y) +{ + x.intersect(y); + return x; +} + +template +String +Interval_t::str() const +{ + if (empty()) + return "[empty]"; + String s("["); + + return s + left + "," + right +"]"; +} + +template +bool +Interval_t::elt_q(T r) +{ + return r >= left && r <= right; +} -- 2.39.5