summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2019-07-23 17:27:55 +0200
committerRémi Verschelde <rverschelde@gmail.com>2019-07-23 17:31:38 +0200
commitd844e306147689c3f02473b3dd5d592bdf141023 (patch)
tree1124a98e2d55dfe351b490b7839bc96de811457e /core/math
parent4c943cca2c6d6cd7a197cb1601a6356e65254837 (diff)
Inspector: Make default float step configurable
Also allow lifting the decimal step formatting with a hint range step of 0. A new `range_step_decimals()` is added for this to avoid breaking compatibility on the general purpose `step_decimals()` (which still returns 0 for an input step of 0). Supersedes #25470. Partial fix for #18251.
Diffstat (limited to 'core/math')
-rw-r--r--core/math/math_funcs.cpp9
-rw-r--r--core/math/math_funcs.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 7a2e74a413..f04e40cb6c 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -79,6 +79,15 @@ int Math::step_decimals(double p_step) {
return 0;
}
+// Only meant for editor usage in float ranges, where a step of 0
+// means that decimal digits should not be limited in String::num.
+int Math::range_step_decimals(double p_step) {
+ if (p_step < 0.0000000000001) {
+ return 16; // Max value hardcoded in String::num
+ }
+ return step_decimals(p_step);
+}
+
double Math::dectime(double p_value, double p_amount, double p_step) {
double sgn = p_value < 0 ? -1.0 : 1.0;
double val = Math::abs(p_value);
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index b8b5151802..a712356ddc 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -270,6 +270,7 @@ public:
// double only, as these functions are mainly used by the editor and not performance-critical,
static double ease(double p_x, double p_c);
static int step_decimals(double p_step);
+ static int range_step_decimals(double p_step);
static double stepify(double p_value, double p_step);
static double dectime(double p_value, double p_amount, double p_step);