Added transformation by quaternion test.

This commit is contained in:
Jarl Gullberg 2017-06-01 21:26:34 +02:00
parent 7d846c4459
commit a2a9c922d4
No known key found for this signature in database
GPG key ID: 750FF6F6BDA72D23
2 changed files with 49 additions and 3 deletions

View file

@ -684,7 +684,7 @@ module Vector3 =
[<Property>]
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)
@ -697,3 +697,26 @@ module Vector3 =
Assert.Equal(expectedSize, Vector3.SizeInBytes)
Assert.Equal(expectedSize, Marshal.SizeOf(Vector3()))
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module Transformation =
//
[<Property>]
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))
[<Property>]
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))

View file

@ -807,3 +807,26 @@ module Vector4 =
Assert.Equal(expectedSize, Vector4.SizeInBytes)
Assert.Equal(expectedSize, Marshal.SizeOf(Vector4()))
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module Transformation =
//
[<Property>]
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))
[<Property>]
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))