forked from bit/DotRecastNetSim
implement Vector3f, Vector2f Equals, GetHashCode
This commit is contained in:
parent
208c1a9e76
commit
7677add89e
|
@ -0,0 +1,10 @@
|
|||
namespace DotRecast.Core
|
||||
{
|
||||
public static class RcHashCodes
|
||||
{
|
||||
public static int CombineHashCodes(int h1, int h2)
|
||||
{
|
||||
return (((h1 << 5) + h1) ^ h2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,5 +19,36 @@ namespace DotRecast.Core
|
|||
|
||||
throw new IndexOutOfRangeException("vector2f index out of range");
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Vector2f))
|
||||
return false;
|
||||
|
||||
return Equals((Vector2f)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Vector2f other)
|
||||
{
|
||||
return x.Equals(other.x) &&
|
||||
y.Equals(other.y);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = x.GetHashCode();
|
||||
hash = RcHashCodes.CombineHashCodes(hash, y.GetHashCode());
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static bool operator ==(Vector2f left, Vector2f right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector2f left, Vector2f right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -88,11 +88,33 @@ namespace DotRecast.Core
|
|||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Vector3f))
|
||||
return false;
|
||||
|
||||
return Equals((Vector3f)obj);
|
||||
}
|
||||
|
||||
public bool Equals(Vector3f other)
|
||||
{
|
||||
return x.Equals(other.x) &&
|
||||
y.Equals(other.y) &&
|
||||
z.Equals(other.z);
|
||||
}
|
||||
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hash = x.GetHashCode();
|
||||
hash = RcHashCodes.CombineHashCodes(hash, y.GetHashCode());
|
||||
hash = RcHashCodes.CombineHashCodes(hash, z.GetHashCode());
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static bool operator ==(Vector3f left, Vector3f right)
|
||||
{
|
||||
return left.x.Equals(right.x)
|
||||
&& left.y.Equals(right.y)
|
||||
&& left.z.Equals(right.z);
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector3f left, Vector3f right)
|
||||
|
@ -100,4 +122,4 @@ namespace DotRecast.Core
|
|||
return !left.Equals(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue