Avoid non-supported ranges for exponential slider (#1672)

* Warn if setExponent is called with an invalid minmax range

* Disable bounding and interaction sphere exponent, to suppress warning
This commit is contained in:
Emma Broman
2021-07-02 08:11:37 +02:00
committed by GitHub
parent 87da9a27ab
commit 1912f8f08b
2 changed files with 39 additions and 4 deletions
@@ -23,9 +23,11 @@
****************************************************************************************/
#include <openspace/util/json_helper.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/lua/ghoul_lua.h>
#include <glm/ext/matrix_common.hpp>
#include <cmath>
#include <type_traits>
namespace openspace::properties {
@@ -90,6 +92,35 @@ float NumericalProperty<T>::exponent() const {
template <typename T>
void NumericalProperty<T>::setExponent(float exponent) {
ghoul_assert(std::abs(exponent) > 0.f, "Exponent for property input cannot be zero");
auto isValidRange = [](const T& minValue, const T& maxValue) {
if constexpr (ghoul::isGlmVector<T>() || ghoul::isGlmMatrix<T>()) {
return glm::all(glm::greaterThanEqual(minValue, T(0))) &&
glm::all(glm::greaterThanEqual(maxValue, T(0)));
}
else {
return (minValue >= T(0) && maxValue >= T(0));
}
};
// While the exponential slider does not support ranges with negative values,
// prevent setting the exponent for such ranges
// @ TODO (2021-06-30, emmbr), remove this check when no longer needed
if (!std::is_unsigned<T>::value) {
if (!isValidRange(_minimumValue, _maximumValue)) {
LWARNINGC(
"NumericalProperty: setExponent",
fmt::format(
"Setting exponent for properties with negative values in "
"[min, max] range is not yet supported. Property: {}",
this->fullyQualifiedIdentifier()
)
);
_exponent = 1.f;
return;
}
}
_exponent = exponent;
}