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