]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.0.17
authorfred <fred>
Sun, 22 Dec 1996 22:54:39 +0000 (22:54 +0000)
committerfred <fred>
Sun, 22 Dec 1996 22:54:39 +0000 (22:54 +0000)
flower/interval.cc

index f176c7486fe5738ab5150ac46f22cdfab5b1ae4c..46b4fc7e1603f2bb7346f5af0d6ec3e857eb5404 100644 (file)
@@ -4,80 +4,90 @@
 #include "string.hh"
 
 
-const Real INFTY = HUGE;
 
-void
-Interval::set_empty() {
-    min = INFTY;
-    max = -INFTY;
-}
+template<class T>
+int
+Interval__compare(const Interval_t<T>&a,Interval_t<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;
 
-Real
-Interval::length() const {
-    assert(max >= min);
-    return max-min;
-}
+    if (a.left >= b.left && a.right <= b.right)
+       return -1;
 
-void
-Interval::unite(Interval h)
-{
-    compare(h, *this );
-    if (h.min<min)
-       min = h.min;
-    if (h.max>max)
-       max = h.max;
+    assert(false);             // not comparable
+
+    return 0;
 }
 
+const Real INFTY = HUGE;
+
+template<class T>
 void
-Interval::intersect(Interval h)
-{
-    min = MAX(h.min, min);
-    max = MIN(h.max, max);
+Interval_t<T>::set_empty() {
+    left = INFTY;
+    right = -INFTY;
 }
 
-Interval
-intersection(Interval a, Interval const&b)
-{
-    a.intersect(b);
-    return a;
-    
+template<class T>
+T
+Interval_t<T>::length() const {
+    assert(right >= left);
+    return right-left;
 }
 
-int
-Interval::compare(const Interval&a,Interval const&b)
+template<class T>
+void
+Interval_t<T>::unite(Interval_t<T> h)
 {
-    if (a.min == b.min && a.max == b.max)
-       return 0;
-    
-    if (a.min <= b.min && a.max >= b.max)
-       return 1;
-
-    if (a.min >= b.min && a.max <= b.max)
-       return -1;
+    if (h.left<left)
+       left = h.left;
+    if (h.right>right)
+       right = h.right;
+}
 
-    assert(false);             // not comparable
+/**
+  smallest Interval which includes *this and #h#
+ */
 
-    return 0;
+template<class T>
+void
+Interval_t<T>::intersect(Interval_t<T> h)
+{
+#if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
+    left = h.left >? left;
+    right = h.right <?right;
+#else
+    left = max(h.left, left);
+    right = min(h.right, right);
+#endif
 }
 
-Interval
-intersect(Interval x, Interval const &y)
+template<class T>
+Interval_t<T>
+intersect(Interval_t<T> x, Interval_t<T> const &y)
 {
     x.intersect(y);
     return x;
 }
-    
+
+template<class T>
 String
-Interval::str() const
+Interval_t<T>::str() const
 {
     if (empty())
        return "[empty]";
     String s("[");
  
-    return s + min + "," + max +"]";
+    return s + left + "," + right +"]";
 }
+
+template<class T>
 bool
-Interval::elt_q(Real r)
+Interval_t<T>::elt_q(T r)
 {
-    return r >= min && r <= max;
+    return r >= left && r <= right;
 }