source file of the Flower Library
- (c) 1996--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1996--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/
#ifndef INTERVAL_TCC
#define INTERVAL_TCC
#include <cassert>
-#include <cmath>
+
+// MacOS 10.3 problems:
+// #include <cmath>
+using namespace std;
#include "interval.hh"
#include "string.hh"
template<class T>
int
-_Interval__compare (const Interval_t<T>&a, Interval_t<T> const &b)
+_Interval__compare (const Interval_t<T> &a, Interval_t<T> const &b)
{
if (a.elem (LEFT) == b.elem (LEFT) && a.elem (RIGHT) == b.elem (RIGHT))
return 0;
void
Interval_t<T>::unite (Interval_t<T> h)
{
- elem_ref (LEFT) = h.elem (LEFT) <? elem (LEFT);
- elem_ref (RIGHT) = h.elem (RIGHT) >? elem (RIGHT);
+ elem_ref (LEFT) = min (h.elem (LEFT), elem (LEFT));
+ elem_ref (RIGHT) = max (h.elem (RIGHT), elem (RIGHT));
}
template<class T>
void
Interval_t<T>::intersect (Interval_t<T> h)
{
-#if defined (__GNUG__) && !defined (__STRICT_ANSI__)
- elem_ref (LEFT) = h.elem (LEFT) >? elem (LEFT);
- elem_ref (RIGHT) = h.elem (RIGHT) <? elem (RIGHT);
-#else
elem_ref (LEFT) = max (h.elem (LEFT), elem (LEFT));
elem_ref (RIGHT) = min (h.elem (RIGHT), elem (RIGHT));
-#endif
-}
-
-#if 0 //this is called intersection
-template<class T>
-Interval_t<T>
-intersect (Interval_t<T> x, Interval_t<T> const &y)
-{
- x.intersect (y);
- return x;
}
-#endif
template<class T>
String
template<class T>
bool
-Interval_t<T>::contains (T r)
+Interval_t<T>::contains (T r) const
{
return r >= elem (LEFT) && r <= elem (RIGHT);
}
#define INTERVAL__INSTANTIATE(T) struct Interval_t<T>; \
- template int Interval__compare (const Interval_t<T>&, Interval_t<T> const &)
+ template int Interval__compare (const Interval_t<T> &, Interval_t<T> const &)
#endif // INTERVAL_TCC