Skip to content

Commit 5ceb1b1

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

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

source/OpenBveApi/Vector3.cs

Lines changed: 32 additions & 4 deletions
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,37 @@ 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>
188+
/// Returns the hashcode for this instance.
189+
/// </summary>
190+
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
191+
public override int GetHashCode()
192+
{
193+
unchecked
194+
{
195+
var hashCode = this.X.GetHashCode();
196+
hashCode = (hashCode * 397) ^ this.Y.GetHashCode();
197+
hashCode = (hashCode * 397) ^ this.Z.GetHashCode();
198+
return hashCode;
199+
}
200+
}
201+
202+
/// <summary>
203+
/// Indicates whether this instance and a specified object are equal.
204+
/// </summary>
205+
/// <param name="obj">The object to compare to.</param>
206+
/// <returns>True if the instances are equal; false otherwise.</returns>
207+
public override bool Equals(object obj)
208+
{
209+
if (!(obj is Vector3))
210+
{
211+
return false;
212+
}
213+
214+
return this.Equals((Vector3)obj);
215+
}
216+
189217
/// <summary>Checks whether the two specified vectors are unequal.</summary>
190218
/// <param name="a">The first vector.</param>
191219
/// <param name="b">The second vector.</param>

0 commit comments

Comments
 (0)