Range.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.Timeline
  4. {
  5. struct Range
  6. {
  7. public double start;
  8. public double end;
  9. public double length { get { return end - start; } }
  10. public static Range Union(Range lhs, Range rhs)
  11. {
  12. return new Range
  13. {
  14. start = Math.Min(lhs.start, rhs.start),
  15. end = Math.Max(lhs.end, rhs.end)
  16. };
  17. }
  18. public static Range Intersection(Range lhs, Range rhs)
  19. {
  20. var s = Math.Max(lhs.start, rhs.start);
  21. var e = Math.Min(lhs.end, rhs.end);
  22. if (s > e)
  23. {
  24. // No intersection returns a 0-length range from 0 to 0
  25. return new Range();
  26. }
  27. return new Range
  28. {
  29. start = s,
  30. end = e
  31. };
  32. }
  33. public override string ToString()
  34. {
  35. return ToString("F3");
  36. }
  37. public string ToString(string format)
  38. {
  39. return UnityString.Format("({0}, {1})", start.ToString(format), end.ToString(format));
  40. }
  41. }
  42. }