Vector2EqualityComparer.cs 966 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections.Generic;
  2. namespace UnityEngine.TestTools.Utils
  3. {
  4. public class Vector2EqualityComparer : IEqualityComparer<Vector2>
  5. {
  6. private const float k_DefaultError = 0.0001f;
  7. private readonly float AllowedError;
  8. private static readonly Vector2EqualityComparer m_Instance = new Vector2EqualityComparer();
  9. public static Vector2EqualityComparer Instance { get { return m_Instance; } }
  10. private Vector2EqualityComparer() : this(k_DefaultError)
  11. {
  12. }
  13. public Vector2EqualityComparer(float error)
  14. {
  15. this.AllowedError = error;
  16. }
  17. public bool Equals(Vector2 expected, Vector2 actual)
  18. {
  19. return Utils.AreFloatsEqual(expected.x, actual.x, AllowedError) &&
  20. Utils.AreFloatsEqual(expected.y, actual.y, AllowedError);
  21. }
  22. public int GetHashCode(Vector2 vec2)
  23. {
  24. return 0;
  25. }
  26. }
  27. }