Merge pull request #26761 from Chaosus/fix_mono_wrap
Fix division by zero at wrap functions in mono
This commit is contained in:
commit
47407ba2df
2 changed files with 7 additions and 2 deletions
|
@ -289,13 +289,13 @@ namespace Godot
|
|||
public static int Wrap(int value, int min, int max)
|
||||
{
|
||||
int rng = max - min;
|
||||
return min + ((value - min) % rng + rng) % rng;
|
||||
return rng != 0 ? min + ((value - min) % rng + rng) % rng : min;
|
||||
}
|
||||
|
||||
public static real_t Wrap(real_t value, real_t min, real_t max)
|
||||
{
|
||||
real_t rng = max - min;
|
||||
return min + ((value - min) % rng + rng) % rng;
|
||||
return !IsEqualApprox(rng, default(real_t)) ? min + ((value - min) % rng + rng) % rng : min;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,5 +35,10 @@ namespace Godot
|
|||
{
|
||||
return (int)Math.Round(s);
|
||||
}
|
||||
|
||||
public static bool IsEqualApprox(real_t a, real_t b, real_t ratio = Mathf.Epsilon)
|
||||
{
|
||||
return Abs(a - b) < ratio;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue