MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / computeMinMaxValues

Method computeMinMaxValues

app/src/UI/Widgets/Plot.cpp:776–815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

774 */
775template<typename Extractor>
776bool Widgets::Plot::computeMinMaxValues(double& min,
777 double& max,
778 const DataModel::Dataset& dataset,
779 const bool addPadding,
780 Extractor extractor)
781{
782 bool ok = true;
783 const auto prevMinY = min;
784 const auto prevMaxY = max;
785
786 if (m_data.isEmpty()) {
787 min = 0;
788 max = 1;
789 }
790
791 else {
792 ok &= DSP::notEqual(dataset.pltMin, dataset.pltMax);
793 if (ok) {
794 min = qMin(dataset.pltMin, dataset.pltMax);
795 max = qMax(dataset.pltMin, dataset.pltMax);
796 }
797 }
798
799 if (!ok) {
800 min = std::numeric_limits<double>::max();
801 max = std::numeric_limits<double>::lowest();
802
803 for (auto i = 0; i < m_data.size(); ++i) {
804 const double value = extractor(m_data[i]);
805 if (std::isfinite(value)) {
806 min = qMin(min, value);
807 max = qMax(max, value);
808 }
809 }
810
811 padDerivedRange(min, max, addPadding);
812 }
813
814 return DSP::notEqual(prevMinY, min) || DSP::notEqual(prevMaxY, max);
815}
816
817/**
818 * @brief Pads a data-derived [min, max] range and rounds to integer bounds.

Callers

nothing calls this directly

Calls 4

notEqualFunction · 0.85
isfiniteFunction · 0.85
isEmptyMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected