FloatComparer.cs 708 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. namespace UnityTest
  3. {
  4. public class FloatComparer : ComparerBaseGeneric<float>
  5. {
  6. public enum CompareTypes
  7. {
  8. Equal,
  9. NotEqual,
  10. Greater,
  11. Less
  12. }
  13. public CompareTypes compareTypes;
  14. public double floatingPointError = 0.0001f;
  15. protected override bool Compare (float a, float b)
  16. {
  17. switch (compareTypes)
  18. {
  19. case CompareTypes.Equal:
  20. return Math.Abs (a - b) < floatingPointError;
  21. case CompareTypes.NotEqual:
  22. return Math.Abs (a - b) > floatingPointError;
  23. case CompareTypes.Greater:
  24. return a > b;
  25. case CompareTypes.Less:
  26. return a < b;
  27. }
  28. throw new Exception();
  29. }
  30. public override int GetDepthOfSearch()
  31. {
  32. return 3;
  33. }
  34. }
  35. }