improved GetHashCode override of all float and double based Vector/Matrix/Quaternion/Box types

This commit is contained in:
amulware 2016-03-16 08:11:13 +01:00
parent dc54e9bc02
commit e4c6f521e2
28 changed files with 184 additions and 35 deletions

View file

@ -12,7 +12,7 @@ namespace OpenTK
/// Defines a 2d box (rectangle).
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Box2
public struct Box2 : IEquatable<Box2>
{
/// <summary>
/// The left boundary of the structure.
@ -190,15 +190,22 @@ namespace OpenTK
return obj is Box2 && Equals((Box2) obj);
}
/// <summary>
/// Gets the hash code for this Box2.
/// </summary>
/// <returns></returns>
///// <summary>
///// Gets the hash code for this Box2.
///// </summary>
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;
/// <summary>
/// Returns a <see cref="System.String"/> describing the current instance.

View file

@ -12,8 +12,9 @@ namespace OpenTK
/// Defines a 2d box (rectangle).
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct Box2d
public struct Box2d : IEquatable<Box2d>
{
/// <summary>
/// The left boundary of the structure.
/// </summary>
@ -193,10 +194,16 @@ namespace OpenTK
/// <summary>
/// Gets the hash code for this Box2d.
/// </summary>
/// <returns></returns>
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;

View file

@ -721,7 +721,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode()
{
return Row0.GetHashCode() ^ Row1.GetHashCode();
unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
}
#endregion

View file

@ -721,7 +721,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode()
{
return Row0.GetHashCode() ^ Row1.GetHashCode();
unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
}
#endregion

View file

@ -679,7 +679,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode()
{
return Row0.GetHashCode() ^ Row1.GetHashCode();
unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
}
#endregion

View file

@ -679,7 +679,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode()
{
return Row0.GetHashCode() ^ Row1.GetHashCode();
unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
}
#endregion

View file

@ -716,7 +716,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode()
{
return Row0.GetHashCode() ^ Row1.GetHashCode();
unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
}
#endregion

View file

@ -716,7 +716,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode()
{
return Row0.GetHashCode() ^ Row1.GetHashCode();
unchecked
{
return (this.Row0.GetHashCode() * 397) ^ this.Row1.GetHashCode();
}
}
#endregion

View file

@ -960,7 +960,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -951,7 +951,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -690,7 +690,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -690,7 +690,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -954,7 +954,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -954,7 +954,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -1715,7 +1715,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -1665,7 +1665,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -739,7 +739,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -739,7 +739,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -962,7 +962,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -962,7 +962,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -857,7 +857,10 @@ namespace OpenTK
/// <returns>A hash code formed from the bitwise XOR of this objects members.</returns>
public override int GetHashCode()
{
return Xyz.GetHashCode() ^ W.GetHashCode();
unchecked
{
return (this.xyz.GetHashCode() * 397) ^ this.w.GetHashCode();
}
}
#endregion

View file

@ -854,9 +854,13 @@ namespace OpenTK
/// Provides the hash code for this object.
/// </summary>
/// <returns>A hash code formed from the bitwise XOR of this objects members.</returns>
public override int GetHashCode()
{
return Xyz.GetHashCode() ^ W.GetHashCode();
unchecked
{
return (this.xyz.GetHashCode() * 397) ^ this.w.GetHashCode();
}
}
#endregion

View file

@ -1137,7 +1137,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode();
unchecked
{
return (this.X.GetHashCode() * 397) ^ this.Y.GetHashCode();
}
}
#endregion

View file

@ -1015,7 +1015,10 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode();
unchecked
{
return (this.X.GetHashCode() * 397) ^ this.Y.GetHashCode();
}
}
#endregion

View file

@ -1629,7 +1629,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -1466,7 +1466,13 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -1657,7 +1657,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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

View file

@ -1613,7 +1613,14 @@ namespace OpenTK
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
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