18 #ifndef vtkMathUtilities_h
19 #define vtkMathUtilities_h
21 #include "vtkABINamespace.h"
26 #include <type_traits>
30 VTK_ABI_NAMESPACE_BEGIN
36 bool FuzzyCompare(A a, A b, A epsilon = std::numeric_limits<A>::epsilon())
38 return fabs(a - b) < epsilon;
54 if ((a ==
static_cast<A
>(0)) ||
55 ((b >
static_cast<A
>(1)) && (a < b * std::numeric_limits<A>::min())))
57 return static_cast<A
>(0);
69 bool NearlyEqual(A a, A b, A tol = std::numeric_limits<A>::epsilon())
71 A absdiff = fabs(a - b);
72 A d1 = vtkMathUtilities::SafeDivision<A>(absdiff, fabs(a));
73 A d2 = vtkMathUtilities::SafeDivision<A>(absdiff, fabs(b));
75 return ((d1 <= tol) || (d2 <= tol));
110 else if (
value > max0)
121 UpdateRangeImpl<A>(min0, max0,
value);
130 UpdateRangeImpl<A>(min0, max0,
value);
134 VTK_ABI_NAMESPACE_END
void UpdateRangeImpl(A &min0, A &max0, const A &value)
Update an existing min - max range with a new prospective value.
bool NearlyEqual(A a, A b, A tol=std::numeric_limits< A >::epsilon())
A slightly different fuzzy comparator that checks if two values are "nearly" equal based on Knuth,...
A SafeDivision(A a, A b)
Performs safe division that catches overflow and underflow.
bool FuzzyCompare(A a, A b, A epsilon=std::numeric_limits< A >::epsilon())
Perform a fuzzy compare of floats/doubles, specify the allowed tolerance.
void UpdateRange(A &min0, A &max0, const A &value, typename std::enable_if<!std::is_floating_point< A >::value >::type *=nullptr)