Vector3EqualityComparer.cs 1.0 KB

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