Merge pull request #45220 from Calinou/range-ratio-equal-min-max-no-error

Make Range return 1.0 ratio if minimum and maximum values are equal
This commit is contained in:
Rémi Verschelde 2021-01-26 15:24:58 +01:00 committed by GitHub
commit b84729f848
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -171,7 +171,10 @@ void Range::set_as_ratio(double p_value) {
}
double Range::get_as_ratio() const {
ERR_FAIL_COND_V_MSG(Math::is_equal_approx(get_max(), get_min()), 0.0, "Cannot get ratio when minimum and maximum value are equal.");
if (Math::is_equal_approx(get_max(), get_min())) {
// Avoid division by zero.
return 1.0;
}
if (shared->exp_ratio && get_min() >= 0) {
double exp_min = get_min() == 0 ? 0.0 : Math::log(get_min()) / Math::log((double)2);