Skip to content

Commit 7b5406d

Browse files
committed
Change: Add GetHashCode and Equals overrides to Vector3
[ci skip]
1 parent d91d666 commit 7b5406d

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

source/OpenBveApi/Vector3.cs

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#pragma warning disable 0660, 0661
2-
3-
using System;
1+
using System;
42

53
namespace OpenBveApi.Math {
64
/// <summary>Represents a three-dimensional vector.</summary>
@@ -185,7 +183,33 @@ public static Vector3 LinearInterpolate(Vector3 Vector1, Vector3 Vector2, double
185183
if (a.Z != b.Z) return false;
186184
return true;
187185
}
188-
186+
187+
/// <summary>Returns the hashcode for this instance.</summary>
188+
/// <returns>An integer representing the unique hashcode for this instance.</returns>
189+
public override int GetHashCode()
190+
{
191+
unchecked
192+
{
193+
var hashCode = this.X.GetHashCode();
194+
hashCode = (hashCode * 397) ^ this.Y.GetHashCode();
195+
hashCode = (hashCode * 397) ^ this.Z.GetHashCode();
196+
return hashCode;
197+
}
198+
}
199+
200+
/// <summary>Indicates whether this instance and a specified object are equal.</summary>
201+
/// <param name="obj">The object to compare to.</param>
202+
/// <returns>True if the instances are equal; false otherwise.</returns>
203+
public override bool Equals(object obj)
204+
{
205+
if (!(obj is Vector3))
206+
{
207+
return false;
208+
}
209+
210+
return this.Equals((Vector3)obj);
211+
}
212+
189213
/// <summary>Checks whether the two specified vectors are unequal.</summary>
190214
/// <param name="a">The first vector.</param>
191215
/// <param name="b">The second vector.</param>

0 commit comments

Comments
 (0)