1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-18 14:21:41 +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

@@ -65,14 +65,15 @@ namespace Godot
internal void Normalize()
{
real_t length = Length();
real_t lengthsq = LengthSquared();
if (length == 0f)
if (lengthsq == 0)
{
x = y = z = 0f;
}
else
{
real_t length = Mathf.Sqrt(lengthsq);
x /= length;
y /= length;
z /= length;
@@ -397,9 +398,9 @@ namespace Godot
public static bool operator <(Vector3 left, Vector3 right)
{
if (left.x == right.x)
if (Mathf.IsEqualApprox(left.x, right.x))
{
if (left.y == right.y)
if (Mathf.IsEqualApprox(left.y, right.y))
return left.z < right.z;
return left.y < right.y;
}
@@ -409,9 +410,9 @@ namespace Godot
public static bool operator >(Vector3 left, Vector3 right)
{
if (left.x == right.x)
if (Mathf.IsEqualApprox(left.x, right.x))
{
if (left.y == right.y)
if (Mathf.IsEqualApprox(left.y, right.y))
return left.z > right.z;
return left.y > right.y;
}
@@ -421,9 +422,9 @@ namespace Godot
public static bool operator <=(Vector3 left, Vector3 right)
{
if (left.x == right.x)
if (Mathf.IsEqualApprox(left.x, right.x))
{
if (left.y == right.y)
if (Mathf.IsEqualApprox(left.y, right.y))
return left.z <= right.z;
return left.y < right.y;
}
@@ -433,9 +434,9 @@ namespace Godot
public static bool operator >=(Vector3 left, Vector3 right)
{
if (left.x == right.x)
if (Mathf.IsEqualApprox(left.x, right.x))
{
if (left.y == right.y)
if (Mathf.IsEqualApprox(left.y, right.y))
return left.z >= right.z;
return left.y > right.y;
}
@@ -455,7 +456,7 @@ namespace Godot
public bool Equals(Vector3 other)
{
return x == other.x && y == other.y && z == other.z;
return Mathf.IsEqualApprox(x, other.x) && Mathf.IsEqualApprox(y, other.y) && Mathf.IsEqualApprox(z, other.z);
}
public override int GetHashCode()