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 <type_traits>
36
37namespace ogdf {
38
40private:
41 const double eps;
42
43public:
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}
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
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:81
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
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:55
const double eps
Epsilon for floating point comparisons.
Definition EpsilonTest.h:41
EpsilonTest(double epsilon=1.0e-8)
Constructs an EpsilonTest with a given epsilon (double) for comparisons.
Definition EpsilonTest.h:45
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.