From 7c298cc43d56fe868a13d341ac893f15f040ea8b Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 19:32:22 +0200 Subject: [PATCH] Eliminated additional step for division operations. --- src/OpenTK/Math/Vector2.cs | 9 ++++----- src/OpenTK/Math/Vector2d.cs | 9 ++++----- src/OpenTK/Math/Vector3.cs | 17 ++++++++--------- src/OpenTK/Math/Vector3d.cs | 13 ++++++------- src/OpenTK/Math/Vector4.cs | 31 ++++++++++++++----------------- src/OpenTK/Math/Vector4d.cs | 15 +++++++-------- 6 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/OpenTK/Math/Vector2.cs b/src/OpenTK/Math/Vector2.cs index d7f8142..463296a 100644 --- a/src/OpenTK/Math/Vector2.cs +++ b/src/OpenTK/Math/Vector2.cs @@ -623,7 +623,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector2 vector, float scale, out Vector2 result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1074,7 +1074,7 @@ namespace OpenTK vec.Y *= scale.Y; return vec; } - + /// /// Divides the specified instance by a scalar. /// @@ -1083,9 +1083,8 @@ namespace OpenTK /// Result of the division. public static Vector2 operator /(Vector2 vec, float scale) { - float mult = 1.0f / scale; - vec.X *= mult; - vec.Y *= mult; + vec.X /= scale; + vec.Y /= scale; return vec; } diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index 3993aaf..8282265 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -541,7 +541,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector2d vector, double scale, out Vector2d result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -936,7 +936,7 @@ namespace OpenTK vec.Y *= scale.Y; return vec; } - + /// /// Divides an instance by a scalar. /// @@ -945,9 +945,8 @@ namespace OpenTK /// The result of the operation. public static Vector2d operator /(Vector2d vec, double f) { - double mult = 1.0 / f; - vec.X *= mult; - vec.Y *= mult; + vec.X /= f; + vec.Y /= f; return vec; } diff --git a/src/OpenTK/Math/Vector3.cs b/src/OpenTK/Math/Vector3.cs index 000a369..d47bfdf 100644 --- a/src/OpenTK/Math/Vector3.cs +++ b/src/OpenTK/Math/Vector3.cs @@ -629,7 +629,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector3 vector, float scale, out Vector3 result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1270,10 +1270,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 = @@ -1574,10 +1574,9 @@ namespace OpenTK /// The result of the calculation. public static Vector3 operator /(Vector3 vec, float scale) { - float mult = 1.0f / scale; - vec.X *= mult; - vec.Y *= mult; - vec.Z *= mult; + vec.X /= scale; + vec.Y /= scale; + vec.Z /= scale; return vec; } diff --git a/src/OpenTK/Math/Vector3d.cs b/src/OpenTK/Math/Vector3d.cs index 556b9ab..d05a0c6 100644 --- a/src/OpenTK/Math/Vector3d.cs +++ b/src/OpenTK/Math/Vector3d.cs @@ -627,7 +627,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector3d vector, double scale, out Vector3d result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1372,7 +1372,7 @@ namespace OpenTK vec.Z *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// @@ -1386,7 +1386,7 @@ namespace OpenTK vec.Z *= scale.Z; return vec; } - + /// /// Divides an instance by a scalar. /// @@ -1395,10 +1395,9 @@ namespace OpenTK /// The result of the calculation. public static Vector3d operator /(Vector3d vec, double scale) { - double mult = 1 / scale; - vec.X *= mult; - vec.Y *= mult; - vec.Z *= mult; + vec.X /= scale; + vec.Y /= scale; + vec.Z /= scale; return vec; } diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index a821031..6ccac39 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -514,11 +514,10 @@ namespace OpenTK /// Result of the division public static Vector4 Div(Vector4 a, float f) { - float mult = 1.0f / f; - a.X *= mult; - a.Y *= mult; - a.Z *= mult; - a.W *= mult; + a.X /= f; + a.Y /= f; + a.Z /= f; + a.W /= f; return a; } @@ -530,11 +529,10 @@ namespace OpenTK /// Result of the division public static void Div(ref Vector4 a, float f, out Vector4 result) { - float mult = 1.0f / f; - result.X = a.X * mult; - result.Y = a.Y * mult; - result.Z = a.Z * mult; - result.W = a.W * mult; + result.X = a.X / f; + result.Y = a.Y / f; + result.Z = a.Z / f; + result.W = a.W / f; } #endregion @@ -667,7 +665,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector4 vector, float scale, out Vector4 result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1514,7 +1512,7 @@ namespace OpenTK vec.W *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// @@ -1577,11 +1575,10 @@ namespace OpenTK /// The result of the calculation. public static Vector4 operator /(Vector4 vec, float scale) { - float mult = 1.0f / scale; - vec.X *= mult; - vec.Y *= mult; - vec.Z *= mult; - vec.W *= mult; + vec.X /= scale; + vec.Y /= scale; + vec.Z /= scale; + vec.W /= scale; return vec; } diff --git a/src/OpenTK/Math/Vector4d.cs b/src/OpenTK/Math/Vector4d.cs index facc329..427291c 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. /// @@ -669,7 +669,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector4d vector, double scale, out Vector4d result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1493,7 +1493,7 @@ namespace OpenTK vec.W *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// @@ -1517,11 +1517,10 @@ namespace OpenTK /// The result of the calculation. public static Vector4d operator /(Vector4d vec, double scale) { - double mult = 1 / scale; - vec.X *= mult; - vec.Y *= mult; - vec.Z *= mult; - vec.W *= mult; + vec.X /= scale; + vec.Y /= scale; + vec.Z /= scale; + vec.W /= scale; return vec; } -- 2.7.4