Commit 1cf2db60 authored by Purves, Murray's avatar Purves, Murray
Browse files

Fix for interpolation to new base values when base values are high->low

parent a5c4a110
Pipeline #35079 failed with stages
in 9 minutes and 20 seconds
......@@ -181,24 +181,34 @@ std::vector<T> interpolateToOtherBaseValues(
for (size_t i = 0; i < newBaseValues.size(); ++i)
{
// Fill in values with a new base lower than the lowest original
if ((lowToHigh && newBaseValues[i] < baseValues.front()) ||
(!lowToHigh && newBaseValues[i] < baseValues.back()))
if (!lowToHigh && newBaseValues[i] < baseValues.back())
{
radix_line(" Base value "
<< newBaseValues[i] << " below range " << baseValues.front()
<< "-" << baseValues.back() << ": filling with lowest");
finalInterpolatedValues[i] = std::min(initialInterpolatedValues.front(),
initialInterpolatedValues.back());
finalInterpolatedValues[i] = initialInterpolatedValues.back();
}
else if (lowToHigh && newBaseValues[i] < baseValues.front())
{
radix_line(" Base value "
<< newBaseValues[i] << " below range " << baseValues.front()
<< "-" << baseValues.back() << ": filling with lowest");
finalInterpolatedValues[i] = initialInterpolatedValues.front();
}
// Fill in values with a new base higher than the highest original
else if ((lowToHigh && newBaseValues[i] > baseValues.back()) ||
(!lowToHigh && newBaseValues[i] > baseValues.front()))
else if (!lowToHigh && newBaseValues[i] > baseValues.front())
{
radix_line(" Base value "
<< newBaseValues[i] << " above range " << baseValues.front()
<< "-" << baseValues.back() << ": filling with highest");
finalInterpolatedValues[i] = initialInterpolatedValues.front();
}
else if (lowToHigh && newBaseValues[i] > baseValues.back())
{
radix_line(" Base value "
<< newBaseValues[i] << " above range " << baseValues.front()
<< "-" << baseValues.back() << ": filling with highest");
finalInterpolatedValues[i] = std::max(initialInterpolatedValues.front(),
initialInterpolatedValues.back());
finalInterpolatedValues[i] = initialInterpolatedValues.back();
}
// Fill in central values
else
......
......@@ -191,3 +191,22 @@ TEST(Interpolate, NewBaseValuesDoubles)
expectValues1[i] * tolerance);
}
}
TEST(Interpolate, NewBaseValuesHighToLow)
{
double missingValue = -9999.0;
double tolerance = 0.0001;
std::vector<double> baseValues1{1000.0, 2000.0, 3000.0};
std::vector<double> newBaseValues1{100.0, 500.0, 1500.0, 2000.0,
2500.0, 3500.0, 18000.0};
std::vector<double> interpValues1{30.5, 20.5, 10.5};
std::vector<double> expectValues1{30.5, 30.5, 25.5, 20.5, 15.5, 10.5, 10.5};
std::vector<double> testValues1 =
interpolateToOtherBaseValues(baseValues1, newBaseValues1, interpValues1);
ASSERT_EQ(expectValues1.size(), testValues1.size());
for (size_t i = 0; i < testValues1.size(); ++i)
{
EXPECT_NEAR(expectValues1[i], testValues1[i], expectValues1[i] * tolerance);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment