18#ifndef vtkMathUtilities_h
19#define vtkMathUtilities_h
21#include "vtkABINamespace.h"
30VTK_ABI_NAMESPACE_BEGIN
37bool FuzzyCompare(A a, A b, A epsilon = std::numeric_limits<A>::epsilon())
39 return fabs(a - b) < epsilon;
49 if ((b <
static_cast<A
>(1)) && (a > b * std::numeric_limits<A>::max()))
51 return std::numeric_limits<A>::max();
55 if ((a ==
static_cast<A
>(0)) ||
56 ((b >
static_cast<A
>(1)) && (a < b * std::numeric_limits<A>::min())))
58 return static_cast<A
>(0);
71bool NearlyEqual(A a, A b, A tol = std::numeric_limits<A>::epsilon())
73 A absdiff = fabs(a - b);
74 A d1 = vtkMathUtilities::SafeDivision<A>(absdiff, fabs(a));
75 A d2 = vtkMathUtilities::SafeDivision<A>(absdiff, fabs(b));
77 return ((d1 <= tol) || (d2 <= tol));
110 max0 = max0 < value ? value : max0;
112 else if (value > max0)
114 min0 = min0 > value ? value : min0;
121 typename std::enable_if<!std::is_floating_point<A>::value>::type* =
nullptr)
123 UpdateRangeImpl<A>(min0, max0, value);
128 typename std::enable_if<std::is_floating_point<A>::value>::type* =
nullptr)
130 if (!std::isnan(value))
132 UpdateRangeImpl<A>(min0, max0, value);
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 NB: this uses an absolute to...
void UpdateRange(A &min0, A &max0, const A &value, typename std::enable_if<!std::is_floating_point< A >::value >::type *=nullptr)