Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

EpsilonTest.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <type_traits>
36 
37 namespace ogdf {
38 
39 class EpsilonTest {
40 private:
41  const double eps;
42 
43 public:
45  explicit EpsilonTest(double epsilon = 1.0e-8) : eps(epsilon) { }
46 
47  // LESS: integral and floating_point
49 
54  template<typename T>
55  inline typename std::enable_if<std::is_integral<T>::value, bool>::type less(const T& x,
56  const T& y) const {
57  return x < y;
58  }
59 
62 
67  template<typename T>
68  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type less(const T& x,
69  const T& y) const {
70  return x < (y - eps);
71  }
72 
73  // LEQ: integral and floating_point
75 
80  template<typename T>
81  inline typename std::enable_if<std::is_integral<T>::value, bool>::type leq(const T& x,
82  const T& y) const {
83  return x <= y;
84  }
85 
88 
93  template<typename T>
94  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type leq(const T& x,
95  const T& y) const {
96  return x < (y + eps);
97  }
98 
99  // EQUAL: integral and floating_point
101 
106  template<typename T>
107  inline typename std::enable_if<std::is_integral<T>::value, bool>::type equal(const T& x,
108  const T& y) const {
109  return x == y;
110  }
111 
114 
119  template<typename T>
120  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type equal(const T& x,
121  const T& y) const {
122  return leq(x, y) && geq(x, y);
123  }
124 
125  // GEQ: integral and floating_point
127 
132  template<typename T>
133  inline typename std::enable_if<std::is_integral<T>::value, bool>::type geq(const T& x,
134  const T& y) const {
135  return x >= y;
136  }
137 
140 
145  template<typename T>
146  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type geq(const T& x,
147  const T& y) const {
148  return x > (y - eps);
149  }
150 
151  // GREATER: integral and floating_point
153 
158  template<typename T>
159  inline typename std::enable_if<std::is_integral<T>::value, bool>::type greater(const T& x,
160  const T& y) const {
161  return x > y;
162  }
163 
166 
171  template<typename T>
172  inline typename std::enable_if<std::is_floating_point<T>::value, bool>::type greater(const T& x,
173  const T& y) const {
174  return x > (y + eps);
175  }
176 };
177 
178 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::EpsilonTest
Definition: EpsilonTest.h:39
ogdf::EpsilonTest::eps
const double eps
Epsilon for floating point comparisons.
Definition: EpsilonTest.h:41
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:55
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:172
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:146
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:159
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:120
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:68
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:81
ogdf::EpsilonTest::EpsilonTest
EpsilonTest(double epsilon=1.0e-8)
Constructs an EpsilonTest with a given epsilon (double) for comparisons.
Definition: EpsilonTest.h:45
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:107
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:94
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:133