From db2236fe221344d2d260bde24b261bae5817afd6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 8 Apr 2022 15:17:41 +0200 Subject: [PATCH] Gui: [skip ci] improve readability of SoFCColorGradient::setRange --- src/Gui/SoFCColorGradient.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Gui/SoFCColorGradient.cpp b/src/Gui/SoFCColorGradient.cpp index 048cc481d4..987111fbf5 100644 --- a/src/Gui/SoFCColorGradient.cpp +++ b/src/Gui/SoFCColorGradient.cpp @@ -161,12 +161,13 @@ void SoFCColorGradient::setRange(float fMin, float fMax, int prec) // otherwise output "normal" (fixed notation) SoMFString label; - std::ios::fmtflags flags = (std::ios::fixed | std::ios::showpoint | std::ios::showpos); float eps = std::pow(10.0f, static_cast(-prec)); + float value_min = std::min(fabs(fMin), fabs(fMax)); + float value_max = std::max(fabs(fMin), fabs(fMax)); - if ( ( (std::min(fabs(fMin), fabs(fMax)) < eps) && (std::min(fabs(fMin), fabs(fMax)) != 0.0f) ) - || (std::max(fabs(fMin), fabs(fMax)) > 1e4) ) - flags = (std::ios::scientific | std::ios::showpoint | std::ios::showpos); + bool scientific = (value_min < eps && value_min > 0.0f) || value_max > 1e4; + std::ios::fmtflags flags = scientific ? (std::ios::scientific | std::ios::showpoint | std::ios::showpos) + : (std::ios::fixed | std::ios::showpoint | std::ios::showpos); // write the labels int i = 0;