1
0
mirror of https://github.com/godotengine/godot.git synced 2026-01-06 19:41:11 +00:00

Fix wrapf to correct wrap values with 0.1 stepping

This commit is contained in:
Yuri Rubinsky
2022-06-08 16:55:31 +03:00
parent c09d830106
commit 09418afbc0

View File

@@ -302,11 +302,19 @@ public:
}
static _ALWAYS_INLINE_ double wrapf(double value, double min, double max) {
double range = max - min;
return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
double result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
if (is_equal_approx(result, max)) {
return min;
}
return result;
}
static _ALWAYS_INLINE_ float wrapf(float value, float min, float max) {
float range = max - min;
return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
float result = is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
if (is_equal_approx(result, max)) {
return min;
}
return result;
}
static _ALWAYS_INLINE_ float fract(float value) {