Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

EpsilonTest.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/basic.h>
36 
37 #include <type_traits>
38 
39 namespace ogdf {
40 
41 class EpsilonTest {
42 private:
43  const double eps;
44 
45 public:
47  explicit EpsilonTest(double epsilon = 1.0e-8) : eps(epsilon) { }
48 
49  // LESS: integral and floating_point
51 
56  template<typename T>
57  inline typename std::enable_if<std::is_integral<T>::value, bool>::type less(const T& x,
58  const T& y) const {
59  return x < y;
60  }
61 
64 
69  template<typename T>
70  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type less(const T& x,
71  const T& y) const {
72  return x < (y - eps);
73  }
74 
75  // LEQ: integral and floating_point
77 
82  template<typename T>
83  inline typename std::enable_if<std::is_integral<T>::value, bool>::type leq(const T& x,
84  const T& y) const {
85  return x <= y;
86  }
87 
90 
95  template<typename T>
96  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type leq(const T& x,
97  const T& y) const {
98  return x < (y + eps);
99  }
100 
101  // EQUAL: integral and floating_point
103 
108  template<typename T>
109  inline typename std::enable_if<std::is_integral<T>::value, bool>::type equal(const T& x,
110  const T& y) const {
111  return x == y;
112  }
113 
116 
121  template<typename T>
122  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type equal(const T& x,
123  const T& y) const {
124  return leq(x, y) && geq(x, y);
125  }
126 
127  // GEQ: integral and floating_point
129 
134  template<typename T>
135  inline typename std::enable_if<std::is_integral<T>::value, bool>::type geq(const T& x,
136  const T& y) const {
137  return x >= y;
138  }
139 
142 
147  template<typename T>
148  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type geq(const T& x,
149  const T& y) const {
150  return x > (y - eps);
151  }
152 
153  // GREATER: integral and floating_point
155 
160  template<typename T>
161  inline typename std::enable_if<std::is_integral<T>::value, bool>::type greater(const T& x,
162  const T& y) const {
163  return x > y;
164  }
165 
168 
173  template<typename T>
174  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type greater(const T& x,
175  const T& y) const {
176  return x > (y + eps);
177  }
178 };
179 
180 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::EpsilonTest
Definition: EpsilonTest.h:41
ogdf::EpsilonTest::eps
const double eps
Epsilon for floating point comparisons.
Definition: EpsilonTest.h:43
ogdf::EpsilonTest::less
std::enable_if< std::is_integral< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for integral types.
Definition: EpsilonTest.h:57
ogdf::EpsilonTest::greater
std::enable_if< std::is_floating_point< T >::value, bool >::type greater(const T &x, const T &y) const
Compare if x is GREATER than y for floating point types, using the given epsilon.
Definition: EpsilonTest.h:174
backward::Color::type
type
Definition: backward.hpp:1716
ogdf::EpsilonTest::geq
std::enable_if< std::is_floating_point< T >::value, bool >::type geq(const T &x, const T &y) const
Compare if x is GEQ to y for floating point types, using the given epsilon.
Definition: EpsilonTest.h:148
ogdf::EpsilonTest::greater
std::enable_if< std::is_integral< T >::value, bool >::type greater(const T &x, const T &y) const
Compare if x is GREATER than y for integral types.
Definition: EpsilonTest.h:161
ogdf::EpsilonTest::equal
std::enable_if< std::is_floating_point< T >::value, bool >::type equal(const T &x, const T &y) const
Compare if x is EQUAL to y for floating point types, using the given epsilon.
Definition: EpsilonTest.h:122
ogdf::EpsilonTest::less
std::enable_if< std::is_floating_point< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for floating point types, using the given epsilon.
Definition: EpsilonTest.h:70
ogdf::EpsilonTest::leq
std::enable_if< std::is_integral< T >::value, bool >::type leq(const T &x, const T &y) const
Compare if x is LEQ than y for integral types.
Definition: EpsilonTest.h:83
ogdf::EpsilonTest::EpsilonTest
EpsilonTest(double epsilon=1.0e-8)
Constructs an EpsilonTest with a given epsilon (double) for comparisons.
Definition: EpsilonTest.h:47
ogdf::EpsilonTest::equal
std::enable_if< std::is_integral< T >::value, bool >::type equal(const T &x, const T &y) const
Compare if x is EQUAL to y for integral types.
Definition: EpsilonTest.h:109
ogdf::EpsilonTest::leq
std::enable_if< std::is_floating_point< T >::value, bool >::type leq(const T &x, const T &y) const
Compare if x is LEQ than y for floating point types, using the given epsilon.
Definition: EpsilonTest.h:96
basic.h
Basic declarations, included by all source files.
ogdf::EpsilonTest::geq
std::enable_if< std::is_integral< T >::value, bool >::type geq(const T &x, const T &y) const
Compare if x is GEQ to y for integral types.
Definition: EpsilonTest.h:135