From 0cd47f2c3c9e791dbafa1f09565f22cc31dfff52 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 10:56:02 +0200 Subject: [PATCH] Added test of multiplication operators. --- tests/OpenTK.Tests/Vector2Tests.fs | 11 +++++++++++ tests/OpenTK.Tests/Vector3Tests.fs | 10 ++++++++++ tests/OpenTK.Tests/Vector4Tests.fs | 16 +++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index 0bf0b30e..fccdbc63 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -574,6 +574,17 @@ module Vector2 = Assert.Equal(transformedVector, Vector2.Transform(ref v, ref q)) +// TODO: Implement multiplication operator for Vector2 and Quaternion +// [] +// let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = +// let vectorQuat = Quaternion(v.X, v.Y, 0.0f, 0.0f) +// let inverse = Quaternion.Invert(q) +// +// let transformedQuat = q * vectorQuat * inverse +// let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) +// +// Assert.Equal(transformedVector, q * v) + [ |])>] module Serialization = // diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 37bac293..851358cc 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -721,6 +721,16 @@ module Vector3 = Assert.ApproximatelyEqual(transformedVector, Vector3.Transform(ref v, ref q)) + [] + let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector3, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, v.Z, 0.0f) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = transformedQuat.Xyz + + Assert.ApproximatelyEqual(transformedVector, q * v) + [] let ``Transformation by identity quaternion does not alter vector`` (v : Vector3) = let q = Quaternion.Identity diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index ea6e0720..0cf78ad0 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -812,7 +812,7 @@ module Vector4 = module Transformation = // [] - let ``Transformation by quaternion is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = + let ``Transformation by quaternion with static method is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = let vectorQuat = Quaternion(v.X, v.Y, v.Z, v.W) let inverse = Quaternion.Invert(q) @@ -822,11 +822,21 @@ module Vector4 = Assert.Equal(transformedVector, Vector4.Transform(v, q)) [] - let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = + let ``Transformation by quaternion with static method by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = let vectorQuat = Quaternion(v.X, v.Y, v.Z, v.W) let inverse = Quaternion.Invert(q) let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y,transformedQuat.Z, transformedQuat.W) - Assert.Equal(transformedVector, Vector4.Transform(ref v, ref q)) \ No newline at end of file + Assert.Equal(transformedVector, Vector4.Transform(ref v, ref q)) + + [] + let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, v.Z, v.W) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y, transformedQuat.Z, transformedQuat.W) + + Assert.Equal(transformedVector, q * v) \ No newline at end of file