Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

EpsilonTest.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/basic.h>
36 #include <type_traits>
37 
38 namespace ogdf {
39 
40 class EpsilonTest {
41 private:
42  const double eps;
43 
44 public:
46  explicit EpsilonTest(double epsilon = 1.0e-8) : eps(epsilon) {}
47 
48  // LESS: integral and floating_point
50 
55  template<typename T>
56  inline typename std::enable_if<std::is_integral<T>::value, bool>::type
57  less(const T &x, const T &y) const
58  {
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
71  less(const T &x, const T &y) const
72  {
73  return x < (y - eps);
74  }
75 
76  // LEQ: integral and floating_point
78 
83  template<typename T>
84  inline typename std::enable_if<std::is_integral<T>::value, bool>::type
85  leq(const T &x, const T &y) const
86  {
87  return x <= y;
88  }
89 
92 
97  template<typename T>
98  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type
99  leq(const T &x, const T &y) const
100  {
101  return x < (y + eps);
102  }
103 
104  // EQUAL: integral and floating_point
106 
111  template<typename T>
112  inline typename std::enable_if<std::is_integral<T>::value, bool>::type
113  equal(const T &x, const T &y) const
114  {
115  return x == y;
116  }
117 
120 
125  template<typename T>
126  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type
127  equal(const T &x, const T &y) const
128  {
129  return leq(x, y) && geq(x, y);
130  }
131 
132  // GEQ: integral and floating_point
134 
139  template<typename T>
140  inline typename std::enable_if<std::is_integral<T>::value, bool>::type
141  geq(const T &x, const T &y) const
142  {
143  return x >= y;
144  }
145 
148 
153  template<typename T>
154  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type
155  geq(const T &x, const T &y) const
156  {
157  return x > (y - eps);
158  }
159 
160  // GREATER: integral and floating_point
162 
167  template<typename T>
168  inline typename std::enable_if<std::is_integral<T>::value, bool>::type
169  greater(const T &x, const T &y) const
170  {
171  return x > y;
172  }
173 
176 
181  template<typename T>
182  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type
183  greater(const T &x, const T &y) const
184  {
185  return x > (y + eps);
186  }
187 };
188 
189 }
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:85
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:155
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:113
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:99
const double eps
Epsilon for floating point comparisons.
Definition: EpsilonTest.h:42
EpsilonTest(double epsilon=1.0e-8)
Constructs an EpsilonTest with a given epsilon (double) for comparisons.
Definition: EpsilonTest.h:46
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
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:127
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:71
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:169
Basic declarations, included by all source files.
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:183
The namespace for all OGDF objects.
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:141