##// END OF EJS Templates
Implements OptionalAxis::bounds() method...
Alexandre Leroux -
r901:fa55ed58c66a
parent child
Show More
@@ -41,6 +41,10 public:
41 /// @return gets the data at the index passed in parameter, NaN if the index is outside the
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
42 /// bounds of the axis, or if the axis is undefined
43 double at(int index) const;
43 double at(int index) const;
44
45 ///@return the min and max values of the data on the axis, NaN values if there is no data
46 std::pair<double, double> bounds() const;
47
44 /// @return the number of data on the axis, 0 if the axis is not defined
48 /// @return the number of data on the axis, 0 if the axis is not defined
45 int size() const;
49 int size() const;
46 /// @return the unit of the axis, an empty unit if the axis is not defined
50 /// @return the unit of the axis, an empty unit if the axis is not defined
@@ -44,6 +44,31 double OptionalAxis::at(int index) const
44 }
44 }
45 }
45 }
46
46
47 std::pair<double, double> OptionalAxis::bounds() const
48 {
49 if (!m_Defined || m_Data->size() == 0) {
50 return std::make_pair(std::numeric_limits<double>::quiet_NaN(),
51 std::numeric_limits<double>::quiet_NaN());
52 }
53 else {
54
55 auto minIt = std::min_element(
56 m_Data->cbegin(), m_Data->cend(), [](const auto &it1, const auto &it2) {
57 return SortUtils::minCompareWithNaN(it1.first(), it2.first());
58 });
59
60 // Gets the iterator on the max of all values data
61 auto maxIt = std::max_element(
62 m_Data->cbegin(), m_Data->cend(), [](const auto &it1, const auto &it2) {
63 return SortUtils::maxCompareWithNaN(it1.first(), it2.first());
64 });
65
66 auto pair = std::make_pair(minIt->first(), maxIt->first());
67
68 return std::make_pair(minIt->first(), maxIt->first());
69 }
70 }
71
47 int OptionalAxis::size() const
72 int OptionalAxis::size() const
48 {
73 {
49 return m_Defined ? m_Data->size() : 0;
74 return m_Defined ? m_Data->size() : 0;
General Comments 0
You need to be logged in to leave comments. Login now