Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
39namespace ogdf {
40
42private:
43 const double eps;
44
45public:
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}
Basic declarations, included by all source files.
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
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.
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
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
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.
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
const double eps
Epsilon for floating point comparisons.
Definition EpsilonTest.h:43
EpsilonTest(double epsilon=1.0e-8)
Constructs an EpsilonTest with a given epsilon (double) for comparisons.
Definition EpsilonTest.h:47
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.
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.
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.
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.
The namespace for all OGDF objects.