Mathd.cs 1.0 KB

12345678910111213141516171819202122232425262728
  1. // 'double' precision variants for some of Unity's Mathf functions.
  2. using System.Runtime.CompilerServices;
  3. namespace Mirror
  4. {
  5. public static class Mathd
  6. {
  7. /// <summary>Linearly interpolates between a and b by t with no limit to t.</summary>
  8. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  9. public static double LerpUnclamped(double a, double b, double t) =>
  10. a + (b - a) * t;
  11. /// <summary>Clamps value between 0 and 1 and returns value.</summary>
  12. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  13. public static double Clamp01(double value)
  14. {
  15. if (value < 0.0)
  16. return 0;
  17. return value > 1 ? 1 : value;
  18. }
  19. /// <summary>Calculates the linear parameter t that produces the interpolant value within the range [a, b].</summary>
  20. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  21. public static double InverseLerp(double a, double b, double value) =>
  22. a != b ? Clamp01((value - a) / (b - a)) : 0;
  23. }
  24. }