From 1ef1123a80a6af7986822aec80941828d8615a8c Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@igpm.rwth-aachen.de>
Date: Sun, 26 Jan 2014 18:07:33 +0000
Subject: [PATCH] Copy the file interval.hh from dune-fufem to here.

dune-tnnmg needs it, but we want dune-tnnmg to be independent from dune-fufem.
Hence we make a copy here in dune-solvers, which dune-tnnmg will always depend
on.

[[Imported from SVN: r12745]]
---
 dune/solvers/common/Makefile.am |  1 +
 dune/solvers/common/interval.hh | 79 +++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)
 create mode 100644 dune/solvers/common/interval.hh

diff --git a/dune/solvers/common/Makefile.am b/dune/solvers/common/Makefile.am
index f93219a8..01aa3468 100644
--- a/dune/solvers/common/Makefile.am
+++ b/dune/solvers/common/Makefile.am
@@ -4,6 +4,7 @@ commondir = $(includedir)/dune/solvers/common
 common_HEADERS = boxconstraint.hh \
                  genericvectortools.hh \
                  canignore.hh \
+                 interval.hh \
                  numproc.hh \
                  permutationmanager.hh \
                  preconditioner.hh \
diff --git a/dune/solvers/common/interval.hh b/dune/solvers/common/interval.hh
new file mode 100644
index 00000000..6b5e6360
--- /dev/null
+++ b/dune/solvers/common/interval.hh
@@ -0,0 +1,79 @@
+#ifndef DUNE_SOLVERS_COMMON_INTERVAL_HH
+#define DUNE_SOLVERS_COMMON_INTERVAL_HH
+
+#include <iostream>
+#include <algorithm>
+
+
+
+#include <dune/common/array.hh>
+
+
+
+/** \brief Encapsulates a closed interval
+ * \tparam field_type The type used for real numbers
+ */
+template <class field_type>
+class Interval
+{
+public:
+    /** \brief Array-like access
+     */
+    field_type& operator[](int i)
+    {
+        return data_[i];
+    }
+    
+    /** \brief Const array-like access
+     */
+    const field_type& operator[](int i) const
+    {
+        return data_[i];
+    }
+    
+    /** \brief Project a scalar onto the interval
+     */
+    field_type projectIn(const field_type& x) const
+    {
+        return std::max(std::min(x,data_[1]), data_[0]);
+    }
+    
+    /** \brief Fast projection onto the interval if you know that your value
+     *         is smaller than your upper bound
+     */
+    field_type projectFromBelow(const field_type& x) const
+    {
+        return std::max(x,data_[0]);
+    };
+
+    /** \brief Fast projection onto the interval if you know that your value
+     *         is larger than your lower bound
+     */
+    field_type projectFromAbove(const field_type& x) const
+    {
+        return std::min(x,data_[1]);
+    };
+
+    /** \brief Return true if zero is contained in the interval
+     * \param safety An additive safety distance
+     */
+    bool containsZero(const field_type& safety) const
+    {
+        return (data_[0] <= safety) and (-safety <= data_[1]);
+    };
+
+private:
+    
+    /** \brief The actual data */
+    Dune::array<field_type,2> data_;
+};
+
+//! Output operator for Interval
+template <class field_type>
+inline std::ostream& operator<< (std::ostream& s, const Interval<field_type>& interval)
+{
+    s << "[" << interval[0] << ", " << interval[1] << "]";
+    return s;
+}
+  
+#endif
-- 
GitLab