Skip to content

Commit

Permalink
Use functor for equality with tolerance check
Browse files Browse the repository at this point in the history
Refs #11179
  • Loading branch information
DanNixon committed Feb 27, 2015
1 parent 916e91c commit 65a6bac
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Code/Mantid/Framework/API/src/NumericAxis.cpp
Expand Up @@ -11,11 +11,14 @@
namespace {
Mantid::Kernel::Logger g_log("NumericAxis");

// For variable tolerance comparison for axis values
double g_tolerance;
bool withinTolerance(double a, double b) {
return std::abs(a - b) <= g_tolerance;
}
class EqualWithinTolerance {
public:
EqualWithinTolerance(double tolerance) : m_tolerance(tolerance) {};
bool operator()(double a, double b) { return std::abs(a - b) <= m_tolerance; }

private:
double m_tolerance;
};
}

namespace Mantid {
Expand Down Expand Up @@ -164,9 +167,9 @@ bool NumericAxis::equalWithinTolerance(const Axis &axis2,
return false;
}
// Check each value is within tolerance
g_tolerance = tolerance;
EqualWithinTolerance comparison(tolerance);
return std::equal(m_values.begin(), m_values.end(), spec2->m_values.begin(),
withinTolerance);
comparison);
}

/** Returns a text label which shows the value at index and identifies the
Expand Down

0 comments on commit 65a6bac

Please sign in to comment.