Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MathUtil.cs 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. using UnityEngine.UI;
  8. namespace XCharts.Runtime
  9. {
  10. public static class MathUtil
  11. {
  12. public static double Abs(double d)
  13. {
  14. return d > 0 ? d : -d;
  15. }
  16. public static double Clamp(double d, double min, double max)
  17. {
  18. if (d >= min && d <= max) return d;
  19. else if (d < min) return min;
  20. else return max;
  21. }
  22. public static bool Approximately(double a, double b)
  23. {
  24. return Math.Abs(b - a) < Math.Max(0.000001f * Math.Max(Math.Abs(a), Math.Abs(b)), Mathf.Epsilon * 8);
  25. }
  26. public static double Clamp01(double value)
  27. {
  28. if (value < 0F)
  29. return 0F;
  30. else if (value > 1F)
  31. return 1F;
  32. else
  33. return value;
  34. }
  35. public static double Lerp(double a, double b, double t)
  36. {
  37. return a + (b - a) * Clamp01(t);
  38. }
  39. }
  40. }