Refactor engine to support double-precision vectors
This commit is contained in:
@@ -50,6 +50,15 @@ namespace FlaxEngine
|
||||
return Math.Abs(f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the absolute value of f.
|
||||
/// </summary>
|
||||
/// <param name="f"></param>
|
||||
public static double Abs(double f)
|
||||
{
|
||||
return Math.Abs(f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the absolute value of value.
|
||||
/// </summary>
|
||||
@@ -65,7 +74,7 @@ namespace FlaxEngine
|
||||
/// <param name="f"></param>
|
||||
public static float Acos(float f)
|
||||
{
|
||||
return (float)Mathf.Acos(f);
|
||||
return (float)Math.Acos(f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -136,6 +145,18 @@ namespace FlaxEngine
|
||||
return value > 1f ? 1f : value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamps value between 0 and 1 and returns value.
|
||||
/// </summary>
|
||||
/// <param name="value">Value to clamp</param>
|
||||
/// <returns>Result value</returns>
|
||||
public static double Saturate(double value)
|
||||
{
|
||||
if (value < 0f)
|
||||
return 0f;
|
||||
return value > 1f ? 1f : value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cosine of angle f in radians.
|
||||
/// </summary>
|
||||
@@ -863,6 +884,15 @@ namespace FlaxEngine
|
||||
return (float)Math.Sqrt(f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns square root of f.
|
||||
/// </summary>
|
||||
/// <param name="f"></param>
|
||||
public static double Sqrt(double f)
|
||||
{
|
||||
return Math.Sqrt(f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns square of the given value.
|
||||
/// </summary>
|
||||
@@ -903,7 +933,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a and b are almost equals, taking into account the magnitude of floating point numbers (unlike <see cref="WithinEpsilon" /> method).
|
||||
/// Checks if a and b are almost equals, taking into account the magnitude of floating point numbers (unlike <see cref="WithinEpsilon(float,float,float)" /> method).
|
||||
/// </summary>
|
||||
/// <param name="a">The left value to compare.</param>
|
||||
/// <param name="b">The right value to compare.</param>
|
||||
@@ -941,7 +971,7 @@ namespace FlaxEngine
|
||||
/// <returns><c>true</c> if a almost equal to b, <c>false</c> otherwise</returns>
|
||||
public static bool NearEqual(double a, double b)
|
||||
{
|
||||
return Math.Abs(a - b) < double.Epsilon * 10;
|
||||
return Math.Abs(a - b) < Mathd.Epsilon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -964,6 +994,26 @@ namespace FlaxEngine
|
||||
return Math.Abs(a - 1.0f) < Epsilon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified value is close to zero (0.0f).
|
||||
/// </summary>
|
||||
/// <param name="a">The floating value.</param>
|
||||
/// <returns><c>true</c> if the specified value is close to zero (0.0f); otherwise, <c>false</c>.</returns>
|
||||
public static bool IsZero(double a)
|
||||
{
|
||||
return Math.Abs(a) < Mathd.Epsilon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified value is close to one (1.0f).
|
||||
/// </summary>
|
||||
/// <param name="a">The floating value.</param>
|
||||
/// <returns><c>true</c> if the specified value is close to one (1.0f); otherwise, <c>false</c>.</returns>
|
||||
public static bool IsOne(double a)
|
||||
{
|
||||
return Math.Abs(a - 1.0f) < Mathd.Epsilon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a - b are almost equals within a float epsilon.
|
||||
/// </summary>
|
||||
@@ -977,6 +1027,19 @@ namespace FlaxEngine
|
||||
return (-epsilon <= num) && (num <= epsilon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a - b are almost equals within a float epsilon.
|
||||
/// </summary>
|
||||
/// <param name="a">The left value to compare.</param>
|
||||
/// <param name="b">The right value to compare.</param>
|
||||
/// <param name="epsilon">Epsilon value</param>
|
||||
/// <returns><c>true</c> if a almost equal to b within a float epsilon, <c>false</c> otherwise</returns>
|
||||
public static bool WithinEpsilon(double a, double b, double epsilon)
|
||||
{
|
||||
double num = a - b;
|
||||
return (-epsilon <= num) && (num <= epsilon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified value is in a given range [min; max].
|
||||
/// </summary>
|
||||
@@ -1001,6 +1064,30 @@ namespace FlaxEngine
|
||||
return value < min || value > max;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified value is in a given range [min; max].
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="min">The minimum.</param>
|
||||
/// <param name="max">The maximum.</param>
|
||||
/// <returns><c>true</c> if the specified value is in a given range; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsInRange(double value, double min, double max)
|
||||
{
|
||||
return value >= min && value <= max;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified value is NOT in a given range [min; max].
|
||||
/// </summary>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="min">The minimum.</param>
|
||||
/// <param name="max">The maximum.</param>
|
||||
/// <returns><c>true</c> if the specified value is NOT in a given range; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsNotInRange(double value, double min, double max)
|
||||
{
|
||||
return value < min || value > max;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified value is in a given range [min; max].
|
||||
/// </summary>
|
||||
@@ -1197,9 +1284,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Interpolates between two values using a linear function by a given amount.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
|
||||
/// </remarks>
|
||||
/// <remarks>See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/</remarks>
|
||||
/// <param name="from">Value to interpolate from.</param>
|
||||
/// <param name="to">Value to interpolate to.</param>
|
||||
/// <param name="amount">Interpolation amount.</param>
|
||||
@@ -1212,9 +1297,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Interpolates between two values using a linear function by a given amount.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
|
||||
/// </remarks>
|
||||
/// <remarks>See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/</remarks>
|
||||
/// <param name="from">Value to interpolate from.</param>
|
||||
/// <param name="to">Value to interpolate to.</param>
|
||||
/// <param name="amount">Interpolation amount.</param>
|
||||
@@ -1227,9 +1310,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Interpolates between two values using a linear function by a given amount.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
|
||||
/// </remarks>
|
||||
/// <remarks>See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/</remarks>
|
||||
/// <param name="from">Value to interpolate from.</param>
|
||||
/// <param name="to">Value to interpolate to.</param>
|
||||
/// <param name="amount">Interpolation amount.</param>
|
||||
@@ -1242,9 +1323,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Interpolates between two values using a linear function by a given amount.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
|
||||
/// </remarks>
|
||||
/// <remarks>See http://www.encyclopediaofmath.org/index.php/Linear_interpolation and http://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/</remarks>
|
||||
/// <param name="from">Value to interpolate from.</param>
|
||||
/// <param name="to">Value to interpolate to.</param>
|
||||
/// <param name="amount">Interpolation amount.</param>
|
||||
@@ -1257,27 +1336,43 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Performs smooth (cubic Hermite) interpolation between 0 and 1.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See https://en.wikipedia.org/wiki/Smoothstep
|
||||
/// </remarks>
|
||||
/// <remarks>See https://en.wikipedia.org/wiki/Smoothstep</remarks>
|
||||
/// <param name="amount">Value between 0 and 1 indicating interpolation amount.</param>
|
||||
public static float SmoothStep(float amount)
|
||||
{
|
||||
return amount <= 0 ? 0 : amount >= 1 ? 1 : amount * amount * (3 - 2 * amount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs smooth (cubic Hermite) interpolation between 0 and 1.
|
||||
/// </summary>
|
||||
/// <remarks>See https://en.wikipedia.org/wiki/Smoothstep</remarks>
|
||||
/// <param name="amount">Value between 0 and 1 indicating interpolation amount.</param>
|
||||
public static double SmoothStep(double amount)
|
||||
{
|
||||
return amount <= 0 ? 0 : amount >= 1 ? 1 : amount * amount * (3 - 2 * amount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a smooth(er) interpolation between 0 and 1 with 1st and 2nd order derivatives of zero at endpoints.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See https://en.wikipedia.org/wiki/Smoothstep
|
||||
/// </remarks>
|
||||
/// <remarks>See https://en.wikipedia.org/wiki/Smoothstep</remarks>
|
||||
/// <param name="amount">Value between 0 and 1 indicating interpolation amount.</param>
|
||||
public static float SmootherStep(float amount)
|
||||
{
|
||||
return amount <= 0 ? 0 : amount >= 1 ? 1 : amount * amount * amount * (amount * (amount * 6 - 15) + 10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a smooth(er) interpolation between 0 and 1 with 1st and 2nd order derivatives of zero at endpoints.
|
||||
/// </summary>
|
||||
/// <remarks>See https://en.wikipedia.org/wiki/Smoothstep</remarks>
|
||||
/// <param name="amount">Value between 0 and 1 indicating interpolation amount.</param>
|
||||
public static double SmootherStep(double amount)
|
||||
{
|
||||
return amount <= 0 ? 0 : amount >= 1 ? 1 : amount * amount * amount * (amount * (amount * 6 - 15) + 10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the modulo of the specified value.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user