#2125 Refactor : Return by value instead of incoming parameter

This commit is contained in:
Magne Sjaastad 2017-11-16 13:37:47 +01:00
parent cd368d8ef2
commit 5cbaf3c1eb
5 changed files with 23 additions and 31 deletions

View File

@ -25,11 +25,10 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCurveDataTools::calculateIntervalsOfValidValues(const std::vector<double>& values,
CurveIntervals* intervals,
RigCurveDataTools::CurveIntervals RigCurveDataTools::calculateIntervalsOfValidValues(const std::vector<double>& values,
bool removeNegativeValues)
{
CVF_ASSERT(intervals);
CurveIntervals intervals;
int startIdx = -1;
size_t vIdx = 0;
@ -43,7 +42,7 @@ void RigCurveDataTools::calculateIntervalsOfValidValues(const std::vector<double
{
if (startIdx >= 0)
{
intervals->push_back(std::make_pair(startIdx, vIdx - 1));
intervals.push_back(std::make_pair(startIdx, vIdx - 1));
startIdx = -1;
}
}
@ -57,30 +56,33 @@ void RigCurveDataTools::calculateIntervalsOfValidValues(const std::vector<double
if (startIdx >= 0 && startIdx < ((int)valueCount))
{
intervals->push_back(std::make_pair(startIdx, valueCount - 1));
intervals.push_back(std::make_pair(startIdx, valueCount - 1));
}
return intervals;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigCurveDataTools::computePolyLineStartStopIndices(const CurveIntervals& intervals,
std::vector<std::pair<size_t, size_t>>* lineStartAndStopIndices)
std::vector<std::pair<size_t, size_t>> RigCurveDataTools::computePolyLineStartStopIndices(const CurveIntervals& intervals)
{
CVF_ASSERT(lineStartAndStopIndices);
std::vector<std::pair<size_t, size_t>> lineStartAndStopIndices;
const size_t intervalCount = intervals.size();
if (intervalCount < 1) return;
if (intervalCount < 1) return lineStartAndStopIndices;
size_t index = 0;
for (size_t intIdx = 0; intIdx < intervalCount; intIdx++)
{
size_t intervalSize = intervals[intIdx].second - intervals[intIdx].first + 1;
lineStartAndStopIndices->push_back(std::make_pair(index, index + intervalSize - 1));
lineStartAndStopIndices.push_back(std::make_pair(index, index + intervalSize - 1));
index += intervalSize;
}
return lineStartAndStopIndices;
}
//--------------------------------------------------------------------------------------------------

View File

@ -34,8 +34,7 @@ public:
typedef std::vector<std::pair<size_t, size_t>> CurveIntervals;
public:
static void calculateIntervalsOfValidValues(const std::vector<double>& values,
CurveIntervals* intervals,
static CurveIntervals calculateIntervalsOfValidValues(const std::vector<double>& values,
bool removeNegativeValues);
template <typename T>
@ -54,8 +53,7 @@ public:
}
}
static void computePolyLineStartStopIndices(const CurveIntervals& intervals,
std::vector<std::pair<size_t, size_t>>* lineStartAndStopIndices);
static std::vector<std::pair<size_t, size_t>> computePolyLineStartStopIndices(const CurveIntervals& intervals);
private:
static bool isValidValue(double value, bool removeNegativeValues);

View File

@ -168,15 +168,11 @@ std::vector<double> RigWellLogCurveData::measuredDepthPlotValues(RiaDefines::Dep
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector< std::pair<size_t, size_t> > RigWellLogCurveData::polylineStartStopIndices() const
std::vector<std::pair<size_t, size_t>> RigWellLogCurveData::polylineStartStopIndices() const
{
std::vector< std::pair<size_t, size_t> > lineStartStopIndices;
RigCurveDataTools::computePolyLineStartStopIndices(m_intervalsOfContinousValidValues, &lineStartStopIndices);
return lineStartStopIndices;
return RigCurveDataTools::computePolyLineStartStopIndices(m_intervalsOfContinousValidValues);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -250,8 +246,7 @@ cvf::ref<RigWellLogCurveData> RigWellLogCurveData::calculateResampledCurveData(d
//--------------------------------------------------------------------------------------------------
void RigWellLogCurveData::calculateIntervalsOfContinousValidValues()
{
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
RigCurveDataTools::calculateIntervalsOfValidValues(m_xValues, &intervalsOfValidValues, false);
std::vector<std::pair<size_t, size_t>> intervalsOfValidValues = RigCurveDataTools::calculateIntervalsOfValidValues(m_xValues, false);
m_intervalsOfContinousValidValues.clear();

View File

@ -18,8 +18,7 @@ TEST(RimWellLogExtractionCurveImplTest, StripOffInvalidValAtEndsOfVector)
values.push_back(3.0);
values.push_back(HUGE_VAL);
std::vector< std::pair<size_t, size_t> > valuesIntervals;
RigCurveDataTools::calculateIntervalsOfValidValues(values, &valuesIntervals, false);
auto valuesIntervals = RigCurveDataTools::calculateIntervalsOfValidValues(values, false);
EXPECT_EQ(1, static_cast<int>(valuesIntervals.size()));
EXPECT_EQ(2, static_cast<int>(valuesIntervals[0].first));
@ -42,8 +41,7 @@ TEST(RimWellLogExtractionCurveImplTest, StripOffHugeValAtEndsAndInteriorOfVector
values.push_back(3.0);
values.push_back(HUGE_VAL);
std::vector< std::pair<size_t, size_t> > valuesIntervals;
RigCurveDataTools::calculateIntervalsOfValidValues(values, &valuesIntervals, false);
auto valuesIntervals = RigCurveDataTools::calculateIntervalsOfValidValues(values, false);
EXPECT_EQ(2, static_cast<int>(valuesIntervals.size()));
EXPECT_EQ(2, static_cast<int>(valuesIntervals[0].first));

View File

@ -62,13 +62,12 @@ void RiuLineSegmentQwtPlotCurve::setSamplesFromXValuesAndYValues(const std::vect
std::vector<double> filteredXValues;
{
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
RigCurveDataTools::calculateIntervalsOfValidValues(yValues, &intervalsOfValidValues, removeNegativeValues);
auto intervalsOfValidValues = RigCurveDataTools::calculateIntervalsOfValidValues(yValues, removeNegativeValues);
RigCurveDataTools::getValuesByIntervals(yValues, intervalsOfValidValues, &filteredYValues);
RigCurveDataTools::getValuesByIntervals(xValues, intervalsOfValidValues, &filteredXValues);
RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues, &filteredIntervals);
filteredIntervals = RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues);
}
points.reserve(static_cast<int>(filteredXValues.size()));