1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-13 13:31:48 +00:00

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

An error message is also no longer printed.
This matches the behavior found in most UI frameworks where having
equal minimum and maximum values is considered acceptable.

This closes #43179.

(cherry picked from commit 44204ec32d)
This commit is contained in:
Hugo Locurcio
2021-01-15 23:13:08 +01:00
committed by Rémi Verschelde
parent 0e45fb9798
commit 76bd7d796b

View File

@@ -170,8 +170,10 @@ void Range::set_as_ratio(double p_value) {
set_value(v); set_value(v);
} }
double Range::get_as_ratio() const { double Range::get_as_ratio() const {
if (Math::is_equal_approx(get_max(), get_min())) {
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."); // Avoid division by zero.
return 1.0;
}
if (shared->exp_ratio && get_min() >= 0) { if (shared->exp_ratio && get_min() >= 0) {