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
thesis-src/Examples/Common/Distance/DistanceComparer.cs
T
2023-12-04 18:22:08 +01:00

44 lines
896 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;
}
return
$"<strong style='color: orange;' title='REf: {Reference}, CER: {Distance}'>{str ?? "-"}</strong>";
}
}