diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index fccdbc63..fd9fb6e3 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -462,94 +462,99 @@ module Vector2 = Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); + [ |])>] + module ``Magnitude min and max`` = + // + [] + let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.MagnitudeMin(v1, v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.MagnitudeMax(v1, v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + + [] + let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.MagnitudeMin(ref v1, ref v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax by reference selects the vector with equal greater magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.MagnitudeMax(ref v1, ref v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + [ |])>] module ``Component min and max`` = // [] - let ``ComponentMin produces a new vector from the smallest components of the given vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - + let ``ComponentMin creates a new vector from the smallest components of given vectors`` (v1 : Vector2, v2: Vector2) = let vMin = Vector2.ComponentMin(v1, v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) - - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) [] - let ``ComponentMax produces a new vector from the largest components of the given vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - + let ``ComponentMax creates a new vector from the greatest components of given vectors`` (v1 : Vector2, v2: Vector2) = let vMax = Vector2.ComponentMax(v1, v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) - - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) [] - let ``ComponentMin by reference produces a new vector from the smallest components of the given vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - + let ``ComponentMin by reference creates a new vector from the smallest components of given vectors`` (v1 : Vector2, v2: Vector2) = let vMin = Vector2.ComponentMin(ref v1, ref v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) - - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) [] - let ``ComponentMax by reference produces a new vector from the largest components of the given vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - + let ``ComponentMax by reference creates a new vector from the greatest components of given vectors`` (v1 : Vector2, v2: Vector2) = let vMax = Vector2.ComponentMax(ref v1, ref v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) - - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) - - [] - let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared - - let vMin = Vector2.Min(v1, v2) - - if l1 < l2 then - let equalsFirst = vMin = v1 - Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) - - [] - let ``Max selects the vector with greater magnitude given two vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared - - let vMin = Vector2.Max(v1, v2) - - if l1 >= l2 then - let equalsFirst = vMin = v1 - Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) [ |])>] module Transformation = diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 851358cc..36713dd9 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -527,106 +527,103 @@ module Vector3 = let vRes = Vector3.Cross(ref a, ref b) Assert.Equal(cross, vRes) + [ |])>] + module ``Magnitude min and max`` = + // + [] + let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.MagnitudeMin(v1, v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.MagnitudeMax(v1, v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + + [] + let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.MagnitudeMin(ref v1, ref v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax by reference selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.MagnitudeMax(ref v1, ref v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + [ |])>] module ``Component min and max`` = // [] - let ``ComponentMin produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - + let ``ComponentMin creates a new vector from the smallest components of given vectors`` (v1 : Vector3, v2: Vector3) = let vMin = Vector3.ComponentMin(v1, v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) - - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) - - Assert.True(vMin.Z <= v1.Z) - Assert.True(vMin.Z <= v2.Z) + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) + Assert.True(isComponentSmallest vMin.Z v1.Z v2.Z) [] - let ``ComponentMax producing a new vector from the largest components of the given vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - + let ``ComponentMax creates a new vector from the greatest components of given vectors`` (v1 : Vector3, v2: Vector3) = let vMax = Vector3.ComponentMax(v1, v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) - - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) - - Assert.True(vMax.Z >= v1.Z) - Assert.True(vMax.Z >= v2.Z) + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) + Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) [] - let ``ComponentMin by reference produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - + let ``ComponentMin by reference creates a new vector from the smallest components of given vectors`` (v1 : Vector3, v2: Vector3) = let vMin = Vector3.ComponentMin(ref v1, ref v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) - - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) - - Assert.True(vMin.Z <= v1.Z) - Assert.True(vMin.Z <= v2.Z) + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) + Assert.True(isComponentSmallest vMin.Z v1.Z v2.Z) [] - let ``ComponentMax produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - + let ``ComponentMax by reference creates a new vector from the greatest components of given vectors`` (v1 : Vector3, v2: Vector3) = let vMax = Vector3.ComponentMax(ref v1, ref v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) - - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) - - Assert.True(vMax.Z >= v1.Z) - Assert.True(vMax.Z >= v2.Z) - - [] - let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared - - let vMin = Vector3.Min(v1, v2) - - if l1 < l2 then - let equalsFirst = vMin = v1 - Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) - - [] - let ``Max selects the vector with greater magnitude given two vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared - - let vMin = Vector3.Max(v1, v2) - - if l1 >= l2 then - let equalsFirst = vMin = v1 - Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) + Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) [ |])>] module Clamping = diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 0cf78ad0..90babe05 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -692,17 +692,14 @@ module Vector4 = Assert.Equal(dot, vRes) [ |])>] - module ``Component min and max`` = + module ``Magnitude min and max`` = // [] - let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, z, w, a, b, c, d) = - let v1 = Vector4(x, y, z, w) - let v2 = Vector4(a, b, c, d) - + let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = let l1 = v1.LengthSquared let l2 = v2.LengthSquared - let vMin = Vector4.Min(v1, v2) + let vMin = Vector4.MagnitudeMin(v1, v2) if vMin = v1 then let v1ShorterThanv2 = l1 < l2 @@ -712,14 +709,11 @@ module Vector4 = Assert.True(v2ShorterThanv1) [] - let ``Max selects the vector with greater magnitude given two vectors`` (x, y, z, w, a, b, c, d) = - let v1 = Vector4(x, y, z, w) - let v2 = Vector4(a, b, c, d) - + let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = let l1 = v1.LengthSquared let l2 = v2.LengthSquared - let vMin = Vector4.Max(v1, v2) + let vMin = Vector4.MagnitudeMax(v1, v2) if vMin = v1 then let v1LongerThanOrEqualTov2 = l1 >= l2 @@ -728,6 +722,78 @@ module Vector4 = let v2LongerThanv1 = l2 > l1 Assert.True(v2LongerThanv1) + [] + let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector4.MagnitudeMin(ref v1, ref v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax by reference selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector4.MagnitudeMax(ref v1, ref v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + + [ |])>] + module ``Component min and max`` = + // + [] + let ``ComponentMin creates a new vector from the smallest components of given vectors`` (v1 : Vector4, v2: Vector4) = + let vMin = Vector4.ComponentMin(v1, v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 + + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) + Assert.True(isComponentSmallest vMin.Z v1.Z v2.Z) + Assert.True(isComponentSmallest vMin.W v1.W v2.W) + + [] + let ``ComponentMax creates a new vector from the greatest components of given vectors`` (v1 : Vector4, v2: Vector4) = + let vMax = Vector4.ComponentMax(v1, v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 + + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) + Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) + Assert.True(isComponentLargest vMax.W v1.W v2.W) + + [] + let ``ComponentMin by reference creates a new vector from the smallest components of given vectors`` (v1 : Vector4, v2: Vector4) = + let vMin = Vector4.ComponentMin(ref v1, ref v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 + + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) + Assert.True(isComponentSmallest vMin.Z v1.Z v2.Z) + Assert.True(isComponentSmallest vMin.W v1.W v2.W) + + [] + let ``ComponentMax by reference creates a new vector from the greatest components of given vectors`` (v1 : Vector4, v2: Vector4) = + let vMax = Vector4.ComponentMax(ref v1, ref v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 + + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) + Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) + Assert.True(isComponentLargest vMax.W v1.W v2.W) + + [ |])>] module Clamping = //