diff --git a/src/DotRecast.Core/RcHashCodes.cs b/src/DotRecast.Core/RcHashCodes.cs new file mode 100644 index 0000000..d94f6cf --- /dev/null +++ b/src/DotRecast.Core/RcHashCodes.cs @@ -0,0 +1,10 @@ +namespace DotRecast.Core +{ + public static class RcHashCodes + { + public static int CombineHashCodes(int h1, int h2) + { + return (((h1 << 5) + h1) ^ h2); + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Core/Vector2f.cs b/src/DotRecast.Core/Vector2f.cs index 71e4627..5c59be2 100644 --- a/src/DotRecast.Core/Vector2f.cs +++ b/src/DotRecast.Core/Vector2f.cs @@ -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); + } } } \ No newline at end of file diff --git a/src/DotRecast.Core/Vector3f.cs b/src/DotRecast.Core/Vector3f.cs index cca73ff..11e760e 100644 --- a/src/DotRecast.Core/Vector3f.cs +++ b/src/DotRecast.Core/Vector3f.cs @@ -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); } } -} +} \ No newline at end of file