Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Range return 1.0 ratio if minimum and maximum values are equal #45220

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scene/gui/range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down