From fae20daac947a98d3ad1736566b58b4f7de8b4f7 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 26 Jul 2023 19:28:55 +0200 Subject: [PATCH] Cleanup code #1267 --- Source/Engine/Core/Math/Mathd.cs | 34 ++++++++++++------------------ Source/Engine/Core/Math/Mathf.cs | 36 +++++++++++++------------------- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/Source/Engine/Core/Math/Mathd.cs b/Source/Engine/Core/Math/Mathd.cs index d671d310b..48db547df 100644 --- a/Source/Engine/Core/Math/Mathd.cs +++ b/Source/Engine/Core/Math/Mathd.cs @@ -876,62 +876,54 @@ namespace FlaxEngine /// /// Given a heading which may be outside the +/- PI range, 'unwind' it back into that range. /// + /// Optimized version of that is it faster and has fixed cost but with large angle values (100 for example) starts to lose accuracy floating point problem. /// Angle in radians to unwind. /// Valid angle in radians. 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 - // 1 call teaks ~20-30 ns with anny value - 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 + var a = angle - Math.Floor(angle / TwoPi) * TwoPi; // Loop function between 0 and TwoPi + return a > Pi ? a - TwoPi : a; // Change range so it become Pi and -Pi } + /// - /// the same as but is more computation intensive with large and has better accuracy with large - ///
cost of this funcion is %
+ /// The same as but is more computation intensive with large and has better accuracy with large . + ///
cost of this function is %
///
/// Angle in radians to unwind. /// Valid angle in radians. public static double UnwindRadiansAccurate(double angle) { while (angle > Pi) - { angle -= TwoPi; - } while (angle < -Pi) - { angle += TwoPi; - } return angle; } /// - /// Utility to ensure angle is between +/- 180 degrees by unwinding + /// Utility to ensure angle is between +/- 180 degrees by unwinding. /// + /// Optimized version of that is it faster and has fixed cost but with large angle values (100 for example) starts to lose accuracy floating point problem. /// Angle in degrees to unwind. /// Valid angle in degrees. 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 - // 1 call teaks ~20 ns with anny value - 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 + var a = angle - Math.Floor(angle / 360.0) * 360.0; // Loop function between 0 and 360 + return a > 180 ? a - 360.0 : a; // Change range so it become 180 and -180 } + /// - /// the same as but is more computation intensive with large and has better accuracy with large - ///
cost of this funcion is % 180.0f
+ /// The same as but is more computation intensive with large and has better accuracy with large . + ///
cost of this function is % 180.0f
///
/// Angle in radians to unwind. /// Valid angle in radians. public static double UnwindDegreesAccurate(double angle) { while (angle > 180.0) - { angle -= 360.0; - } while (angle < -180.0) - { angle += 360.0; - } return angle; } diff --git a/Source/Engine/Core/Math/Mathf.cs b/Source/Engine/Core/Math/Mathf.cs index 09000e0cb..cea81a779 100644 --- a/Source/Engine/Core/Math/Mathf.cs +++ b/Source/Engine/Core/Math/Mathf.cs @@ -1176,63 +1176,57 @@ namespace FlaxEngine /// /// Given a heading which may be outside the +/- PI range, 'unwind' it back into that range. /// + /// Optimized version of that is it faster and has fixed cost but with large angle values (100 for example) starts to lose accuracy floating point problem. /// Angle in radians to unwind. /// Valid angle in radians. 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 - // 1 call teaks ~20-30 ns with anny value - 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 + var a = angle - (float)Math.Floor(angle / TwoPi) * TwoPi; // Loop function between 0 and TwoPi + return a > Pi ? a - TwoPi : a; // Change range so it become Pi and -Pi } + /// - /// the same as but is more computation intensive with large and has better accuracy with large - ///
cost of this funcion is %
+ /// The same as but is more computation intensive with large and has better accuracy with large . + ///
cost of this function is %
///
/// Angle in radians to unwind. /// Valid angle in radians. public static float UnwindRadiansAccurate(float angle) { while (angle > Pi) - { angle -= TwoPi; - } while (angle < -Pi) - { angle += TwoPi; - } return angle; } + /// - /// Utility to ensure angle is between +/- 180 degrees by unwinding + /// Utility to ensure angle is between +/- 180 degrees by unwinding. /// + /// Optimized version of that is it faster and has fixed cost but with large angle values (100 for example) starts to lose accuracy floating point problem. /// Angle in degrees to unwind. /// Valid angle in degrees. 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 - // 1 call teaks ~20 ns with anny value - 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 + var a = angle - (float)Math.Floor(angle / 360.0f) * 360.0f; // Loop function between 0 and 360 + return a > 180 ? a - 360.0f : a; // Change range so it become 180 and -180 } + /// - /// the same as but is more computation intensive with large and has better accuracy with large - ///
cost of this funcion is % 180.0f
+ /// The same as but is more computation intensive with large and has better accuracy with large . + ///
cost of this function is % 180.0f
///
/// Angle in radians to unwind. /// Valid angle in radians. public static float UnwindDegreesAccurate(float angle) { while (angle > 180.0f) - { angle -= 360.0f; - } while (angle < -180.0f) - { angle += 360.0f; - } return angle; } + /// /// Clamps the specified value. ///