You've already forked godot
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user