// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using System.Numerics;
namespace SixLabors.ImageSharp.Tests
{
///
/// Allows the approximate comparison of single precision floating point values.
///
internal readonly struct ApproximateFloatComparer :
IEqualityComparer,
IEqualityComparer,
IEqualityComparer
{
private readonly float Epsilon;
///
/// Initializes a new instance of the class.
///
/// The comparison error difference epsilon to use.
public ApproximateFloatComparer(float epsilon = 1f) => this.Epsilon = epsilon;
///
public bool Equals(float x, float y)
{
float d = x - y;
return d >= -this.Epsilon && d <= this.Epsilon;
}
///
public int GetHashCode(float obj) => obj.GetHashCode();
///
public bool Equals(Vector4 a, Vector4 b) => this.Equals(a.X, b.X) && this.Equals(a.Y, b.Y) && this.Equals(a.Z, b.Z) && this.Equals(a.W, b.W);
///
public int GetHashCode(Vector4 obj) => obj.GetHashCode();
///
public bool Equals(Vector2 a, Vector2 b) => this.Equals(a.X, b.X) && this.Equals(a.Y, b.Y);
public int GetHashCode(Vector2 obj)
{
throw new System.NotImplementedException();
}
}
}