]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/interval.cc
Doc-es: various updates.
[lilypond.git] / flower / interval.cc
index 46b4fc7e1603f2bb7346f5af0d6ec3e857eb5404..a73da9e7889a4552bc7bd7a35582d7dbe4798c1a 100644 (file)
@@ -1,93 +1,53 @@
-#include <assert.h> 
-#include <math.h>
-#include "interval.hh"
-#include "string.hh"
-
+/*
+  This file is part of LilyPond, the GNU music typesetter.
 
+  Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-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;
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
 
-    if (a.left >= b.left && a.right <= b.right)
-       return -1;
-
-    assert(false);             // not comparable
-
-    return 0;
-}
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
 
-const Real INFTY = HUGE;
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
-template<class T>
-void
-Interval_t<T>::set_empty() {
-    left = INFTY;
-    right = -INFTY;
-}
+#include "interval.hh"
 
-template<class T>
-T
-Interval_t<T>::length() const {
-    assert(right >= left);
-    return right-left;
-}
+#include "interval.tcc"
 
-template<class T>
-void
-Interval_t<T>::unite(Interval_t<T> h)
+template<>
+Real
+Interval_t<Real>::infinity ()
 {
-    if (h.left<left)
-       left = h.left;
-    if (h.right>right)
-       right = h.right;
+  return HUGE_VAL;
 }
 
-/**
-  smallest Interval which includes *this and #h#
- */
-
-template<class T>
-void
-Interval_t<T>::intersect(Interval_t<T> h)
+template<>
+string
+Interval_t<Real>::T_to_string (Real r)
 {
-#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
+  return ::to_string (r);
 }
 
-template<class T>
-Interval_t<T>
-intersect(Interval_t<T> x, Interval_t<T> const &y)
+template<>
+int
+Interval_t<int>::infinity ()
 {
-    x.intersect(y);
-    return x;
+  return INT_MAX;
 }
 
-template<class T>
-String
-Interval_t<T>::str() const
+template<>
+string
+Interval_t<int>::T_to_string (int i)
 {
-    if (empty())
-       return "[empty]";
-    String s("[");
-    return s + left + "," + right +"]";
+  return ::to_string (i);
 }
 
-template<class T>
-bool
-Interval_t<T>::elt_q(T r)
-{
-    return r >= left && r <= right;
-}
+template INTERVAL__INSTANTIATE (int);
+template INTERVAL__INSTANTIATE (Real);