You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Update wrap functions
This commit is contained in:
@@ -177,18 +177,3 @@ float Math::random(float from, float to) {
|
|||||||
float ret = (float)r / (float)RANDOM_MAX;
|
float ret = (float)r / (float)RANDOM_MAX;
|
||||||
return (ret) * (to - from) + from;
|
return (ret) * (to - from) + from;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Math::wrapi(int value, int min, int max) {
|
|
||||||
--max;
|
|
||||||
int rng = max - min + 1;
|
|
||||||
value = ((value - min) % rng);
|
|
||||||
if (value < 0)
|
|
||||||
return max + 1 + value;
|
|
||||||
else
|
|
||||||
return min + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Math::wrapf(float value, float min, float max) {
|
|
||||||
float rng = max - min;
|
|
||||||
return min + (value - min) - (rng * floor((value - min) / rng));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -209,8 +209,18 @@ public:
|
|||||||
static _ALWAYS_INLINE_ double round(double p_val) { return (p_val >= 0) ? Math::floor(p_val + 0.5) : -Math::floor(-p_val + 0.5); }
|
static _ALWAYS_INLINE_ double round(double p_val) { return (p_val >= 0) ? Math::floor(p_val + 0.5) : -Math::floor(-p_val + 0.5); }
|
||||||
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_ float round(float p_val) { return (p_val >= 0) ? Math::floor(p_val + 0.5) : -Math::floor(-p_val + 0.5); }
|
||||||
|
|
||||||
static int wrapi(int value, int min, int max);
|
static _ALWAYS_INLINE_ int wrapi(int value, int min, int max) {
|
||||||
static float wrapf(float value, float min, float max);
|
int rng = max - min;
|
||||||
|
return min + ((((value - min) % rng) + rng) % rng);
|
||||||
|
}
|
||||||
|
static _ALWAYS_INLINE_ double wrapf(double value, double min, double max) {
|
||||||
|
double rng = max - min;
|
||||||
|
return min + (value - min) - (rng * Math::floor((value - min) / rng));
|
||||||
|
}
|
||||||
|
static _ALWAYS_INLINE_ float wrapf(float value, float min, float max) {
|
||||||
|
float rng = max - min;
|
||||||
|
return min + (value - min) - (rng * Math::floor((value - min) / rng));
|
||||||
|
}
|
||||||
|
|
||||||
// double only, as these functions are mainly used by the editor and not performance-critical,
|
// 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 double ease(double p_x, double p_c);
|
||||||
|
|||||||
Reference in New Issue
Block a user