This repository has been archived on 2024-06-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2024-01-15 00:05:04 +01:00

46 lines
948 B
C#

using System.Collections;
namespace Common.Distance;
public readonly struct DistanceComparer<T> : IDistanceComparer<T>
where T : IEnumerable
{
/// <inheritdoc />
public T Reference { get; }
/// <inheritdoc />
public T? Hypothesis { get; }
/// <inheritdoc />
public double Distance { get; }
public DistanceComparer(T reference) : this(reference, default)
{
}
public DistanceComparer(T reference, T? hypothesis)
{
Reference = reference;
Hypothesis = hypothesis;
Distance = Calculator.GetDistance(Reference, Hypothesis);
}
/// <inheritdoc />
public override string ToString()
{
var str = Hypothesis?.ToString();
if (Hypothesis is var hyp && Equals(hyp, Reference))
{
return str ?? string.Empty;
}
// Enable for HTML/MD only
// return $"<strong style='color: orange;' title='REf: {Reference}, CER: {Distance}'>{str ?? "-"}</strong>";
return str ?? "-";
}
}