Merge pull request #4 from Nihlus/fix-division-rounding
Fixed rounding error in division operations.
This commit is contained in:
commit
ecdd0cdc0d
6 changed files with 44 additions and 40 deletions
|
@ -623,7 +623,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector2 vector, float scale, out Vector2 result)
|
public static void Divide(ref Vector2 vector, float scale, out Vector2 result)
|
||||||
{
|
{
|
||||||
Multiply(ref vector, 1 / scale, out result);
|
result.X = vector.X / scale;
|
||||||
|
result.Y = vector.Y / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1143,9 +1144,8 @@ namespace OpenTK
|
||||||
/// <returns>Result of the division.</returns>
|
/// <returns>Result of the division.</returns>
|
||||||
public static Vector2 operator /(Vector2 vec, float scale)
|
public static Vector2 operator /(Vector2 vec, float scale)
|
||||||
{
|
{
|
||||||
float mult = 1.0f / scale;
|
vec.X /= scale;
|
||||||
vec.X *= mult;
|
vec.Y /= scale;
|
||||||
vec.Y *= mult;
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -541,7 +541,8 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector2d vector, double scale, out Vector2d result)
|
public static void Divide(ref Vector2d vector, double scale, out Vector2d result)
|
||||||
{
|
{
|
||||||
Multiply(ref vector, 1 / scale, out result);
|
result.X = vector.X / scale;
|
||||||
|
result.Y = vector.Y / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1065,9 +1066,8 @@ namespace OpenTK
|
||||||
/// <returns>The result of the operation.</returns>
|
/// <returns>The result of the operation.</returns>
|
||||||
public static Vector2d operator /(Vector2d vec, double f)
|
public static Vector2d operator /(Vector2d vec, double f)
|
||||||
{
|
{
|
||||||
double mult = 1.0 / f;
|
vec.X /= f;
|
||||||
vec.X *= mult;
|
vec.Y /= f;
|
||||||
vec.Y *= mult;
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -629,7 +629,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector3 vector, float scale, out Vector3 result)
|
public static void Divide(ref Vector3 vector, float scale, out Vector3 result)
|
||||||
{
|
{
|
||||||
Multiply(ref vector, 1 / scale, out result);
|
result.X = vector.X / scale;
|
||||||
|
result.Y = vector.Y / scale;
|
||||||
|
result.Z = vector.Z / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1634,10 +1636,9 @@ namespace OpenTK
|
||||||
/// <returns>The result of the calculation.</returns>
|
/// <returns>The result of the calculation.</returns>
|
||||||
public static Vector3 operator /(Vector3 vec, float scale)
|
public static Vector3 operator /(Vector3 vec, float scale)
|
||||||
{
|
{
|
||||||
float mult = 1.0f / scale;
|
vec.X /= scale;
|
||||||
vec.X *= mult;
|
vec.Y /= scale;
|
||||||
vec.Y *= mult;
|
vec.Z /= scale;
|
||||||
vec.Z *= mult;
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -627,7 +627,9 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector3d vector, double scale, out Vector3d result)
|
public static void Divide(ref Vector3d vector, double scale, out Vector3d result)
|
||||||
{
|
{
|
||||||
Multiply(ref vector, 1 / scale, out result);
|
result.X = vector.X / scale;
|
||||||
|
result.Y = vector.Y / scale;
|
||||||
|
result.Z = vector.Z / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1451,10 +1453,9 @@ namespace OpenTK
|
||||||
/// <returns>The result of the calculation.</returns>
|
/// <returns>The result of the calculation.</returns>
|
||||||
public static Vector3d operator /(Vector3d vec, double scale)
|
public static Vector3d operator /(Vector3d vec, double scale)
|
||||||
{
|
{
|
||||||
double mult = 1 / scale;
|
vec.X /= scale;
|
||||||
vec.X *= mult;
|
vec.Y /= scale;
|
||||||
vec.Y *= mult;
|
vec.Z /= scale;
|
||||||
vec.Z *= mult;
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -514,11 +514,10 @@ namespace OpenTK
|
||||||
/// <returns>Result of the division</returns>
|
/// <returns>Result of the division</returns>
|
||||||
public static Vector4 Div(Vector4 a, float f)
|
public static Vector4 Div(Vector4 a, float f)
|
||||||
{
|
{
|
||||||
float mult = 1.0f / f;
|
a.X /= f;
|
||||||
a.X *= mult;
|
a.Y /= f;
|
||||||
a.Y *= mult;
|
a.Z /= f;
|
||||||
a.Z *= mult;
|
a.W /= f;
|
||||||
a.W *= mult;
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,11 +529,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the division</param>
|
/// <param name="result">Result of the division</param>
|
||||||
public static void Div(ref Vector4 a, float f, out Vector4 result)
|
public static void Div(ref Vector4 a, float f, out Vector4 result)
|
||||||
{
|
{
|
||||||
float mult = 1.0f / f;
|
result.X = a.X / f;
|
||||||
result.X = a.X * mult;
|
result.Y = a.Y / f;
|
||||||
result.Y = a.Y * mult;
|
result.Z = a.Z / f;
|
||||||
result.Z = a.Z * mult;
|
result.W = a.W / f;
|
||||||
result.W = a.W * mult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -667,7 +665,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector4 vector, float scale, out Vector4 result)
|
public static void Divide(ref Vector4 vector, float scale, out Vector4 result)
|
||||||
{
|
{
|
||||||
Multiply(ref vector, 1 / scale, out result);
|
result.X = vector.X / scale;
|
||||||
|
result.Y = vector.Y / scale;
|
||||||
|
result.Z = vector.Z / scale;
|
||||||
|
result.W = vector.W / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1705,11 +1706,10 @@ namespace OpenTK
|
||||||
/// <returns>The result of the calculation.</returns>
|
/// <returns>The result of the calculation.</returns>
|
||||||
public static Vector4 operator /(Vector4 vec, float scale)
|
public static Vector4 operator /(Vector4 vec, float scale)
|
||||||
{
|
{
|
||||||
float mult = 1.0f / scale;
|
vec.X /= scale;
|
||||||
vec.X *= mult;
|
vec.Y /= scale;
|
||||||
vec.Y *= mult;
|
vec.Z /= scale;
|
||||||
vec.Z *= mult;
|
vec.W /= scale;
|
||||||
vec.W *= mult;
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -669,7 +669,10 @@ namespace OpenTK
|
||||||
/// <param name="result">Result of the operation.</param>
|
/// <param name="result">Result of the operation.</param>
|
||||||
public static void Divide(ref Vector4d vector, double scale, out Vector4d result)
|
public static void Divide(ref Vector4d vector, double scale, out Vector4d result)
|
||||||
{
|
{
|
||||||
Multiply(ref vector, 1 / scale, out result);
|
result.X = vector.X / scale;
|
||||||
|
result.Y = vector.Y / scale;
|
||||||
|
result.Z = vector.Z / scale;
|
||||||
|
result.W = vector.W / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1641,11 +1644,10 @@ namespace OpenTK
|
||||||
/// <returns>The result of the calculation.</returns>
|
/// <returns>The result of the calculation.</returns>
|
||||||
public static Vector4d operator /(Vector4d vec, double scale)
|
public static Vector4d operator /(Vector4d vec, double scale)
|
||||||
{
|
{
|
||||||
double mult = 1 / scale;
|
vec.X /= scale;
|
||||||
vec.X *= mult;
|
vec.Y /= scale;
|
||||||
vec.Y *= mult;
|
vec.Z /= scale;
|
||||||
vec.Z *= mult;
|
vec.W /= scale;
|
||||||
vec.W *= mult;
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue