Vector4EqualityComparer.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections.Generic;
  2. namespace UnityEngine.TestTools.Utils
  3. {
  4. public class Vector4EqualityComparer : IEqualityComparer<Vector4>
  5. {
  6. private const float k_DefaultError = 0.0001f;
  7. private readonly float AllowedError;
  8. private static readonly Vector4EqualityComparer m_Instance = new Vector4EqualityComparer();
  9. public static Vector4EqualityComparer Instance { get { return m_Instance; } }
  10. private Vector4EqualityComparer() : this(k_DefaultError) {}
  11. public Vector4EqualityComparer(float allowedError)
  12. {
  13. this.AllowedError = allowedError;
  14. }
  15. public bool Equals(Vector4 expected, Vector4 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. Utils.AreFloatsEqual(expected.w, actual.w, AllowedError);
  21. }
  22. public int GetHashCode(Vector4 vec4)
  23. {
  24. return 0;
  25. }
  26. }
  27. }