From fa55ed58c66aa2bf27940a73eb59de901c1f6486 2017-11-08 08:27:55 From: Alexandre Leroux Date: 2017-11-08 08:27:55 Subject: [PATCH] Implements OptionalAxis::bounds() method This method will be used to get min/max of th y-axis of a spectrogramm, to use it for setting the Y range of the colormap --- diff --git a/core/include/Data/OptionalAxis.h b/core/include/Data/OptionalAxis.h index 1d3b198..73e6ae2 100644 --- a/core/include/Data/OptionalAxis.h +++ b/core/include/Data/OptionalAxis.h @@ -41,6 +41,10 @@ public: /// @return gets the data at the index passed in parameter, NaN if the index is outside the /// bounds of the axis, or if the axis is undefined double at(int index) const; + + ///@return the min and max values of the data on the axis, NaN values if there is no data + std::pair bounds() const; + /// @return the number of data on the axis, 0 if the axis is not defined int size() const; /// @return the unit of the axis, an empty unit if the axis is not defined diff --git a/core/src/Data/OptionalAxis.cpp b/core/src/Data/OptionalAxis.cpp index 8e25635..024fd4d 100644 --- a/core/src/Data/OptionalAxis.cpp +++ b/core/src/Data/OptionalAxis.cpp @@ -44,6 +44,31 @@ double OptionalAxis::at(int index) const } } +std::pair OptionalAxis::bounds() const +{ + if (!m_Defined || m_Data->size() == 0) { + return std::make_pair(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()); + } + else { + + auto minIt = std::min_element( + m_Data->cbegin(), m_Data->cend(), [](const auto &it1, const auto &it2) { + return SortUtils::minCompareWithNaN(it1.first(), it2.first()); + }); + + // Gets the iterator on the max of all values data + auto maxIt = std::max_element( + m_Data->cbegin(), m_Data->cend(), [](const auto &it1, const auto &it2) { + return SortUtils::maxCompareWithNaN(it1.first(), it2.first()); + }); + + auto pair = std::make_pair(minIt->first(), maxIt->first()); + + return std::make_pair(minIt->first(), maxIt->first()); + } +} + int OptionalAxis::size() const { return m_Defined ? m_Data->size() : 0;