##// END OF EJS Templates
(Refactoring) Renames IDataSeries::subData()
Alexandre Leroux -
r605:06b66012b93b
parent child
Show More
@@ -210,23 +210,22 public:
210 return it == cbegin() ? cend() : --it;
210 return it == cbegin() ? cend() : --it;
211 }
211 }
212
212
213 std::pair<DataSeriesIterator, DataSeriesIterator> subData(double min, double max) const override
213 std::pair<DataSeriesIterator, DataSeriesIterator> xAxisRange(double minXAxisData,
214 double maxXAxisData) const override
214 {
215 {
215 if (min > max) {
216 if (minXAxisData > maxXAxisData) {
216 std::swap(min, max);
217 std::swap(minXAxisData, maxXAxisData);
217 }
218 }
218
219
219 auto begin = cbegin();
220 auto begin = cbegin();
220 auto end = cend();
221 auto end = cend();
221
222
222 auto lowerIt
223 auto lowerIt = std::lower_bound(
223 = std::lower_bound(begin, end, min, [](const auto &itValue, const auto &value) {
224 begin, end, minXAxisData,
224 return itValue.x() < value;
225 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
225 });
226 auto upperIt = std::upper_bound(
226 auto upperIt
227 begin, end, maxXAxisData,
227 = std::upper_bound(begin, end, max, [](const auto &value, const auto &itValue) {
228 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
228 return value < itValue.x();
229 });
230
229
231 return std::make_pair(lowerIt, upperIt);
230 return std::make_pair(lowerIt, upperIt);
232 }
231 }
@@ -78,8 +78,10 public:
78 /// equal to the value passed in parameter, or the end iterator if there is no matching value
78 /// equal to the value passed in parameter, or the end iterator if there is no matching value
79 virtual DataSeriesIterator maxXAxisData(double maxXAxisData) const = 0;
79 virtual DataSeriesIterator maxXAxisData(double maxXAxisData) const = 0;
80
80
81 virtual std::pair<DataSeriesIterator, DataSeriesIterator> subData(double min,
81 /// @return the iterators pointing to the range of data whose x-axis values are between min and
82 double max) const = 0;
82 /// max passed in parameters
83 virtual std::pair<DataSeriesIterator, DataSeriesIterator>
84 xAxisRange(double minXAxisData, double maxXAxisData) const = 0;
83
85
84 // /////// //
86 // /////// //
85 // Mutexes //
87 // Mutexes //
@@ -18,7 +18,7 std::shared_ptr<IDataSeries> ScalarSeries::subDataSeries(const SqpRange &range)
18 auto subValuesData = QVector<double>();
18 auto subValuesData = QVector<double>();
19 this->lockRead();
19 this->lockRead();
20 {
20 {
21 auto bounds = subData(range.m_TStart, range.m_TEnd);
21 auto bounds = xAxisRange(range.m_TStart, range.m_TEnd);
22 for (auto it = bounds.first; it != bounds.second; ++it) {
22 for (auto it = bounds.first; it != bounds.second; ++it) {
23 subXAxisData.append(it->x());
23 subXAxisData.append(it->x());
24 subValuesData.append(it->value());
24 subValuesData.append(it->value());
@@ -24,7 +24,7 std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range)
24
24
25 this->lockRead();
25 this->lockRead();
26 {
26 {
27 auto bounds = subData(range.m_TStart, range.m_TEnd);
27 auto bounds = xAxisRange(range.m_TStart, range.m_TEnd);
28 for (auto it = bounds.first; it != bounds.second; ++it) {
28 for (auto it = bounds.first; it != bounds.second; ++it) {
29 subXAxisData.append(it->x());
29 subXAxisData.append(it->x());
30 subXValuesData.append(it->value(0));
30 subXValuesData.append(it->value(0));
@@ -38,11 +38,11 private slots:
38 void testMaxXAxisData();
38 void testMaxXAxisData();
39
39
40 /// Input test data
40 /// Input test data
41 /// @sa testSubdata()
41 /// @sa testXAxisRange()
42 void testSubdata_data();
42 void testXAxisRange_data();
43
43
44 /// Tests get subdata of two data series
44 /// Tests get x-axis range of a data series
45 void testSubdata();
45 void testXAxisRange();
46 };
46 };
47
47
48 void TestDataSeries::testCtor_data()
48 void TestDataSeries::testCtor_data()
@@ -289,20 +289,20 void TestDataSeries::testMaxXAxisData()
289 }
289 }
290 }
290 }
291
291
292 void TestDataSeries::testSubdata_data()
292 void TestDataSeries::testXAxisRange_data()
293 {
293 {
294 // ////////////// //
294 // ////////////// //
295 // Test structure //
295 // Test structure //
296 // ////////////// //
296 // ////////////// //
297
297
298 // Data series to get subdata
298 // Data series to get x-axis range
299 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
299 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
300
300
301 // Min/max values
301 // Min/max values
302 QTest::addColumn<double>("min");
302 QTest::addColumn<double>("min");
303 QTest::addColumn<double>("max");
303 QTest::addColumn<double>("max");
304
304
305 // Expected values after subdata
305 // Expected values
306 QTest::addColumn<QVector<double> >("expectedXAxisData");
306 QTest::addColumn<QVector<double> >("expectedXAxisData");
307 QTest::addColumn<QVector<double> >("expectedValuesData");
307 QTest::addColumn<QVector<double> >("expectedValuesData");
308
308
@@ -310,29 +310,37 void TestDataSeries::testSubdata_data()
310 // Test cases //
310 // Test cases //
311 // ////////// //
311 // ////////// //
312
312
313 QTest::newRow("subData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
313 QTest::newRow("xAxisRange1") << createSeries({1., 2., 3., 4., 5.},
314 << -1. << 3.2 << QVector<double>{1., 2., 3.}
314 {100., 200., 300., 400., 500.})
315 << QVector<double>{100., 200., 300.};
315 << -1. << 3.2 << QVector<double>{1., 2., 3.}
316 QTest::newRow("subData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
316 << QVector<double>{100., 200., 300.};
317 << 1. << 4. << QVector<double>{1., 2., 3., 4.}
317 QTest::newRow("xAxisRange2") << createSeries({1., 2., 3., 4., 5.},
318 << QVector<double>{100., 200., 300., 400.};
318 {100., 200., 300., 400., 500.})
319 QTest::newRow("subData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
319 << 1. << 4. << QVector<double>{1., 2., 3., 4.}
320 << 1. << 3.9 << QVector<double>{1., 2., 3.}
320 << QVector<double>{100., 200., 300., 400.};
321 << QVector<double>{100., 200., 300.};
321 QTest::newRow("xAxisRange3") << createSeries({1., 2., 3., 4., 5.},
322 QTest::newRow("subData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
322 {100., 200., 300., 400., 500.})
323 << 0. << 0.9 << QVector<double>{} << QVector<double>{};
323 << 1. << 3.9 << QVector<double>{1., 2., 3.}
324 QTest::newRow("subData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
324 << QVector<double>{100., 200., 300.};
325 << 0. << 1. << QVector<double>{1.} << QVector<double>{100.};
325 QTest::newRow("xAxisRange4") << createSeries({1., 2., 3., 4., 5.},
326 QTest::newRow("subData6") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
326 {100., 200., 300., 400., 500.})
327 << 2.1 << 6. << QVector<double>{3., 4., 5.}
327 << 0. << 0.9 << QVector<double>{} << QVector<double>{};
328 << QVector<double>{300., 400., 500.};
328 QTest::newRow("xAxisRange5") << createSeries({1., 2., 3., 4., 5.},
329 QTest::newRow("subData7") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
329 {100., 200., 300., 400., 500.})
330 << 6. << 9. << QVector<double>{} << QVector<double>{};
330 << 0. << 1. << QVector<double>{1.} << QVector<double>{100.};
331 QTest::newRow("subData8") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
331 QTest::newRow("xAxisRange6") << createSeries({1., 2., 3., 4., 5.},
332 << 5. << 9. << QVector<double>{5.} << QVector<double>{500.};
332 {100., 200., 300., 400., 500.})
333 << 2.1 << 6. << QVector<double>{3., 4., 5.}
334 << QVector<double>{300., 400., 500.};
335 QTest::newRow("xAxisRange7") << createSeries({1., 2., 3., 4., 5.},
336 {100., 200., 300., 400., 500.})
337 << 6. << 9. << QVector<double>{} << QVector<double>{};
338 QTest::newRow("xAxisRange8") << createSeries({1., 2., 3., 4., 5.},
339 {100., 200., 300., 400., 500.})
340 << 5. << 9. << QVector<double>{5.} << QVector<double>{500.};
333 }
341 }
334
342
335 void TestDataSeries::testSubdata()
343 void TestDataSeries::testXAxisRange()
336 {
344 {
337 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
345 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
338 QFETCH(double, min);
346 QFETCH(double, min);
@@ -341,7 +349,7 void TestDataSeries::testSubdata()
341 QFETCH(QVector<double>, expectedXAxisData);
349 QFETCH(QVector<double>, expectedXAxisData);
342 QFETCH(QVector<double>, expectedValuesData);
350 QFETCH(QVector<double>, expectedValuesData);
343
351
344 auto bounds = dataSeries->subData(min, max);
352 auto bounds = dataSeries->xAxisRange(min, max);
345 QVERIFY(std::equal(bounds.first, bounds.second, expectedXAxisData.cbegin(),
353 QVERIFY(std::equal(bounds.first, bounds.second, expectedXAxisData.cbegin(),
346 expectedXAxisData.cend(),
354 expectedXAxisData.cend(),
347 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
355 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
@@ -149,7 +149,7 struct PlottablesUpdater<T,
149 // - Gets the data of the series included in the current range
149 // - Gets the data of the series included in the current range
150 // - Updates each plottable by adding, for each data item, a point that takes x-axis data
150 // - Updates each plottable by adding, for each data item, a point that takes x-axis data
151 // and value data. The correct value is retrieved according to the index of the component
151 // and value data. The correct value is retrieved according to the index of the component
152 auto subDataIts = dataSeries.subData(range.m_TStart, range.m_TEnd);
152 auto subDataIts = dataSeries.xAxisRange(range.m_TStart, range.m_TEnd);
153 for (auto it = subDataIts.first; it != subDataIts.second; ++it) {
153 for (auto it = subDataIts.first; it != subDataIts.second; ++it) {
154 for (const auto &dataContainer : dataContainers) {
154 for (const auto &dataContainer : dataContainers) {
155 auto componentIndex = dataContainer.first;
155 auto componentIndex = dataContainer.first;
General Comments 0
You need to be logged in to leave comments. Login now