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

@@ -52,11 +52,15 @@ namespace Godot
internal void Normalize()
{
real_t length = x * x + y * y;
real_t lengthsq = LengthSquared();
if (length != 0f)
if (lengthsq == 0)
{
length = Mathf.Sqrt(length);
x = y = 0f;
}
else
{
real_t length = Mathf.Sqrt(lengthsq);
x /= length;
y /= length;
}
@@ -184,9 +188,9 @@ namespace Godot
public Vector2 Normalized()
{
var result = this;
result.Normalize();
return result;
var v = this;
v.Normalize();
return v;
}
public Vector2 Project(Vector2 onNormal)
@@ -343,7 +347,7 @@ namespace Godot
public static bool operator <(Vector2 left, Vector2 right)
{
if (left.x.Equals(right.x))
if (Mathf.IsEqualApprox(left.x, right.x))
{
return left.y < right.y;
}
@@ -353,7 +357,7 @@ namespace Godot
public static bool operator >(Vector2 left, Vector2 right)
{
if (left.x.Equals(right.x))
if (Mathf.IsEqualApprox(left.x, right.x))
{
return left.y > right.y;
}
@@ -363,7 +367,7 @@ namespace Godot
public static bool operator <=(Vector2 left, Vector2 right)
{
if (left.x.Equals(right.x))
if (Mathf.IsEqualApprox(left.x, right.x))
{
return left.y <= right.y;
}
@@ -373,7 +377,7 @@ namespace Godot
public static bool operator >=(Vector2 left, Vector2 right)
{
if (left.x.Equals(right.x))
if (Mathf.IsEqualApprox(left.x, right.x))
{
return left.y >= right.y;
}
@@ -393,7 +397,7 @@ namespace Godot
public bool Equals(Vector2 other)
{
return x == other.x && y == other.y;
return Mathf.IsEqualApprox(x, other.x) && Mathf.IsEqualApprox(y, other.y);
}
public override int GetHashCode()