##// END OF EJS Templates
Updates access to y-axis properties of the data series (2)...
Alexandre Leroux -
r989:958f5923ee65
parent child
Show More
@@ -36,7 +36,9 public:
36 36 template <bool IC = IsConst, typename = std::enable_if_t<IC == false> >
37 37 explicit IteratorValue(DataSeries<Dim> &dataSeries, bool begin)
38 38 : m_XIt(begin ? dataSeries.xAxisData()->begin() : dataSeries.xAxisData()->end()),
39 m_ValuesIt(begin ? dataSeries.valuesData()->begin() : dataSeries.valuesData()->end())
39 m_ValuesIt(begin ? dataSeries.valuesData()->begin() : dataSeries.valuesData()->end()),
40 m_YItBegin{dataSeries.yAxis().begin()},
41 m_YItEnd{dataSeries.yAxis().end()}
40 42 {
41 43 }
42 44
@@ -44,7 +46,9 public:
44 46 explicit IteratorValue(const DataSeries<Dim> &dataSeries, bool begin)
45 47 : m_XIt(begin ? dataSeries.xAxisData()->cbegin() : dataSeries.xAxisData()->cend()),
46 48 m_ValuesIt(begin ? dataSeries.valuesData()->cbegin()
47 : dataSeries.valuesData()->cend())
49 : dataSeries.valuesData()->cend()),
50 m_YItBegin{dataSeries.yAxis().cbegin()},
51 m_YItEnd{dataSeries.yAxis().cend()}
48 52 {
49 53 }
50 54
@@ -65,7 +69,9 public:
65 69
66 70 bool equals(const DataSeriesIteratorValue::Impl &other) const override try {
67 71 const auto &otherImpl = dynamic_cast<const IteratorValue &>(other);
68 return std::tie(m_XIt, m_ValuesIt) == std::tie(otherImpl.m_XIt, otherImpl.m_ValuesIt);
72 return std::tie(m_XIt, m_ValuesIt, m_YItBegin, m_YItEnd)
73 == std::tie(otherImpl.m_XIt, otherImpl.m_ValuesIt, otherImpl.m_YItBegin,
74 otherImpl.m_YItEnd);
69 75 }
70 76 catch (const std::bad_cast &) {
71 77 return false;
@@ -99,6 +105,15 public:
99 105 }
100 106
101 107 double x() const override { return m_XIt->at(0); }
108 std::vector<double> y() const override
109 {
110 std::vector<double> result{};
111 std::transform(m_YItBegin, m_YItEnd, std::back_inserter(result),
112 [](const auto &it) { return it.first(); });
113
114 return result;
115 }
116
102 117 double value() const override { return m_ValuesIt->at(0); }
103 118 double value(int componentIndex) const override { return m_ValuesIt->at(componentIndex); }
104 119 double minValue() const override { return m_ValuesIt->min(); }
@@ -110,11 +125,15 public:
110 125 auto &otherImpl = dynamic_cast<IteratorValue &>(other);
111 126 m_XIt->impl()->swap(*otherImpl.m_XIt->impl());
112 127 m_ValuesIt->impl()->swap(*otherImpl.m_ValuesIt->impl());
128 m_YItBegin->impl()->swap(*otherImpl.m_YItBegin->impl());
129 m_YItEnd->impl()->swap(*otherImpl.m_YItEnd->impl());
113 130 }
114 131
115 132 private:
116 133 ArrayDataIterator m_XIt;
117 134 ArrayDataIterator m_ValuesIt;
135 ArrayDataIterator m_YItBegin;
136 ArrayDataIterator m_YItEnd;
118 137 };
119 138 } // namespace dataseries_detail
120 139
@@ -27,6 +27,7 public:
27 27 virtual void next(int offset) = 0;
28 28 virtual void prev() = 0;
29 29 virtual double x() const = 0;
30 virtual std::vector<double> y() const = 0;
30 31 virtual double value() const = 0;
31 32 virtual double value(int componentIndex) const = 0;
32 33 virtual double minValue() const = 0;
@@ -51,6 +52,8 public:
51 52 void prev();
52 53 /// Gets x-axis data
53 54 double x() const;
55 /// Gets y-axis data
56 std::vector<double> y() const;
54 57 /// Gets value data
55 58 double value() const;
56 59 /// Gets value data depending on an index
@@ -1,6 +1,8
1 1 #ifndef SCIQLOP_OPTIONALAXIS_H
2 2 #define SCIQLOP_OPTIONALAXIS_H
3 3
4 #include <Data/ArrayDataIterator.h>
5
4 6 #include "CoreGlobal.h"
5 7 #include "Unit.h"
6 8
@@ -38,10 +40,6 public:
38 40 /// @return the flag that indicates if the axis is defined or not
39 41 bool isDefined() const;
40 42
41 /// @return gets the data at the index passed in parameter, NaN if the index is outside the
42 /// bounds of the axis, or if the axis is undefined
43 double at(int index) const;
44
45 43 ///@return the min and max values of the data on the axis, NaN values if there is no data
46 44 std::pair<double, double> bounds() const;
47 45
@@ -53,6 +51,12 public:
53 51 bool operator==(const OptionalAxis &other);
54 52 bool operator!=(const OptionalAxis &other);
55 53
54 // Iterators on data
55 ArrayDataIterator begin();
56 ArrayDataIterator end();
57 ArrayDataIterator cbegin() const;
58 ArrayDataIterator cend() const;
59
56 60 private:
57 61 bool m_Defined; ///< Axis is defined or not
58 62 std::shared_ptr<ArrayData<1> > m_Data; ///< Axis' data
@@ -52,6 +52,11 double DataSeriesIteratorValue::x() const
52 52 return m_Impl->x();
53 53 }
54 54
55 std::vector<double> DataSeriesIteratorValue::y() const
56 {
57 return m_Impl->y();
58 }
59
55 60 double DataSeriesIteratorValue::value() const
56 61 {
57 62 return m_Impl->value();
@@ -2,7 +2,8
2 2
3 3 #include "Data/ArrayData.h"
4 4
5 OptionalAxis::OptionalAxis() : m_Defined{false}, m_Data{nullptr}, m_Unit{}
5 OptionalAxis::OptionalAxis()
6 : m_Defined{false}, m_Data{std::make_shared<ArrayData<1> >(std::vector<double>{})}, m_Unit{}
6 7 {
7 8 }
8 9
@@ -15,9 +16,7 OptionalAxis::OptionalAxis(std::shared_ptr<ArrayData<1> > data, Unit unit)
15 16 }
16 17
17 18 OptionalAxis::OptionalAxis(const OptionalAxis &other)
18 : m_Defined{other.m_Defined},
19 m_Data{other.m_Data ? std::make_shared<ArrayData<1> >(*other.m_Data) : nullptr},
20 m_Unit{other.m_Unit}
19 : m_Defined{other.m_Defined}, m_Data{other.m_Data}, m_Unit{other.m_Unit}
21 20 {
22 21 }
23 22
@@ -35,17 +34,6 bool OptionalAxis::isDefined() const
35 34 return m_Defined;
36 35 }
37 36
38 double OptionalAxis::at(int index) const
39 {
40 if (m_Defined) {
41 return (index >= 0 && index < m_Data->size()) ? m_Data->at(index)
42 : std::numeric_limits<double>::quiet_NaN();
43 }
44 else {
45 return std::numeric_limits<double>::quiet_NaN();
46 }
47 }
48
49 37 std::pair<double, double> OptionalAxis::bounds() const
50 38 {
51 39 if (!m_Defined || m_Data->size() == 0) {
@@ -97,3 +85,23 bool OptionalAxis::operator!=(const OptionalAxis &other)
97 85 {
98 86 return !(*this == other);
99 87 }
88
89 ArrayDataIterator OptionalAxis::begin()
90 {
91 return m_Data->begin();
92 }
93
94 ArrayDataIterator OptionalAxis::end()
95 {
96 return m_Data->end();
97 }
98
99 ArrayDataIterator OptionalAxis::cbegin() const
100 {
101 return m_Data->cbegin();
102 }
103
104 ArrayDataIterator OptionalAxis::cend() const
105 {
106 return m_Data->cend();
107 }
@@ -17,10 +17,6 private slots:
17 17 void testDefinedAxisCtor_data();
18 18 void testDefinedAxisCtor();
19 19
20 /// Tests @sa OptionalAxis::at() method
21 void testAt_data();
22 void testAt();
23
24 20 /// Tests @sa OptionalAxis::size() method
25 21 void testSize_data();
26 22 void testSize();
@@ -64,39 +60,6 void TestOptionalAxis::testDefinedAxisCtor()
64 60 }
65 61 }
66 62
67 void TestOptionalAxis::testAt_data()
68 {
69 QTest::addColumn<OptionalAxis>("axis"); // Axis used for test case (defined or not)
70 QTest::addColumn<int>("index"); // Index to test in the axis
71 QTest::addColumn<double>("expectedValue"); // Expected axis value for the index
72
73 OptionalAxis definedAxis{std::make_shared<ArrayData<1> >(std::vector<double>{1, 2, 3}),
74 Unit{"Hz"}};
75
76 QTest::newRow("data1") << definedAxis << 0 << 1.;
77 QTest::newRow("data2") << definedAxis << 1 << 2.;
78 QTest::newRow("data3") << definedAxis << 2 << 3.;
79 QTest::newRow("data4 (index out of bounds)")
80 << definedAxis << 3
81 << std::numeric_limits<double>::quiet_NaN(); // Expects NaN for out of bounds index
82 QTest::newRow("data5 (index out of bounds)")
83 << definedAxis << -1
84 << std::numeric_limits<double>::quiet_NaN(); // Expects NaN for out of bounds index
85 QTest::newRow("data6 (axis not defined)")
86 << OptionalAxis{} << 0
87 << std::numeric_limits<double>::quiet_NaN(); // Expects NaN for undefined axis
88 }
89
90 void TestOptionalAxis::testAt()
91 {
92 QFETCH(OptionalAxis, axis);
93 QFETCH(int, index);
94 QFETCH(double, expectedValue);
95
96 auto value = axis.at(index);
97 QVERIFY((std::isnan(value) && std::isnan(expectedValue)) || value == expectedValue);
98 }
99
100 63 void TestOptionalAxis::testSize_data()
101 64 {
102 65 QTest::addColumn<OptionalAxis>("axis"); // Axis used for test case (defined or not)
@@ -135,11 +135,10 struct ExpectedResults {
135 135 QCOMPARE(yAxis.unit(), m_YAxisUnit);
136 136
137 137 // Data
138 auto yAxisSize = yAxis.size();
139 QCOMPARE(yAxisSize, m_YAxisData.size());
140 for (auto i = 0; i < yAxisSize; ++i) {
141 QCOMPARE(yAxis.at(i), m_YAxisData.at(i));
142 }
138 QVERIFY(std::equal(yAxis.cbegin(), yAxis.cend(), m_YAxisData.cbegin(),
139 m_YAxisData.cend(), [](const auto &it, const auto &expectedVal) {
140 return it.first() == expectedVal;
141 }));
143 142 }
144 143 }
145 144 else {
General Comments 0
You need to be logged in to leave comments. Login now