summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-08-05 09:55:57 +0200
committerGitHub <noreply@github.com>2019-08-05 09:55:57 +0200
commit45be9c67ef4367b551e6c62b3f5fd246db41e825 (patch)
treee3a864364e9124fdcce24582c72d64eb0bdd7afa
parent7c3805019d1100e5da831e492d4a6c7e1960501f (diff)
parenta9c10450bd79e862ac1d35576cba30a8425d7e0b (diff)
Merge pull request #31091 from aaronfranke/wrap
Optimize Wrap functions
-rw-r--r--core/math/math_funcs.h12
-rw-r--r--modules/mono/glue/Managed/Files/Mathf.cs8
2 files changed, 10 insertions, 10 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index a712356ddc..af845ca01e 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -255,16 +255,16 @@ public:
static _ALWAYS_INLINE_ float round(float p_val) { return (p_val >= 0) ? Math::floor(p_val + 0.5) : -Math::floor(-p_val + 0.5); }
static _ALWAYS_INLINE_ int64_t wrapi(int64_t value, int64_t min, int64_t max) {
- int64_t rng = max - min;
- return (rng != 0) ? min + ((((value - min) % rng) + rng) % rng) : min;
+ int64_t range = max - min;
+ return range == 0 ? min : min + ((((value - min) % range) + range) % range);
}
static _ALWAYS_INLINE_ double wrapf(double value, double min, double max) {
- double rng = max - min;
- return (!is_equal_approx(rng, 0.0)) ? value - (rng * Math::floor((value - min) / rng)) : min;
+ double range = max - min;
+ return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
}
static _ALWAYS_INLINE_ float wrapf(float value, float min, float max) {
- float rng = max - min;
- return (!is_equal_approx(rng, 0.0f)) ? value - (rng * Math::floor((value - min) / rng)) : min;
+ float range = max - min;
+ return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
}
// double only, as these functions are mainly used by the editor and not performance-critical,
diff --git a/modules/mono/glue/Managed/Files/Mathf.cs b/modules/mono/glue/Managed/Files/Mathf.cs
index 6c1a51fcf9..15adf0a13b 100644
--- a/modules/mono/glue/Managed/Files/Mathf.cs
+++ b/modules/mono/glue/Managed/Files/Mathf.cs
@@ -336,14 +336,14 @@ namespace Godot
public static int Wrap(int value, int min, int max)
{
- int rng = max - min;
- return rng != 0 ? min + ((value - min) % rng + rng) % rng : min;
+ int range = max - min;
+ return range == 0 ? min : min + ((value - min) % range + range) % range;
}
public static real_t Wrap(real_t value, real_t min, real_t max)
{
- real_t rng = max - min;
- return !IsEqualApprox(rng, default(real_t)) ? min + ((value - min) % rng + rng) % rng : min;
+ real_t range = max - min;
+ return IsZeroApprox(range) ? min : min + ((value - min) % range + range) % range;
}
}
}