Mathd.cs 1.0 KB

123456789101112131415161718192021222324252627
  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>Clamps value between 0 and 1 and returns value.</summary>
  8. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  9. public static double Clamp01(double value)
  10. {
  11. if (value < 0.0)
  12. return 0;
  13. return value > 1 ? 1 : value;
  14. }
  15. /// <summary>Calculates the linear parameter t that produces the interpolant value within the range [a, b].</summary>
  16. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  17. public static double InverseLerp(double a, double b, double value) =>
  18. a != b ? Clamp01((value - a) / (b - a)) : 0;
  19. /// <summary>Linearly interpolates between a and b by t with no limit to t.</summary>
  20. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  21. public static double LerpUnclamped(double a, double b, double t) =>
  22. a + (b - a) * t;
  23. }
  24. }