not extrapolating towards negative in VFP tables

This commit is contained in:
Kai Bao
2019-07-29 14:47:33 +02:00
parent 8f2997fde6
commit a772d1ef03
2 changed files with 7 additions and 3 deletions

View File

@@ -199,15 +199,19 @@ struct InterpData {
/** /**
* Helper function to find indices etc. for linear interpolation and extrapolation * Helper function to find indices etc. for linear interpolation and extrapolation
* @param value Value to find in values * @param value_in Value to find in values
* @param values Sorted list of values to search for value in. * @param values Sorted list of values to search for value in.
* @return Data required to find the interpolated value * @return Data required to find the interpolated value
*/ */
inline InterpData findInterpData(const double& value, const std::vector<double>& values) { inline InterpData findInterpData(const double& value_in, const std::vector<double>& values) {
InterpData retval; InterpData retval;
const int nvalues = values.size(); const int nvalues = values.size();
// chopping the value to be zero, which means we do not
// extrapolate the table towards nagative ranges
const double value = value_in < 0.? 0. : value_in;
//If we only have one value in our vector, return that //If we only have one value in our vector, return that
if (values.size() == 1) { if (values.size() == 1) {
retval.ind_[0] = 0; retval.ind_[0] = 0;

View File

@@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(findInterpData)
BOOST_CHECK_EQUAL(eval2.ind_[0], 0); BOOST_CHECK_EQUAL(eval2.ind_[0], 0);
BOOST_CHECK_EQUAL(eval2.ind_[1], 1); BOOST_CHECK_EQUAL(eval2.ind_[1], 1);
BOOST_CHECK_EQUAL(eval2.factor_, -0.5); BOOST_CHECK_EQUAL(eval2.factor_, -0.25);
BOOST_CHECK_EQUAL(eval3.ind_[0], 4); BOOST_CHECK_EQUAL(eval3.ind_[0], 4);
BOOST_CHECK_EQUAL(eval3.ind_[1], 5); BOOST_CHECK_EQUAL(eval3.ind_[1], 5);