From bea15cd250ed7961dfc4c6d9b5703e2cecf7659c Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 19:42:08 +0200 Subject: [PATCH 01/10] Obsoleted Min/Max methods. --- src/OpenTK/Math/Vector2.cs | 4 +++- src/OpenTK/Math/Vector2d.cs | 6 +++++- src/OpenTK/Math/Vector3.cs | 10 ++++++---- src/OpenTK/Math/Vector3d.cs | 6 ++++-- src/OpenTK/Math/Vector4.cs | 6 +++++- src/OpenTK/Math/Vector4d.cs | 8 ++++++-- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/OpenTK/Math/Vector2.cs b/src/OpenTK/Math/Vector2.cs index d7f81427..60474396 100644 --- a/src/OpenTK/Math/Vector2.cs +++ b/src/OpenTK/Math/Vector2.cs @@ -717,6 +717,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMin() instead.")] public static Vector2 Min(Vector2 left, Vector2 right) { return left.LengthSquared < right.LengthSquared ? left : right; @@ -732,6 +733,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMax() instead.")] public static Vector2 Max(Vector2 left, Vector2 right) { return left.LengthSquared >= right.LengthSquared ? left : right; @@ -1074,7 +1076,7 @@ namespace OpenTK vec.Y *= scale.Y; return vec; } - + /// /// Divides the specified instance by a scalar. /// diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index 3993aafa..a57f18e9 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -577,6 +577,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static Vector2d Min(Vector2d a, Vector2d b) { a.X = a.X < b.X ? a.X : b.X; @@ -590,6 +591,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static void Min(ref Vector2d a, ref Vector2d b, out Vector2d result) { result.X = a.X < b.X ? a.X : b.X; @@ -606,6 +608,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static Vector2d Max(Vector2d a, Vector2d b) { a.X = a.X > b.X ? a.X : b.X; @@ -619,6 +622,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static void Max(ref Vector2d a, ref Vector2d b, out Vector2d result) { result.X = a.X > b.X ? a.X : b.X; @@ -936,7 +940,7 @@ namespace OpenTK vec.Y *= scale.Y; return vec; } - + /// /// Divides an instance by a scalar. /// diff --git a/src/OpenTK/Math/Vector3.cs b/src/OpenTK/Math/Vector3.cs index 000a3698..e7eb009d 100644 --- a/src/OpenTK/Math/Vector3.cs +++ b/src/OpenTK/Math/Vector3.cs @@ -727,6 +727,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMin() instead.")] public static Vector3 Min(Vector3 left, Vector3 right) { return left.LengthSquared < right.LengthSquared ? left : right; @@ -742,6 +743,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMax() instead.")] public static Vector3 Max(Vector3 left, Vector3 right) { return left.LengthSquared >= right.LengthSquared ? left : right; @@ -1270,10 +1272,10 @@ namespace OpenTK { Vector4 result; - result.X = - vector.X * worldViewProjection.M11 + - vector.Y * worldViewProjection.M21 + - vector.Z * worldViewProjection.M31 + + result.X = + vector.X * worldViewProjection.M11 + + vector.Y * worldViewProjection.M21 + + vector.Z * worldViewProjection.M31 + worldViewProjection.M41; result.Y = diff --git a/src/OpenTK/Math/Vector3d.cs b/src/OpenTK/Math/Vector3d.cs index 556b9ab9..76202870 100644 --- a/src/OpenTK/Math/Vector3d.cs +++ b/src/OpenTK/Math/Vector3d.cs @@ -725,6 +725,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMin() instead.")] public static Vector3d Min(Vector3d left, Vector3d right) { return left.LengthSquared < right.LengthSquared ? left : right; @@ -740,6 +741,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMax() instead.")] public static Vector3d Max(Vector3d left, Vector3d right) { return left.LengthSquared >= right.LengthSquared ? left : right; @@ -1372,7 +1374,7 @@ namespace OpenTK vec.Z *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// @@ -1386,7 +1388,7 @@ namespace OpenTK vec.Z *= scale.Z; return vec; } - + /// /// Divides an instance by a scalar. /// diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index a821031e..ff09f987 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -703,6 +703,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static Vector4 Min(Vector4 a, Vector4 b) { a.X = a.X < b.X ? a.X : b.X; @@ -718,6 +719,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static void Min(ref Vector4 a, ref Vector4 b, out Vector4 result) { result.X = a.X < b.X ? a.X : b.X; @@ -736,6 +738,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static Vector4 Max(Vector4 a, Vector4 b) { a.X = a.X > b.X ? a.X : b.X; @@ -751,6 +754,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static void Max(ref Vector4 a, ref Vector4 b, out Vector4 result) { result.X = a.X > b.X ? a.X : b.X; @@ -1514,7 +1518,7 @@ namespace OpenTK vec.W *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// diff --git a/src/OpenTK/Math/Vector4d.cs b/src/OpenTK/Math/Vector4d.cs index facc329d..03801497 100644 --- a/src/OpenTK/Math/Vector4d.cs +++ b/src/OpenTK/Math/Vector4d.cs @@ -175,7 +175,7 @@ namespace OpenTK #endregion #region Public Members - + /// /// Gets or sets the value at the index of the Vector. /// @@ -705,6 +705,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static Vector4d Min(Vector4d a, Vector4d b) { a.X = a.X < b.X ? a.X : b.X; @@ -720,6 +721,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static void Min(ref Vector4d a, ref Vector4d b, out Vector4d result) { result.X = a.X < b.X ? a.X : b.X; @@ -738,6 +740,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static Vector4d Max(Vector4d a, Vector4d b) { a.X = a.X > b.X ? a.X : b.X; @@ -753,6 +756,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static void Max(ref Vector4d a, ref Vector4d b, out Vector4d result) { result.X = a.X > b.X ? a.X : b.X; @@ -1493,7 +1497,7 @@ namespace OpenTK vec.W *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// From 809e7b4379ebeaebe547e63f88bcaff94e5391d4 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:31:54 +0200 Subject: [PATCH 02/10] Improved documentation. --- src/OpenTK/Math/Vector2.cs | 58 +++++++++++++++++ src/OpenTK/Math/Vector2d.cs | 112 ++++++++++++++++++++++++++++++++ src/OpenTK/Math/Vector3.cs | 58 +++++++++++++++++ src/OpenTK/Math/Vector3d.cs | 54 ++++++++++++++++ src/OpenTK/Math/Vector4.cs | 124 ++++++++++++++++++++++++++++++++++++ src/OpenTK/Math/Vector4d.cs | 120 ++++++++++++++++++++++++++++++++++ 6 files changed, 526 insertions(+) diff --git a/src/OpenTK/Math/Vector2.cs b/src/OpenTK/Math/Vector2.cs index 60474396..c1e2c2ae 100644 --- a/src/OpenTK/Math/Vector2.cs +++ b/src/OpenTK/Math/Vector2.cs @@ -709,6 +709,64 @@ namespace OpenTK #endregion + #region MagnitudeMin + + /// + /// Returns the Vector2 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The minimum Vector2 + public static Vector2 MagnitudeMin(Vector2 left, Vector2 right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector2 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector2 + public static void MagnitudeMin(ref Vector2 left, ref Vector2 right, out Vector2 result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector2 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The maximum Vector2 + public static Vector2 MagnitudeMax(Vector2 left, Vector2 right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector2 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector2 + public static void MagnitudeMax(ref Vector2 left, ref Vector2 right, out Vector2 result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Min /// diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index a57f18e9..df2abedb 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -631,6 +631,118 @@ namespace OpenTK #endregion + #region ComponentMin + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static Vector2d ComponentMin(Vector2d a, Vector2d b) + { + a.X = a.X < b.X ? a.X : b.X; + a.Y = a.Y < b.Y ? a.Y : b.Y; + return a; + } + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static void ComponentMin(ref Vector2d a, ref Vector2d b, out Vector2d result) + { + result.X = a.X < b.X ? a.X : b.X; + result.Y = a.Y < b.Y ? a.Y : b.Y; + } + + #endregion + + #region ComponentMax + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static Vector2d ComponentMax(Vector2d a, Vector2d b) + { + a.X = a.X > b.X ? a.X : b.X; + a.Y = a.Y > b.Y ? a.Y : b.Y; + return a; + } + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static void ComponentMax(ref Vector2d a, ref Vector2d b, out Vector2d result) + { + result.X = a.X > b.X ? a.X : b.X; + result.Y = a.Y > b.Y ? a.Y : b.Y; + } + + #endregion + + #region MagnitudeMin + + /// + /// Returns the Vector2d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector2d + public static Vector2d MagnitudeMin(Vector2d left, Vector2d right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector2d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector2d + public static void MagnitudeMin(ref Vector2d left, ref Vector2d right, out Vector2d result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector2d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector2d + public static Vector2d MagnitudeMax(Vector2d left, Vector2d right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector2d with the maximum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector2d + public static void MagnitudeMax(ref Vector2d left, ref Vector2d right, out Vector2d result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Clamp /// diff --git a/src/OpenTK/Math/Vector3.cs b/src/OpenTK/Math/Vector3.cs index e7eb009d..b2301f7e 100644 --- a/src/OpenTK/Math/Vector3.cs +++ b/src/OpenTK/Math/Vector3.cs @@ -719,6 +719,64 @@ namespace OpenTK #endregion + #region MagnitudeMin + + /// + /// Returns the Vector3 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The minimum Vector3 + public static Vector3 MagnitudeMin(Vector3 left, Vector3 right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector3 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector3 + public static void MagnitudeMin(ref Vector3 left, ref Vector3 right, out Vector3 result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector3 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The maximum Vector3 + public static Vector3 MagnitudeMax(Vector3 left, Vector3 right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector3 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector3 + public static void MagnitudeMax(ref Vector3 left, ref Vector3 right, out Vector3 result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Min /// diff --git a/src/OpenTK/Math/Vector3d.cs b/src/OpenTK/Math/Vector3d.cs index 76202870..67f307e0 100644 --- a/src/OpenTK/Math/Vector3d.cs +++ b/src/OpenTK/Math/Vector3d.cs @@ -717,6 +717,60 @@ namespace OpenTK #endregion + #region MagnitudeMin + + /// + /// Returns the Vector3d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector3d + public static Vector3d MagnitudeMin(Vector3d left, Vector3d right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector3d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector3d + public static void MagnitudeMin(ref Vector3d left, ref Vector3d right, out Vector3d result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector3d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector3d + public static Vector3d MagnitudeMax(Vector3d left, Vector3d right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector3d with the maximum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector3d + public static void MagnitudeMax(ref Vector3d left, ref Vector3d right, out Vector3d result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Min /// diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index ff09f987..b2f13fb3 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -765,6 +765,130 @@ namespace OpenTK #endregion + #region ComponentMin + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static Vector4 ComponentMin(Vector4 a, Vector4 b) + { + a.X = a.X < b.X ? a.X : b.X; + a.Y = a.Y < b.Y ? a.Y : b.Y; + a.Z = a.Z < b.Z ? a.Z : b.Z; + a.W = a.W < b.W ? a.W : b.W; + return a; + } + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static void ComponentMin(ref Vector4 a, ref Vector4 b, out Vector4 result) + { + result.X = a.X < b.X ? a.X : b.X; + result.Y = a.Y < b.Y ? a.Y : b.Y; + result.Z = a.Z < b.Z ? a.Z : b.Z; + result.W = a.W < b.W ? a.W : b.W; + } + + #endregion + + #region ComponentMax + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static Vector4 ComponentMax(Vector4 a, Vector4 b) + { + a.X = a.X > b.X ? a.X : b.X; + a.Y = a.Y > b.Y ? a.Y : b.Y; + a.Z = a.Z > b.Z ? a.Z : b.Z; + a.W = a.W > b.W ? a.W : b.W; + return a; + } + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static void ComponentMax(ref Vector4 a, ref Vector4 b, out Vector4 result) + { + result.X = a.X > b.X ? a.X : b.X; + result.Y = a.Y > b.Y ? a.Y : b.Y; + result.Z = a.Z > b.Z ? a.Z : b.Z; + result.W = a.W > b.W ? a.W : b.W; + } + + #endregion + + #region MagnitudeMin + + /// + /// Returns the Vector4 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The minimum Vector4 + public static Vector4 MagnitudeMin(Vector4 left, Vector4 right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector4 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector4 + public static void MagnitudeMin(ref Vector4 left, ref Vector4 right, out Vector4 result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector4 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The maximum Vector4 + public static Vector4 MagnitudeMax(Vector4 left, Vector4 right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector4 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector4 + public static void MagnitudeMax(ref Vector4 left, ref Vector4 right, out Vector4 result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Clamp /// diff --git a/src/OpenTK/Math/Vector4d.cs b/src/OpenTK/Math/Vector4d.cs index 03801497..a9d385dd 100644 --- a/src/OpenTK/Math/Vector4d.cs +++ b/src/OpenTK/Math/Vector4d.cs @@ -767,6 +767,126 @@ namespace OpenTK #endregion + #region ComponentMin + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static Vector4d ComponentMin(Vector4d a, Vector4d b) + { + a.X = a.X < b.X ? a.X : b.X; + a.Y = a.Y < b.Y ? a.Y : b.Y; + a.Z = a.Z < b.Z ? a.Z : b.Z; + a.W = a.W < b.W ? a.W : b.W; + return a; + } + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static void ComponentMin(ref Vector4d a, ref Vector4d b, out Vector4d result) + { + result.X = a.X < b.X ? a.X : b.X; + result.Y = a.Y < b.Y ? a.Y : b.Y; + result.Z = a.Z < b.Z ? a.Z : b.Z; + result.W = a.W < b.W ? a.W : b.W; + } + + #endregion + + #region ComponentMax + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static Vector4d ComponentMax(Vector4d a, Vector4d b) + { + a.X = a.X > b.X ? a.X : b.X; + a.Y = a.Y > b.Y ? a.Y : b.Y; + a.Z = a.Z > b.Z ? a.Z : b.Z; + a.W = a.W > b.W ? a.W : b.W; + return a; + } + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static void ComponentMax(ref Vector4d a, ref Vector4d b, out Vector4d result) + { + result.X = a.X > b.X ? a.X : b.X; + result.Y = a.Y > b.Y ? a.Y : b.Y; + result.Z = a.Z > b.Z ? a.Z : b.Z; + result.W = a.W > b.W ? a.W : b.W; + } + + #endregion + + #region MagnitudeMin + + /// + /// Returns the Vector4d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector4d + public static Vector4d MagnitudeMin(Vector4d left, Vector4d right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector4d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector4d + public static void MagnitudeMin(ref Vector4d left, ref Vector4d right, out Vector4d result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector4d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector4d + public static Vector4d MagnitudeMax(Vector4d left, Vector4d right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector4d with the maximum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector4d + public static void MagnitudeMax(ref Vector4d left, ref Vector4d right, out Vector4d result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Clamp /// From 28bede6ca1d1dc63f56a0af98588e6c61c7e9cd8 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:32:16 +0200 Subject: [PATCH 03/10] Added filtering for vector generation to only produce valid vectors. --- tests/OpenTK.Tests/Generators.fs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/OpenTK.Tests/Generators.fs b/tests/OpenTK.Tests/Generators.fs index cbcdd929..39200f5b 100644 --- a/tests/OpenTK.Tests/Generators.fs +++ b/tests/OpenTK.Tests/Generators.fs @@ -22,18 +22,21 @@ module private Generators = singleArb |> Gen.two |> Gen.map Vector2 + |> Gen.filter (fun v -> not <| (Single.IsNaN v.Length || Single.IsInfinity v.Length )) |> Arb.fromGen let vec3 = singleArb |> Gen.three |> Gen.map Vector3 + |> Gen.filter (fun v -> not <| (Single.IsNaN v.Length || Single.IsInfinity v.Length )) |> Arb.fromGen let vec4 = singleArb |> Gen.four |> Gen.map Vector4 + |> Gen.filter (fun v -> not <| (Single.IsNaN v.Length || Single.IsInfinity v.Length )) |> Arb.fromGen let quat = From c3fa66eb15da1f58145315ac7e21d8a5ff467d58 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:33:00 +0200 Subject: [PATCH 04/10] Implemented all ComponentMin/Max and MagnitudeMin/Max tests. --- tests/OpenTK.Tests/Vector2Tests.fs | 145 +++++++++++++------------- tests/OpenTK.Tests/Vector3Tests.fs | 161 ++++++++++++++--------------- tests/OpenTK.Tests/Vector4Tests.fs | 88 ++++++++++++++-- 3 files changed, 231 insertions(+), 163 deletions(-) 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 = // From 5191491cdb042b5e3924df02108e8f12b2cf5021 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:34:13 +0200 Subject: [PATCH 05/10] Fixed MagnitudeMin test. --- tests/OpenTK.Tests/Vector4Tests.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 90babe05..9221adaa 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -705,8 +705,8 @@ module Vector4 = let v1ShorterThanv2 = l1 < l2 Assert.True(v1ShorterThanv2) else - let v2ShorterThanv1 = l2 < l1 - Assert.True(v2ShorterThanv1) + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = From 0438a0325ac355d9941634209b925204f06ca21c Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:35:14 +0200 Subject: [PATCH 06/10] Decreased approximation sensitivity again. --- tests/OpenTK.Tests/Assertions.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index e4e1c412..62c9171f 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -9,7 +9,7 @@ open OpenTK [] module private AssertHelpers = [] - let private BitAccuracy = 9 + let private BitAccuracy = 10 let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) From b26242d1db425860b6b3bf612352d28a15e18c82 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:44:30 +0200 Subject: [PATCH 07/10] Decreased approximation sensitivity even more. --- tests/OpenTK.Tests/Assertions.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index 62c9171f..68eb2759 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -9,7 +9,7 @@ open OpenTK [] module private AssertHelpers = [] - let private BitAccuracy = 10 + let private BitAccuracy = 13 let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) From d27a4671a53797a7e33f1704127438d363f6950f Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 22:25:44 +0200 Subject: [PATCH 08/10] Improved test name. --- tests/OpenTK.Tests/Vector4Tests.fs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 9221adaa..b4f48b38 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -799,27 +799,27 @@ module Vector4 = // [] let ``Clamping one vector between two other vectors clamps all components between corresponding components`` (a : Vector4, b : Vector4, w : Vector4) = - let res = Vector4.Clamp(w, a, b) - let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z let expW = if w.W < a.W then a.W else if w.W > b.W then b.W else w.W + let res = Vector4.Clamp(w, a, b) + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) Assert.Equal(expW, res.W) [] - let ``Clamping one vector between two other vectors by reference clamps all components`` (a : Vector4, b : Vector4, w : Vector4) = - let res = Vector4.Clamp(ref w, ref a, ref b) - + let ``Clamping one vector between two other vectors by reference clamps all components between corresponding components`` (a : Vector4, b : Vector4, w : Vector4) = let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z let expW = if w.W < a.W then a.W else if w.W > b.W then b.W else w.W + let res = Vector4.Clamp(ref w, ref a, ref b) + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) From 18976c898afce3041118c9bcd3b8f1ce36ece697 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 22:59:24 +0200 Subject: [PATCH 09/10] Improve comments. --- src/OpenTK/Math/Vector2d.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index df2abedb..f443a824 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -692,7 +692,8 @@ namespace OpenTK #region MagnitudeMin /// - /// Returns the Vector2d with the minimum magnitude + /// Returns the Vector2d with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. /// /// Left operand /// Right operand @@ -703,7 +704,8 @@ namespace OpenTK } /// - /// Returns the Vector2d with the minimum magnitude + /// Returns the Vector2d with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. /// /// Left operand /// Right operand @@ -719,7 +721,8 @@ namespace OpenTK #region MagnitudeMax /// - /// Returns the Vector2d with the minimum magnitude + /// Returns the Vector2d with the minimum magnitude. If the magnitudes are equal, the first vector + /// is selected. /// /// Left operand /// Right operand @@ -730,7 +733,8 @@ namespace OpenTK } /// - /// Returns the Vector2d with the maximum magnitude + /// Returns the Vector2d with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. /// /// Left operand /// Right operand From 4f50ea8bee392237de221ccce6690d266fbce8ce Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sat, 3 Jun 2017 15:14:39 +0200 Subject: [PATCH 10/10] Improved ComponentMin/Max documentation. --- src/OpenTK/Math/Vector2.cs | 8 ++++---- src/OpenTK/Math/Vector2d.cs | 8 ++++---- src/OpenTK/Math/Vector3.cs | 8 ++++---- src/OpenTK/Math/Vector3d.cs | 8 ++++---- src/OpenTK/Math/Vector4.cs | 8 ++++---- src/OpenTK/Math/Vector4d.cs | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/OpenTK/Math/Vector2.cs b/src/OpenTK/Math/Vector2.cs index c1e2c2ae..b24f8d67 100644 --- a/src/OpenTK/Math/Vector2.cs +++ b/src/OpenTK/Math/Vector2.cs @@ -654,7 +654,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -667,7 +667,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -683,7 +683,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -696,7 +696,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index f443a824..069ac10c 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -634,7 +634,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -647,7 +647,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -663,7 +663,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -676,7 +676,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector3.cs b/src/OpenTK/Math/Vector3.cs index b2301f7e..e0abc54e 100644 --- a/src/OpenTK/Math/Vector3.cs +++ b/src/OpenTK/Math/Vector3.cs @@ -660,7 +660,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -674,7 +674,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -691,7 +691,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -705,7 +705,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector3d.cs b/src/OpenTK/Math/Vector3d.cs index 67f307e0..0be7f1c9 100644 --- a/src/OpenTK/Math/Vector3d.cs +++ b/src/OpenTK/Math/Vector3d.cs @@ -658,7 +658,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -672,7 +672,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -689,7 +689,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -703,7 +703,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index b2f13fb3..7f605dd3 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -768,7 +768,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -783,7 +783,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -801,7 +801,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -816,7 +816,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector4d.cs b/src/OpenTK/Math/Vector4d.cs index a9d385dd..67a4af8b 100644 --- a/src/OpenTK/Math/Vector4d.cs +++ b/src/OpenTK/Math/Vector4d.cs @@ -770,7 +770,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -785,7 +785,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -803,7 +803,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -818,7 +818,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand