1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-24 15:26:15 +00:00

[Mono] Approximate equality

This commit is contained in:
Aaron Franke
2019-04-01 18:13:38 -04:00
parent 7f7d97f536
commit c577ec6ae4
7 changed files with 53 additions and 34 deletions

View File

@@ -143,6 +143,15 @@ namespace Godot
return (weight - from) / (to - from);
}
public static bool IsEqualApprox(real_t a, real_t b)
{
real_t tolerance = Epsilon * Abs(a);
if (tolerance < Epsilon) {
tolerance = Epsilon;
}
return Abs(a - b) < tolerance;
}
public static bool IsInf(real_t s)
{
return real_t.IsInfinity(s);
@@ -153,6 +162,11 @@ namespace Godot
return real_t.IsNaN(s);
}
public static bool IsZeroApprox(real_t s)
{
return Abs(s) < Epsilon;
}
public static real_t Lerp(real_t from, real_t to, real_t weight)
{
return from + (to - from) * weight;