1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 08:55:37 +00:00

Updated nearest interpolation to use equal_range function.

This commit is contained in:
Matt Spraggs 2015-11-09 23:04:09 +00:00
parent de7bdc68a4
commit ff49304137

View File

@ -88,14 +88,14 @@ double TabFunction::operator()(const double *arg) const
break; break;
} }
case InterpType::NEAREST: { case InterpType::NEAREST: {
auto it = value_.upper_bound(x); auto it = value_.equal_range(x);
auto upper_pair = *it; auto lower = (x == it.first->first) ? it.first : prev(it.first);
auto lower_pair = *(--it); auto upper = it.second;
if (fabs(upper_pair.first - x) < fabs(lower_pair.first - x)) { if (fabs(upper->first - x) < fabs(lower->first - x)) {
result = upper_pair.second; result = upper->second;
} }
else { else {
result = lower_pair.second; result = lower->second;
} }
break; break;
} }