Mathd.cs 840 B

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