From a2a9c922d4f36c45a15bce9f79d79472285bf6fd Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 21:26:34 +0200 Subject: [PATCH] Added transformation by quaternion test. --- tests/OpenTK.Tests/Vector3Tests.fs | 27 +++++++++++++++++++++++++-- tests/OpenTK.Tests/Vector4Tests.fs | 25 ++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 9c879b68..2d5b3cab 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -684,7 +684,7 @@ module Vector3 = [] let ``Unit one is correct`` = - let unitOne = Vector3((float32)1, (float32)1, (float32)1) + let unitOne = Vector3(1.0f, 1.0f, 1.0f) Assert.Equal(Vector3.One, unitOne) @@ -696,4 +696,27 @@ module Vector3 = let expectedSize = sizeof * 3 Assert.Equal(expectedSize, Vector3.SizeInBytes) - Assert.Equal(expectedSize, Marshal.SizeOf(Vector3())) \ No newline at end of file + Assert.Equal(expectedSize, Marshal.SizeOf(Vector3())) + + [ |])>] + module Transformation = + // + [] + let ``Transformation by quaternion 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 = Vector3(transformedQuat.X, transformedQuat.Y, transformedQuat.Z) + + Assert.Equal(transformedVector, Vector3.Transform(v, q)) + + [] + let ``Transformation by quaternion by reference 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 = Vector3(transformedQuat.X, transformedQuat.Y,transformedQuat.Z) + + Assert.Equal(transformedVector, Vector3.Transform(ref v, ref q)) \ No newline at end of file diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 7033f2a7..2abb7bb7 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -806,4 +806,27 @@ module Vector4 = let expectedSize = sizeof * 4 Assert.Equal(expectedSize, Vector4.SizeInBytes) - Assert.Equal(expectedSize, Marshal.SizeOf(Vector4())) \ No newline at end of file + Assert.Equal(expectedSize, Marshal.SizeOf(Vector4())) + + [ |])>] + module Transformation = + // + [] + let ``Transformation by quaternion 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(v, q)) + + [] + let ``Transformation by quaternion 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