From 9a52fd42b9d8de952bf9f4fe399f183105dc5a74 2017-08-23 12:29:35 From: Alexandre Leroux Date: 2017-08-23 12:29:35 Subject: [PATCH] Adds methods min() and max() in ArrayData iterators In a case of an 2-dim ArrayData, the search is made on all components. --- diff --git a/core/include/Data/ArrayData.h b/core/include/Data/ArrayData.h index f33f0a5..8097f53 100644 --- a/core/include/Data/ArrayData.h +++ b/core/include/Data/ArrayData.h @@ -70,6 +70,26 @@ public: double at(int index) const { return *m_Its.at(index); } double first() const { return *m_Its.front(); } + /// @return the min value among all components + double min() const + { + auto end = m_Its.cend(); + auto it = std::min_element(m_Its.cbegin(), end, [](const auto &it1, const auto &it2) { + return SortUtils::minCompareWithNaN(*it1, *it2); + }); + return it != end ? **it : std::numeric_limits::quiet_NaN(); + } + + /// @return the max value among all components + double max() const + { + auto end = m_Its.cend(); + auto it = std::max_element(m_Its.cbegin(), end, [](const auto &it1, const auto &it2) { + return SortUtils::maxCompareWithNaN(*it1, *it2); + }); + return it != end ? **it : std::numeric_limits::quiet_NaN(); + } + void next() { for (auto &it : m_Its) {