VTK  9.5.20251211
vtkMathUtilities Namespace Reference

Functions

template<class A>
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 tolerance.
 
template<class A>
SafeDivision (A a, A b)
 Performs safe division that catches overflow and underflow.
 
template<class A>
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, "The Art of Computer Programming (vol II)" NB: this uses a relative tolerance.
 
template<class A>
void UpdateRange (A &min, A &max, const A &value)
 Update an existing min - max range with a new prospective value.
 
template<class A>
void UpdateRangeFinite (A &min, A &max, const A &value)
 Update an existing min - max range with a new prospective value.
 

Function Documentation

◆ FuzzyCompare()

template<class A>
bool vtkMathUtilities::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 tolerance.

Definition at line 39 of file vtkMathUtilities.h.

◆ SafeDivision()

template<class A>
A vtkMathUtilities::SafeDivision ( A a,
A b )

Performs safe division that catches overflow and underflow.

Definition at line 48 of file vtkMathUtilities.h.

◆ NearlyEqual()

template<class A>
bool vtkMathUtilities::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, "The Art of Computer Programming (vol II)" NB: this uses a relative tolerance.

Definition at line 73 of file vtkMathUtilities.h.

◆ UpdateRange()

template<class A>
void vtkMathUtilities::UpdateRange ( A & min,
A & max,
const A & value )
inline

Update an existing min - max range with a new prospective value.

If the value is non NaN then the appropriate range comparisons are made and updated, otherwise the original min - max values are set.

Examples:

No change: UpdateRange(-100, 100, 20) -> (-100, 100)

Update min: UpdateRange(-100, 100, -200) -> (-200, 100)

Update max: UpdateRange(-100, 100, 200) -> (-100, 200)

Input min and max are inverted creating an invalid range so a new range with the specified value is set: UpdateRange(100, -100, 20) -> (20, 20)

Input value is NaN so the original range is set UpdateRange(-100, 100, NaN) -> (-100, 100)

Definition at line 106 of file vtkMathUtilities.h.

◆ UpdateRangeFinite()

template<class A>
void vtkMathUtilities::UpdateRangeFinite ( A & min,
A & max,
const A & value )
inline

Update an existing min - max range with a new prospective value.

If the value is finite (not NaN or Inf) then the appropriate range comparisons are made and updated, otherwise the original min - max values are set.

Definition at line 133 of file vtkMathUtilities.h.