diff --git a/src/App/ColorModel.cpp b/src/App/ColorModel.cpp
index 555e4a1510..4b6ff2e1b4 100644
--- a/src/App/ColorModel.cpp
+++ b/src/App/ColorModel.cpp
@@ -27,6 +27,7 @@
#endif
#include "ColorModel.h"
+#include
using namespace App;
@@ -107,7 +108,10 @@ void ColorField::set (const ColorModel &rclModel, float fMin, float fMax, std::s
{
colorModel = rclModel;
this->fMin = std::min(fMin, fMax);
- this->fMax = std::max(this->fMin + CCR_EPS, fMax);
+ this->fMax = std::max(fMin, fMax);
+ if (this->fMax <= this->fMin) {
+ throw Base::ValueError("Maximum must be higher than minimum");
+ }
ctColors = std::max(usCt, colorModel.getCountColors());
rebuild();
}
@@ -206,7 +210,10 @@ std::vector ColorGradient::getColorModelNames() const
void ColorGradient::set (float fMin, float fMax, std::size_t usCt, TStyle tS, bool bOG)
{
_fMin = std::min(fMin, fMax);
- _fMax = std::max(_fMin + CCR_EPS, fMax);
+ _fMax = std::max(fMin, fMax);
+ if (_fMax <= _fMin) {
+ throw Base::ValueError("Maximum must be higher than minimum");
+ }
ctColors = std::max(usCt, getMinColors());
tStyle = tS;
outsideGrayed = bOG;
diff --git a/src/App/ColorModel.h b/src/App/ColorModel.h
index 998b1154cb..4f1611fe40 100644
--- a/src/App/ColorModel.h
+++ b/src/App/ColorModel.h
@@ -31,8 +31,6 @@
#include
#include
-#define CCR_EPS 1.0e-5f
-
namespace App
{
diff --git a/src/Gui/DlgSettingsColorGradientImp.cpp b/src/Gui/DlgSettingsColorGradientImp.cpp
index a7d320f421..eeb31312ff 100644
--- a/src/Gui/DlgSettingsColorGradientImp.cpp
+++ b/src/Gui/DlgSettingsColorGradientImp.cpp
@@ -122,10 +122,10 @@ bool DlgSettingsColorGradientImp::isOutInvisible() const
void DlgSettingsColorGradientImp::setRange( float fMin, float fMax )
{
ui->floatLineEditMax->blockSignals(true);
- ui->floatLineEditMax->setText(QLocale().toString(fMax, 'f', numberOfDecimals()));
+ ui->floatLineEditMax->setText(QLocale().toString(fMax, 'g', numberOfDecimals()));
ui->floatLineEditMax->blockSignals(false);
ui->floatLineEditMin->blockSignals(true);
- ui->floatLineEditMin->setText(QLocale().toString(fMin, 'f', numberOfDecimals()));
+ ui->floatLineEditMin->setText(QLocale().toString(fMin, 'g', numberOfDecimals()));
ui->floatLineEditMin->blockSignals(false);
}
diff --git a/src/Gui/SoFCColorGradient.cpp b/src/Gui/SoFCColorGradient.cpp
index c0819cdf51..e851706884 100644
--- a/src/Gui/SoFCColorGradient.cpp
+++ b/src/Gui/SoFCColorGradient.cpp
@@ -175,25 +175,24 @@ void SoFCColorGradient::setViewportSize( const SbVec2s& size )
}
}
-void SoFCColorGradient::setRange( float fMin, float fMax, int prec )
+void SoFCColorGradient::setRange(float fMin, float fMax, int prec)
{
_cColGrad.setRange(fMin, fMax);
SoMFString label;
- float fFac = (float)pow(10.0, (double)prec);
+ float eps = std::pow(10.0f, static_cast(-prec));
+ float value = std::min(fabs(fMin), fabs(fMax));
+ std::ios::fmtflags flags = value < eps ? (std::ios::scientific | std::ios::showpoint | std::ios::showpos)
+ : (std::ios::fixed | std::ios::showpoint | std::ios::showpos);
int i=0;
std::vector marks = getMarkerValues(fMin, fMax, _cColGrad.getCountColors());
- for ( std::vector::iterator it = marks.begin(); it != marks.end(); ++it )
- {
+ for (const auto& it : marks) {
std::stringstream s;
s.precision(prec);
- s.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
- float fValue = *it;
- if ( fabs(fValue*fFac) < 1.0 )
- fValue = 0.0f;
- s << fValue;
+ s.setf(flags);
+ s << it;
label.set1Value(i++, s.str().c_str());
}