From b20f461a052c8e3a3f47cbd930a09d908a3e0eae Mon Sep 17 00:00:00 2001 From: CodeInChaos Date: Wed, 22 Jun 2011 14:02:28 +0200 Subject: [PATCH 1/2] Fixed definite assignment problem on out parameters in VS2010 --- Mono.GameMath/Quaternion.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Mono.GameMath/Quaternion.cs b/Mono.GameMath/Quaternion.cs index 2bc3f1a..f0858e7 100644 --- a/Mono.GameMath/Quaternion.cs +++ b/Mono.GameMath/Quaternion.cs @@ -163,6 +163,7 @@ public static void Add (ref Quaternion quaternion1, ref Quaternion quaternion2, #if SIMD result = new Quaternion (quaternion1.v4 + quaternion2.v4); #else + result = new Quaternion(); result.X = quaternion1.X + quaternion2.X; result.Y = quaternion1.Y + quaternion2.Y; result.Z = quaternion1.Z + quaternion2.Z; @@ -185,6 +186,7 @@ public static void Subtract (ref Quaternion quaternion1, ref Quaternion quaterni #if SIMD result = new Quaternion (quaternion1.v4 - quaternion2.v4); #else + result = new Quaternion(); result.X = quaternion1.X - quaternion2.X; result.Y = quaternion1.Y - quaternion2.Y; result.Z = quaternion1.Z - quaternion2.Z; @@ -205,6 +207,7 @@ public static Quaternion Multiply (Quaternion quaternion1, Quaternion quaternion public static void Multiply (ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) { // TODO: SIMD optimization + result = new Quaternion(); result.X = quaternion1.W * quaternion2.X + quaternion1.X * quaternion2.W + quaternion1.Y * quaternion2.Z - quaternion1.Z * quaternion2.Y; result.Y = quaternion1.W * quaternion2.Y - quaternion1.X * quaternion2.Z + quaternion1.Y * quaternion2.W + quaternion1.Z * quaternion2.X; result.Z = quaternion1.W * quaternion2.Z + quaternion1.X * quaternion2.Y - quaternion1.Y * quaternion2.X + quaternion1.Z * quaternion2.W; @@ -385,7 +388,8 @@ public static Quaternion Conjugate (Quaternion value) public static void Conjugate (ref Quaternion value, out Quaternion result) { - result.X = - value.X; + result = new Quaternion(); + result.X = -value.X; result.Y = - value.Y; result.Z = - value.Z; result.W = value.W; From 7fa63d6c64eebe23f6a49dd6e777acf46b0415a7 Mon Sep 17 00:00:00 2001 From: CodeInChaos Date: Wed, 22 Jun 2011 18:14:33 +0200 Subject: [PATCH 2/2] Fixed equality problems in Vector2, Vector3, Vector4 and Quaternion and added unit tests --- .gitignore | 1 + GameMathTests/GameMathTests.csproj | 68 ++++++++++++++++++++++++ GameMathTests/Properties/AssemblyInfo.cs | 35 ++++++++++++ GameMathTests/QuaternionTests.cs | 63 ++++++++++++++++++++++ GameMathTests/Vector2Tests.cs | 47 ++++++++++++++++ GameMathTests/Vector3Tests.cs | 52 ++++++++++++++++++ GameMathTests/Vector4Tests.cs | 56 +++++++++++++++++++ Mono.GameMath.sln | 59 ++++++++++++++++---- Mono.GameMath/Quaternion.cs | 4 +- Mono.GameMath/Vector2.cs | 6 +-- Mono.GameMath/Vector3.cs | 6 +-- Mono.GameMath/Vector4.cs | 6 +-- 12 files changed, 382 insertions(+), 21 deletions(-) create mode 100644 GameMathTests/GameMathTests.csproj create mode 100644 GameMathTests/Properties/AssemblyInfo.cs create mode 100644 GameMathTests/QuaternionTests.cs create mode 100644 GameMathTests/Vector2Tests.cs create mode 100644 GameMathTests/Vector3Tests.cs create mode 100644 GameMathTests/Vector4Tests.cs diff --git a/.gitignore b/.gitignore index 09a34d1..7aae4c1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ obj *.pidb *.userprefs *.suo +TestResults/ \ No newline at end of file diff --git a/GameMathTests/GameMathTests.csproj b/GameMathTests/GameMathTests.csproj new file mode 100644 index 0000000..04d760f --- /dev/null +++ b/GameMathTests/GameMathTests.csproj @@ -0,0 +1,68 @@ + + + + Debug + AnyCPU + + + 2.0 + {8C447CE8-3234-4F00-A88F-555656FB231E} + Library + Properties + GameMathTests + GameMathTests + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + 3.5 + + + + + False + + + + + + + + + + + + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE} + Mono.GameMath + + + + + \ No newline at end of file diff --git a/GameMathTests/Properties/AssemblyInfo.cs b/GameMathTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4d589cf --- /dev/null +++ b/GameMathTests/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("GameMathTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("GameMathTests")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a35f57db-3249-42e7-a944-b5166b4392cf")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GameMathTests/QuaternionTests.cs b/GameMathTests/QuaternionTests.cs new file mode 100644 index 0000000..93ab361 --- /dev/null +++ b/GameMathTests/QuaternionTests.cs @@ -0,0 +1,63 @@ +using System; +using System.Text; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Mono.GameMath; + +namespace GameMathTests +{ + [TestClass] + public class QuaternionTests + { + public Quaternion Zero { get { return new Quaternion(); } } + public Quaternion UnitX { get { return new Quaternion(1, 0, 0, 0); } } + public Quaternion UnitY { get { return new Quaternion(0, 1, 0, 0); } } + public Quaternion UnitZ { get { return new Quaternion(0, 0, 1, 0); } } + public Quaternion UnitW { get { return new Quaternion(0, 0, 0, 1); } } + + + [TestMethod] + public void NaNEquality() + { + Quaternion nanQuat = new Quaternion(float.NaN, float.NaN, float.NaN, float.NaN); + Assert.IsFalse(nanQuat == nanQuat); + Assert.IsTrue(nanQuat != nanQuat); + Assert.IsTrue(nanQuat.Equals(nanQuat)); + } + + [TestMethod] + public void SimpleEquality() + { + Assert.IsTrue(Zero == Zero); + Assert.IsFalse(Zero != Zero); + + Assert.IsFalse(Zero == UnitX); + Assert.IsFalse(Zero == UnitY); + Assert.IsFalse(Zero == UnitZ); + Assert.IsFalse(Zero == UnitW); + + Assert.IsTrue(Zero.Equals(Zero)); + Assert.IsTrue(UnitX.Equals(UnitX)); + Assert.IsTrue(UnitY.Equals(UnitY)); + Assert.IsTrue(UnitZ.Equals(UnitZ)); + Assert.IsTrue(UnitW.Equals(UnitW)); + + Assert.IsFalse(Zero.Equals(UnitX)); + Assert.IsFalse(Zero.Equals(UnitY)); + Assert.IsFalse(Zero.Equals(UnitZ)); + Assert.IsFalse(Zero.Equals(UnitW)); + } + + [TestMethod] + public void GoodHashCode() + { + Assert.IsTrue(UnitX.GetHashCode() != UnitY.GetHashCode()); + + Assert.IsTrue(Zero.GetHashCode() != UnitX.GetHashCode()); + Assert.IsTrue(Zero.GetHashCode() != UnitY.GetHashCode()); + Assert.IsTrue(Zero.GetHashCode() != UnitZ.GetHashCode()); + Assert.IsTrue(Zero.GetHashCode() != UnitW.GetHashCode()); + } + } +} diff --git a/GameMathTests/Vector2Tests.cs b/GameMathTests/Vector2Tests.cs new file mode 100644 index 0000000..842a7be --- /dev/null +++ b/GameMathTests/Vector2Tests.cs @@ -0,0 +1,47 @@ +using System; +using System.Text; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Mono.GameMath; + +namespace GameMathTests +{ + [TestClass] + public class Vector2Tests + { + [TestMethod] + public void NaNEquality() + { + Vector2 nanVec = new Vector2(float.NaN, float.NaN); + Assert.IsFalse(nanVec == nanVec); + Assert.IsTrue(nanVec != nanVec); + Assert.IsTrue(nanVec.Equals(nanVec)); + } + + [TestMethod] + public void SimpleEquality() + { + Assert.IsTrue(Vector2.Zero == Vector2.Zero); + Assert.IsFalse(Vector2.Zero != Vector2.Zero); + + Assert.IsFalse(Vector2.Zero == Vector2.UnitX); + Assert.IsFalse(Vector2.Zero == Vector2.UnitY); + + Assert.IsTrue(Vector2.Zero.Equals(Vector2.Zero)); + Assert.IsTrue(Vector2.UnitX.Equals(Vector2.UnitX)); + Assert.IsTrue(Vector2.UnitY.Equals(Vector2.UnitY)); + + Assert.IsFalse(Vector2.Zero.Equals(Vector2.UnitX)); + Assert.IsFalse(Vector2.Zero.Equals(Vector2.UnitY)); + } + + [TestMethod] + public void GoodHashCode() + { + Assert.IsTrue(Vector2.UnitX.GetHashCode() != Vector2.UnitY.GetHashCode()); + Assert.IsTrue(Vector2.Zero.GetHashCode() != Vector2.UnitX.GetHashCode()); + Assert.IsTrue(Vector2.Zero.GetHashCode() != Vector2.UnitY.GetHashCode()); + } + } +} diff --git a/GameMathTests/Vector3Tests.cs b/GameMathTests/Vector3Tests.cs new file mode 100644 index 0000000..62dbff2 --- /dev/null +++ b/GameMathTests/Vector3Tests.cs @@ -0,0 +1,52 @@ +using System; +using System.Text; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Mono.GameMath; + +namespace GameMathTests +{ + [TestClass] + public class Vector3Tests + { + [TestMethod] + public void NaNEquality() + { + Vector3 nanVec = new Vector3(float.NaN, float.NaN, float.NaN); + Assert.IsFalse(nanVec == nanVec); + Assert.IsTrue(nanVec != nanVec); + Assert.IsTrue(nanVec.Equals(nanVec)); + } + + [TestMethod] + public void SimpleEquality() + { + Assert.IsTrue(Vector3.Zero == Vector3.Zero); + Assert.IsFalse(Vector3.Zero != Vector3.Zero); + + Assert.IsFalse(Vector3.Zero == Vector3.UnitX); + Assert.IsFalse(Vector3.Zero == Vector3.UnitY); + Assert.IsFalse(Vector3.Zero == Vector3.UnitZ); + + Assert.IsTrue(Vector3.Zero.Equals(Vector3.Zero)); + Assert.IsTrue(Vector3.UnitX.Equals(Vector3.UnitX)); + Assert.IsTrue(Vector3.UnitY.Equals(Vector3.UnitY)); + Assert.IsTrue(Vector3.UnitZ.Equals(Vector3.UnitZ)); + + Assert.IsFalse(Vector3.Zero.Equals(Vector3.UnitX)); + Assert.IsFalse(Vector3.Zero.Equals(Vector3.UnitY)); + Assert.IsFalse(Vector3.Zero.Equals(Vector3.UnitZ)); + } + + [TestMethod] + public void GoodHashCode() + { + Assert.IsTrue(Vector3.UnitX.GetHashCode() != Vector3.UnitY.GetHashCode()); + + Assert.IsTrue(Vector3.Zero.GetHashCode() != Vector3.UnitX.GetHashCode()); + Assert.IsTrue(Vector3.Zero.GetHashCode() != Vector3.UnitY.GetHashCode()); + Assert.IsTrue(Vector3.Zero.GetHashCode() != Vector3.UnitZ.GetHashCode()); + } + } +} diff --git a/GameMathTests/Vector4Tests.cs b/GameMathTests/Vector4Tests.cs new file mode 100644 index 0000000..0ca0ee9 --- /dev/null +++ b/GameMathTests/Vector4Tests.cs @@ -0,0 +1,56 @@ +using System; +using System.Text; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Mono.GameMath; + +namespace GameMathTests +{ + [TestClass] + public class Vector4Tests + { + [TestMethod] + public void NaNEquality() + { + Vector4 nanVec = new Vector4(float.NaN, float.NaN, float.NaN, float.NaN); + Assert.IsFalse(nanVec == nanVec); + Assert.IsTrue(nanVec != nanVec); + Assert.IsTrue(nanVec.Equals(nanVec)); + } + + [TestMethod] + public void SimpleEquality() + { + Assert.IsTrue(Vector4.Zero == Vector4.Zero); + Assert.IsFalse(Vector4.Zero != Vector4.Zero); + + Assert.IsFalse(Vector4.Zero == Vector4.UnitX); + Assert.IsFalse(Vector4.Zero == Vector4.UnitY); + Assert.IsFalse(Vector4.Zero == Vector4.UnitZ); + Assert.IsFalse(Vector4.Zero == Vector4.UnitW); + + Assert.IsTrue(Vector4.Zero.Equals(Vector4.Zero)); + Assert.IsTrue(Vector4.UnitX.Equals(Vector4.UnitX)); + Assert.IsTrue(Vector4.UnitY.Equals(Vector4.UnitY)); + Assert.IsTrue(Vector4.UnitZ.Equals(Vector4.UnitZ)); + Assert.IsTrue(Vector4.UnitW.Equals(Vector4.UnitW)); + + Assert.IsFalse(Vector4.Zero.Equals(Vector4.UnitX)); + Assert.IsFalse(Vector4.Zero.Equals(Vector4.UnitY)); + Assert.IsFalse(Vector4.Zero.Equals(Vector4.UnitZ)); + Assert.IsFalse(Vector4.Zero.Equals(Vector4.UnitW)); + } + + [TestMethod] + public void GoodHashCode() + { + Assert.IsTrue(Vector4.UnitX.GetHashCode() != Vector4.UnitY.GetHashCode()); + + Assert.IsTrue(Vector4.Zero.GetHashCode() != Vector4.UnitX.GetHashCode()); + Assert.IsTrue(Vector4.Zero.GetHashCode() != Vector4.UnitY.GetHashCode()); + Assert.IsTrue(Vector4.Zero.GetHashCode() != Vector4.UnitZ.GetHashCode()); + Assert.IsTrue(Vector4.Zero.GetHashCode() != Vector4.UnitW.GetHashCode()); + } + } +} diff --git a/Mono.GameMath.sln b/Mono.GameMath.sln index e63c7e4..0a4eb1b 100644 --- a/Mono.GameMath.sln +++ b/Mono.GameMath.sln @@ -5,15 +5,45 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.GameMath", "Mono.GameM EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "Benchmark\Benchmark.csproj", "{5A022A72-8858-4BCB-8380-7522C35E0006}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameMathTests", "GameMathTests\GameMathTests.csproj", "{8C447CE8-3234-4F00-A88F-555656FB231E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D2AFD0B7-D76C-40B0-8272-EF55E08E5855}" + ProjectSection(SolutionItems) = preProject + Local.testsettings = Local.testsettings + Mono.GameMath.vsmdi = Mono.GameMath.vsmdi + TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings + EndProjectSection +EndProject Global + GlobalSection(TestCaseManagementSettings) = postSolution + CategoryFile = Mono.GameMath.vsmdi + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU Safe|Any CPU = Safe|Any CPU - Unsafe|Any CPU = Unsafe|Any CPU + SafeX86|Any CPU = SafeX86|Any CPU Simd|Any CPU = Simd|Any CPU + Unsafe|Any CPU = Unsafe|Any CPU Xna|Any CPU = Xna|Any CPU - SafeX86|Any CPU = SafeX86|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Debug|Any CPU.ActiveCfg = Simd|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Debug|Any CPU.Build.0 = Simd|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Release|Any CPU.ActiveCfg = Simd|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Release|Any CPU.Build.0 = Simd|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Safe|Any CPU.ActiveCfg = Safe|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Safe|Any CPU.Build.0 = Safe|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.SafeX86|Any CPU.ActiveCfg = Safe|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Simd|Any CPU.ActiveCfg = Simd|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Simd|Any CPU.Build.0 = Simd|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Unsafe|Any CPU.ActiveCfg = Unsafe|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Unsafe|Any CPU.Build.0 = Unsafe|Any CPU + {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Xna|Any CPU.ActiveCfg = Safe|Any CPU + {5A022A72-8858-4BCB-8380-7522C35E0006}.Debug|Any CPU.ActiveCfg = SafeX86|Any CPU + {5A022A72-8858-4BCB-8380-7522C35E0006}.Debug|Any CPU.Build.0 = SafeX86|Any CPU + {5A022A72-8858-4BCB-8380-7522C35E0006}.Release|Any CPU.ActiveCfg = SafeX86|Any CPU + {5A022A72-8858-4BCB-8380-7522C35E0006}.Release|Any CPU.Build.0 = SafeX86|Any CPU {5A022A72-8858-4BCB-8380-7522C35E0006}.Safe|Any CPU.ActiveCfg = Safe|Any CPU {5A022A72-8858-4BCB-8380-7522C35E0006}.Safe|Any CPU.Build.0 = Safe|Any CPU {5A022A72-8858-4BCB-8380-7522C35E0006}.SafeX86|Any CPU.ActiveCfg = SafeX86|Any CPU @@ -24,14 +54,23 @@ Global {5A022A72-8858-4BCB-8380-7522C35E0006}.Unsafe|Any CPU.Build.0 = Unsafe|Any CPU {5A022A72-8858-4BCB-8380-7522C35E0006}.Xna|Any CPU.ActiveCfg = Xna|Any CPU {5A022A72-8858-4BCB-8380-7522C35E0006}.Xna|Any CPU.Build.0 = Xna|Any CPU - {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Safe|Any CPU.ActiveCfg = Safe|Any CPU - {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Safe|Any CPU.Build.0 = Safe|Any CPU - {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.SafeX86|Any CPU.ActiveCfg = Safe|Any CPU - {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Simd|Any CPU.ActiveCfg = Simd|Any CPU - {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Simd|Any CPU.Build.0 = Simd|Any CPU - {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Unsafe|Any CPU.ActiveCfg = Unsafe|Any CPU - {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Unsafe|Any CPU.Build.0 = Unsafe|Any CPU - {DAC0541A-CB1C-44CA-BE7C-BF6CD5A8A9EE}.Xna|Any CPU.ActiveCfg = Safe|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Release|Any CPU.Build.0 = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Safe|Any CPU.ActiveCfg = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Safe|Any CPU.Build.0 = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.SafeX86|Any CPU.ActiveCfg = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.SafeX86|Any CPU.Build.0 = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Simd|Any CPU.ActiveCfg = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Simd|Any CPU.Build.0 = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Unsafe|Any CPU.ActiveCfg = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Unsafe|Any CPU.Build.0 = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Xna|Any CPU.ActiveCfg = Release|Any CPU + {8C447CE8-3234-4F00-A88F-555656FB231E}.Xna|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution StartupItem = Benchmark\Benchmark.csproj diff --git a/Mono.GameMath/Quaternion.cs b/Mono.GameMath/Quaternion.cs index f0858e7..9046f5d 100644 --- a/Mono.GameMath/Quaternion.cs +++ b/Mono.GameMath/Quaternion.cs @@ -535,7 +535,7 @@ public static void Slerp (ref Quaternion quaternion1, ref Quaternion quaternion2 public bool Equals (Quaternion other) { - return other == this; + return x.Equals(other.x) && y.Equals(other.y) && z.Equals(other.z) && w.Equals(other.w); } public override bool Equals (object obj) @@ -545,7 +545,7 @@ public override bool Equals (object obj) public override int GetHashCode () { - return X.GetHashCode () ^ Y.GetHashCode () ^ Z.GetHashCode () ^ W.GetHashCode (); + return x.GetHashCode() * (31 * 31 * 31) + y.GetHashCode() * (31 * 31) + z.GetHashCode() * 31 + w.GetHashCode(); } public static bool operator == (Quaternion a, Quaternion b) diff --git a/Mono.GameMath/Vector2.cs b/Mono.GameMath/Vector2.cs index 83d7c55..5af245e 100644 --- a/Mono.GameMath/Vector2.cs +++ b/Mono.GameMath/Vector2.cs @@ -632,17 +632,17 @@ public static void TransformNormal (Vector2[] sourceArray, ref Matrix matrix, Ve public bool Equals (Vector2 other) { - return x == other.x && y == other.y; + return x.Equals(other.x) && y.Equals(other.y); } public override bool Equals (object obj) { - return obj is Vector2 && ((Vector2)obj) == this; + return obj is Vector2 && this.Equals((Vector2)obj); } public override int GetHashCode () { - return x.GetHashCode () ^ y.GetHashCode (); + return x.GetHashCode () * 31 + y.GetHashCode (); } public static bool operator == (Vector2 a, Vector2 b) diff --git a/Mono.GameMath/Vector3.cs b/Mono.GameMath/Vector3.cs index 95ddb62..09c66a1 100644 --- a/Mono.GameMath/Vector3.cs +++ b/Mono.GameMath/Vector3.cs @@ -811,13 +811,13 @@ public bool Equals (Vector3 other) #if SIMD return v4 == other.v4; #else - return x == other.x && y == other.y && z == other.z; + return x.Equals(other.x) && y.Equals(other.y) && z.Equals(other.z); #endif } public override bool Equals (object obj) { - return obj is Vector3 && ((Vector3)obj) == this; + return obj is Vector3 && this.Equals((Vector2)obj); } public override int GetHashCode () @@ -842,7 +842,7 @@ public override int GetHashCode () } #else - return x.GetHashCode () ^ y.GetHashCode () ^ z.GetHashCode (); + return x.GetHashCode () * (31*31) + y.GetHashCode () * 31+ z.GetHashCode (); #endif } diff --git a/Mono.GameMath/Vector4.cs b/Mono.GameMath/Vector4.cs index e6518b5..d02b6ba 100644 --- a/Mono.GameMath/Vector4.cs +++ b/Mono.GameMath/Vector4.cs @@ -791,13 +791,13 @@ public bool Equals (Vector4 other) #if SIMD return v4 == other.v4; #else - return x == other.x && y == other.y && z == other.z && w == other.w; + return x.Equals(other.x) && y.Equals(other.y) && z.Equals(other.z) && w.Equals(other.w); #endif } public override bool Equals (object obj) { - return obj is Vector4 && ((Vector4)obj) == this; + return obj is Vector4 && this.Equals((Vector2)obj); } public override int GetHashCode () @@ -824,7 +824,7 @@ public override int GetHashCode () } #else - return x.GetHashCode () ^ y.GetHashCode () ^ w.GetHashCode () ^ w.GetHashCode (); + return x.GetHashCode () *(31*31*31) + y.GetHashCode () * (31*31) + z.GetHashCode () * 31 + w.GetHashCode (); #endif }