diff --git a/Source/OpenTK/Math/Box2.cs b/Source/OpenTK/Math/Box2.cs index 418a7c7a..bdb6ca5e 100644 --- a/Source/OpenTK/Math/Box2.cs +++ b/Source/OpenTK/Math/Box2.cs @@ -12,7 +12,7 @@ namespace OpenTK /// Defines a 2d box (rectangle). /// [StructLayout(LayoutKind.Sequential)] - public struct Box2 + public struct Box2 : IEquatable { /// /// The left boundary of the structure. @@ -190,15 +190,22 @@ namespace OpenTK return obj is Box2 && Equals((Box2) obj); } - /// - /// Gets the hash code for this Box2. - /// - /// + ///// + ///// Gets the hash code for this Box2. + ///// public override int GetHashCode() { - return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); + unchecked + { + var hashCode = this.Left.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Right.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Top.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Bottom.GetHashCode(); + return hashCode; + } } + private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; /// /// Returns a describing the current instance. diff --git a/Source/OpenTK/Math/Box2d.cs b/Source/OpenTK/Math/Box2d.cs index 78fe467c..d2de82ff 100644 --- a/Source/OpenTK/Math/Box2d.cs +++ b/Source/OpenTK/Math/Box2d.cs @@ -12,8 +12,9 @@ namespace OpenTK /// Defines a 2d box (rectangle). /// [StructLayout(LayoutKind.Sequential)] - public struct Box2d + public struct Box2d : IEquatable { + /// /// The left boundary of the structure. /// @@ -193,10 +194,16 @@ namespace OpenTK /// /// Gets the hash code for this Box2d. /// - /// public override int GetHashCode() { - return Left.GetHashCode() ^ Right.GetHashCode() ^ Top.GetHashCode() ^ Bottom.GetHashCode(); + unchecked + { + var hashCode = this.Left.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Right.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Top.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Bottom.GetHashCode(); + return hashCode; + } } private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; diff --git a/Source/OpenTK/Math/Matrix2.cs b/Source/OpenTK/Math/Matrix2.cs index 0a0cb382..51856069 100644 --- a/Source/OpenTK/Math/Matrix2.cs +++ b/Source/OpenTK/Math/Matrix2.cs @@ -721,7 +721,10 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode(); + unchecked + { + return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Matrix2d.cs b/Source/OpenTK/Math/Matrix2d.cs index 999f105e..01fbcb2f 100644 --- a/Source/OpenTK/Math/Matrix2d.cs +++ b/Source/OpenTK/Math/Matrix2d.cs @@ -721,7 +721,10 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode(); + unchecked + { + return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Matrix2x3.cs b/Source/OpenTK/Math/Matrix2x3.cs index bd2236ca..6b5f5eae 100644 --- a/Source/OpenTK/Math/Matrix2x3.cs +++ b/Source/OpenTK/Math/Matrix2x3.cs @@ -679,7 +679,10 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode(); + unchecked + { + return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Matrix2x3d.cs b/Source/OpenTK/Math/Matrix2x3d.cs index 30a59eb5..994c75d7 100644 --- a/Source/OpenTK/Math/Matrix2x3d.cs +++ b/Source/OpenTK/Math/Matrix2x3d.cs @@ -679,7 +679,10 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode(); + unchecked + { + return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Matrix2x4.cs b/Source/OpenTK/Math/Matrix2x4.cs index c3afecdb..303f95fe 100644 --- a/Source/OpenTK/Math/Matrix2x4.cs +++ b/Source/OpenTK/Math/Matrix2x4.cs @@ -716,7 +716,10 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode(); + unchecked + { + return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Matrix2x4d.cs b/Source/OpenTK/Math/Matrix2x4d.cs index deb2b1cb..e01ed5a0 100644 --- a/Source/OpenTK/Math/Matrix2x4d.cs +++ b/Source/OpenTK/Math/Matrix2x4d.cs @@ -716,7 +716,10 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode(); + unchecked + { + return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Matrix3.cs b/Source/OpenTK/Math/Matrix3.cs index 9d720c8c..954eb55c 100644 --- a/Source/OpenTK/Math/Matrix3.cs +++ b/Source/OpenTK/Math/Matrix3.cs @@ -960,7 +960,13 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix3d.cs b/Source/OpenTK/Math/Matrix3d.cs index ca270b8a..5c3c1da4 100644 --- a/Source/OpenTK/Math/Matrix3d.cs +++ b/Source/OpenTK/Math/Matrix3d.cs @@ -951,7 +951,13 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix3x2.cs b/Source/OpenTK/Math/Matrix3x2.cs index 639f093a..dd7b7aad 100644 --- a/Source/OpenTK/Math/Matrix3x2.cs +++ b/Source/OpenTK/Math/Matrix3x2.cs @@ -690,7 +690,13 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix3x2d.cs b/Source/OpenTK/Math/Matrix3x2d.cs index 8f1804e9..d977471a 100644 --- a/Source/OpenTK/Math/Matrix3x2d.cs +++ b/Source/OpenTK/Math/Matrix3x2d.cs @@ -690,7 +690,13 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix3x4.cs b/Source/OpenTK/Math/Matrix3x4.cs index 7d251d57..d9c843c8 100644 --- a/Source/OpenTK/Math/Matrix3x4.cs +++ b/Source/OpenTK/Math/Matrix3x4.cs @@ -954,7 +954,13 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix3x4d.cs b/Source/OpenTK/Math/Matrix3x4d.cs index fa37cfc8..44beb2c3 100644 --- a/Source/OpenTK/Math/Matrix3x4d.cs +++ b/Source/OpenTK/Math/Matrix3x4d.cs @@ -954,7 +954,13 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix4.cs b/Source/OpenTK/Math/Matrix4.cs index 945f367d..d62598c0 100644 --- a/Source/OpenTK/Math/Matrix4.cs +++ b/Source/OpenTK/Math/Matrix4.cs @@ -1715,7 +1715,14 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row3.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix4d.cs b/Source/OpenTK/Math/Matrix4d.cs index 8a2a2137..db194b3f 100644 --- a/Source/OpenTK/Math/Matrix4d.cs +++ b/Source/OpenTK/Math/Matrix4d.cs @@ -1665,7 +1665,14 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row3.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix4x2.cs b/Source/OpenTK/Math/Matrix4x2.cs index d548efda..bd618803 100644 --- a/Source/OpenTK/Math/Matrix4x2.cs +++ b/Source/OpenTK/Math/Matrix4x2.cs @@ -739,7 +739,14 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row3.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix4x2d.cs b/Source/OpenTK/Math/Matrix4x2d.cs index bf494a19..638294b4 100644 --- a/Source/OpenTK/Math/Matrix4x2d.cs +++ b/Source/OpenTK/Math/Matrix4x2d.cs @@ -739,7 +739,14 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode() ^ Row3.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row3.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix4x3.cs b/Source/OpenTK/Math/Matrix4x3.cs index e7fd6788..792cedaa 100644 --- a/Source/OpenTK/Math/Matrix4x3.cs +++ b/Source/OpenTK/Math/Matrix4x3.cs @@ -962,7 +962,14 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row3.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Matrix4x3d.cs b/Source/OpenTK/Math/Matrix4x3d.cs index 908477fd..c74d901b 100644 --- a/Source/OpenTK/Math/Matrix4x3d.cs +++ b/Source/OpenTK/Math/Matrix4x3d.cs @@ -962,7 +962,14 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return Row0.GetHashCode() ^ Row1.GetHashCode() ^ Row2.GetHashCode(); + unchecked + { + var hashCode = this.Row0.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row1.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row2.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Row3.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Quaternion.cs b/Source/OpenTK/Math/Quaternion.cs index 8d6b8379..9f6f724a 100644 --- a/Source/OpenTK/Math/Quaternion.cs +++ b/Source/OpenTK/Math/Quaternion.cs @@ -857,7 +857,10 @@ namespace OpenTK /// A hash code formed from the bitwise XOR of this objects members. public override int GetHashCode() { - return Xyz.GetHashCode() ^ W.GetHashCode(); + unchecked + { + return (this.xyz.GetHashCode() * 397) ^ this.w.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Quaterniond.cs b/Source/OpenTK/Math/Quaterniond.cs index be553a24..de3160d2 100644 --- a/Source/OpenTK/Math/Quaterniond.cs +++ b/Source/OpenTK/Math/Quaterniond.cs @@ -854,9 +854,13 @@ namespace OpenTK /// Provides the hash code for this object. /// /// A hash code formed from the bitwise XOR of this objects members. + public override int GetHashCode() { - return Xyz.GetHashCode() ^ W.GetHashCode(); + unchecked + { + return (this.xyz.GetHashCode() * 397) ^ this.w.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Vector2.cs b/Source/OpenTK/Math/Vector2.cs index 4d1064a6..d7f81427 100644 --- a/Source/OpenTK/Math/Vector2.cs +++ b/Source/OpenTK/Math/Vector2.cs @@ -1137,7 +1137,10 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return X.GetHashCode() ^ Y.GetHashCode(); + unchecked + { + return (this.X.GetHashCode() * 397) ^ this.Y.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Vector2d.cs b/Source/OpenTK/Math/Vector2d.cs index 8c3846cf..3993aafa 100644 --- a/Source/OpenTK/Math/Vector2d.cs +++ b/Source/OpenTK/Math/Vector2d.cs @@ -1015,7 +1015,10 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return X.GetHashCode() ^ Y.GetHashCode(); + unchecked + { + return (this.X.GetHashCode() * 397) ^ this.Y.GetHashCode(); + } } #endregion diff --git a/Source/OpenTK/Math/Vector3.cs b/Source/OpenTK/Math/Vector3.cs index fa79e392..158767b6 100644 --- a/Source/OpenTK/Math/Vector3.cs +++ b/Source/OpenTK/Math/Vector3.cs @@ -1629,7 +1629,13 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); + unchecked + { + var hashCode = this.X.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Y.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Z.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Vector3d.cs b/Source/OpenTK/Math/Vector3d.cs index fa3dd95b..556b9ab9 100644 --- a/Source/OpenTK/Math/Vector3d.cs +++ b/Source/OpenTK/Math/Vector3d.cs @@ -1466,7 +1466,13 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); + unchecked + { + var hashCode = this.X.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Y.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Z.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Vector4.cs b/Source/OpenTK/Math/Vector4.cs index 4b9fdd0e..a821031e 100644 --- a/Source/OpenTK/Math/Vector4.cs +++ b/Source/OpenTK/Math/Vector4.cs @@ -1657,7 +1657,14 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode(); + unchecked + { + var hashCode = this.X.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Y.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Z.GetHashCode(); + hashCode = (hashCode * 397) ^ this.W.GetHashCode(); + return hashCode; + } } #endregion diff --git a/Source/OpenTK/Math/Vector4d.cs b/Source/OpenTK/Math/Vector4d.cs index b158005e..facc329d 100644 --- a/Source/OpenTK/Math/Vector4d.cs +++ b/Source/OpenTK/Math/Vector4d.cs @@ -1613,7 +1613,14 @@ namespace OpenTK /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { - return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode(); + unchecked + { + var hashCode = this.X.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Y.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Z.GetHashCode(); + hashCode = (hashCode * 397) ^ this.W.GetHashCode(); + return hashCode; + } } #endregion