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
Simon Gruber 8ada606fa6 a
2023-11-22 07:46:10 +01:00

36 lines
850 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() => Hypothesis switch
{
null => "`null`",
var hyp when Equals(hyp, Reference) => Hypothesis.ToString() ?? string.Empty,
_ => $"<strong style='color: orange;' title='CER: {Distance}'>{Hypothesis}</strong>"
};
}