Cleanup code #1267
This commit is contained in:
@@ -876,62 +876,54 @@ namespace FlaxEngine
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Given a heading which may be outside the +/- PI range, 'unwind' it back into that range.
|
/// Given a heading which may be outside the +/- PI range, 'unwind' it back into that range.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>Optimized version of <see cref="UnwindRadiansAccurate"/> that is it faster and has fixed cost but with large angle values (100 for example) starts to lose accuracy floating point problem.</remarks>
|
||||||
/// <param name="angle">Angle in radians to unwind.</param>
|
/// <param name="angle">Angle in radians to unwind.</param>
|
||||||
/// <returns>Valid angle in radians.</returns>
|
/// <returns>Valid angle in radians.</returns>
|
||||||
public static double UnwindRadians(double angle)
|
public static double UnwindRadians(double angle)
|
||||||
{
|
{
|
||||||
//[nori_sc] made it faster has fixed cost but with large angle values starts to lose accuracy floating point problem
|
var a = angle - Math.Floor(angle / TwoPi) * TwoPi; // Loop function between 0 and TwoPi
|
||||||
// 1 call teaks ~20-30 ns with anny value
|
return a > Pi ? a - TwoPi : a; // Change range so it become Pi and -Pi
|
||||||
var a = angle - Floor(angle / TwoPi) * TwoPi; //loop funcion betwine 0 and TwoPi
|
|
||||||
return a > Pi ? (a - TwoPi) : a; // change range so it become Pi and -Pi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the same as <see cref="UnwindRadians"/> but is more computation intensive with large <see href="angle"/> and has better accuracy with large <see href="angle"/>
|
/// The same as <see cref="UnwindRadians"/> but is more computation intensive with large <see href="angle"/> and has better accuracy with large <see href="angle"/>.
|
||||||
/// <br>cost of this funcion is <see href="angle"/> % <see cref="Pi"/></br>
|
/// <br>cost of this function is <see href="angle"/> % <see cref="Pi"/></br>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="angle">Angle in radians to unwind.</param>
|
/// <param name="angle">Angle in radians to unwind.</param>
|
||||||
/// <returns>Valid angle in radians.</returns>
|
/// <returns>Valid angle in radians.</returns>
|
||||||
public static double UnwindRadiansAccurate(double angle)
|
public static double UnwindRadiansAccurate(double angle)
|
||||||
{
|
{
|
||||||
while (angle > Pi)
|
while (angle > Pi)
|
||||||
{
|
|
||||||
angle -= TwoPi;
|
angle -= TwoPi;
|
||||||
}
|
|
||||||
while (angle < -Pi)
|
while (angle < -Pi)
|
||||||
{
|
|
||||||
angle += TwoPi;
|
angle += TwoPi;
|
||||||
}
|
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Utility to ensure angle is between +/- 180 degrees by unwinding
|
/// Utility to ensure angle is between +/- 180 degrees by unwinding.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>Optimized version of <see cref="UnwindDegreesAccurate"/> that is it faster and has fixed cost but with large angle values (100 for example) starts to lose accuracy floating point problem.</remarks>
|
||||||
/// <param name="angle">Angle in degrees to unwind.</param>
|
/// <param name="angle">Angle in degrees to unwind.</param>
|
||||||
/// <returns>Valid angle in degrees.</returns>
|
/// <returns>Valid angle in degrees.</returns>
|
||||||
public static double UnwindDegrees(double angle)
|
public static double UnwindDegrees(double angle)
|
||||||
{
|
{
|
||||||
//[nori_sc] made it faster for large values has fixed cost but with large angle values starts to lose accuracy floating point problem
|
var a = angle - Math.Floor(angle / 360.0) * 360.0; // Loop function between 0 and 360
|
||||||
// 1 call teaks ~20 ns with anny value
|
return a > 180 ? a - 360.0 : a; // Change range so it become 180 and -180
|
||||||
var a = angle - Floor(angle / 360.0) * 360.0; //loop funcion betwine 0 and 360
|
|
||||||
return a > 180 ? (a - 360.0) : a; // change range so it become 180 and -180
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the same as <see cref="UnwindDegrees"/> but is more computation intensive with large <see href="angle"/> and has better accuracy with large <see href="angle"/>
|
/// The same as <see cref="UnwindDegrees"/> but is more computation intensive with large <see href="angle"/> and has better accuracy with large <see href="angle"/>.
|
||||||
/// <br>cost of this funcion is <see href="angle"/> % 180.0f</br>
|
/// <br>cost of this function is <see href="angle"/> % 180.0f</br>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="angle">Angle in radians to unwind.</param>
|
/// <param name="angle">Angle in radians to unwind.</param>
|
||||||
/// <returns>Valid angle in radians.</returns>
|
/// <returns>Valid angle in radians.</returns>
|
||||||
public static double UnwindDegreesAccurate(double angle)
|
public static double UnwindDegreesAccurate(double angle)
|
||||||
{
|
{
|
||||||
while (angle > 180.0)
|
while (angle > 180.0)
|
||||||
{
|
|
||||||
angle -= 360.0;
|
angle -= 360.0;
|
||||||
}
|
|
||||||
while (angle < -180.0)
|
while (angle < -180.0)
|
||||||
{
|
|
||||||
angle += 360.0;
|
angle += 360.0;
|
||||||
}
|
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1176,63 +1176,57 @@ namespace FlaxEngine
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Given a heading which may be outside the +/- PI range, 'unwind' it back into that range.
|
/// Given a heading which may be outside the +/- PI range, 'unwind' it back into that range.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>Optimized version of <see cref="UnwindRadiansAccurate"/> that is it faster and has fixed cost but with large angle values (100 for example) starts to lose accuracy floating point problem.</remarks>
|
||||||
/// <param name="angle">Angle in radians to unwind.</param>
|
/// <param name="angle">Angle in radians to unwind.</param>
|
||||||
/// <returns>Valid angle in radians.</returns>
|
/// <returns>Valid angle in radians.</returns>
|
||||||
public static float UnwindRadians(float angle)
|
public static float UnwindRadians(float angle)
|
||||||
{
|
{
|
||||||
//[nori_sc] made it faster has fixed cost but with large angle values (100 for example) starts to lose accuracy floating point problem
|
var a = angle - (float)Math.Floor(angle / TwoPi) * TwoPi; // Loop function between 0 and TwoPi
|
||||||
// 1 call teaks ~20-30 ns with anny value
|
return a > Pi ? a - TwoPi : a; // Change range so it become Pi and -Pi
|
||||||
var a = angle - Mathf.Floor(angle / Mathf.TwoPi) * Mathf.TwoPi; //loop funcion betwine 0 and TwoPi
|
|
||||||
return a > Mathf.Pi ? (a - Mathf.TwoPi) : a; // change range so it become Pi and -Pi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the same as <see cref="UnwindRadians"/> but is more computation intensive with large <see href="angle"/> and has better accuracy with large <see href="angle"/>
|
/// The same as <see cref="UnwindRadians"/> but is more computation intensive with large <see href="angle"/> and has better accuracy with large <see href="angle"/>.
|
||||||
/// <br>cost of this funcion is <see href="angle"/> % <see cref="Pi"/></br>
|
/// <br>cost of this function is <see href="angle"/> % <see cref="Pi"/></br>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="angle">Angle in radians to unwind.</param>
|
/// <param name="angle">Angle in radians to unwind.</param>
|
||||||
/// <returns>Valid angle in radians.</returns>
|
/// <returns>Valid angle in radians.</returns>
|
||||||
public static float UnwindRadiansAccurate(float angle)
|
public static float UnwindRadiansAccurate(float angle)
|
||||||
{
|
{
|
||||||
while (angle > Pi)
|
while (angle > Pi)
|
||||||
{
|
|
||||||
angle -= TwoPi;
|
angle -= TwoPi;
|
||||||
}
|
|
||||||
while (angle < -Pi)
|
while (angle < -Pi)
|
||||||
{
|
|
||||||
angle += TwoPi;
|
angle += TwoPi;
|
||||||
}
|
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Utility to ensure angle is between +/- 180 degrees by unwinding
|
/// Utility to ensure angle is between +/- 180 degrees by unwinding.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>Optimized version of <see cref="UnwindDegreesAccurate"/> that is it faster and has fixed cost but with large angle values (100 for example) starts to lose accuracy floating point problem.</remarks>
|
||||||
/// <param name="angle">Angle in degrees to unwind.</param>
|
/// <param name="angle">Angle in degrees to unwind.</param>
|
||||||
/// <returns>Valid angle in degrees.</returns>
|
/// <returns>Valid angle in degrees.</returns>
|
||||||
public static float UnwindDegrees(float angle)
|
public static float UnwindDegrees(float angle)
|
||||||
{
|
{
|
||||||
//[nori_sc] made it faster for large values has fixed cost but with large angle values (1 000 000 for example) starts to lose accuracy floating point problem
|
var a = angle - (float)Math.Floor(angle / 360.0f) * 360.0f; // Loop function between 0 and 360
|
||||||
// 1 call teaks ~20 ns with anny value
|
return a > 180 ? a - 360.0f : a; // Change range so it become 180 and -180
|
||||||
var a = angle - Floor(angle / 360.0f) * 360.0f; //loop funcion betwine 0 and 360
|
|
||||||
return a > 180 ? (a - 360.0f) : a; // change range so it become 180 and -180
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the same as <see cref="UnwindDegrees"/> but is more computation intensive with large <see href="angle"/> and has better accuracy with large <see href="angle"/>
|
/// The same as <see cref="UnwindDegrees"/> but is more computation intensive with large <see href="angle"/> and has better accuracy with large <see href="angle"/>.
|
||||||
/// <br>cost of this funcion is <see href="angle"/> % 180.0f</br>
|
/// <br>cost of this function is <see href="angle"/> % 180.0f</br>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="angle">Angle in radians to unwind.</param>
|
/// <param name="angle">Angle in radians to unwind.</param>
|
||||||
/// <returns>Valid angle in radians.</returns>
|
/// <returns>Valid angle in radians.</returns>
|
||||||
public static float UnwindDegreesAccurate(float angle)
|
public static float UnwindDegreesAccurate(float angle)
|
||||||
{
|
{
|
||||||
while (angle > 180.0f)
|
while (angle > 180.0f)
|
||||||
{
|
|
||||||
angle -= 360.0f;
|
angle -= 360.0f;
|
||||||
}
|
|
||||||
while (angle < -180.0f)
|
while (angle < -180.0f)
|
||||||
{
|
|
||||||
angle += 360.0f;
|
angle += 360.0f;
|
||||||
}
|
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clamps the specified value.
|
/// Clamps the specified value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user