From 5e391936ae10f95be81ebf15719971f0226d61c7 Mon Sep 17 00:00:00 2001 From: Nikolay Pozdnichenko Date: Tue, 3 Dec 2024 18:12:58 +0600 Subject: [PATCH] Try fix hamming distance calculation --- ...tanceBetweenOneDimensionalPointsCalculator.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/HammingDistanceBetweenOneDimensionalPointsCalculator.cs b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/HammingDistanceBetweenOneDimensionalPointsCalculator.cs index 00e21d8d..5a8a95de 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/HammingDistanceBetweenOneDimensionalPointsCalculator.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/HammingDistanceBetweenOneDimensionalPointsCalculator.cs @@ -1,5 +1,7 @@ namespace Libiada.Core.TimeSeries.OneDimensional.DistanceCalculators; +using System.Globalization; + /// /// The hamming distance between one dimensional points calculator. /// @@ -19,22 +21,20 @@ public class HammingDistanceBetweenOneDimensionalPointsCalculator : IOneDimensio /// public double GetDistance(double firstPoint, double secondPoint) { - string[] firstPointStringArray = firstPoint.ToString("0.00000000000000").Split(','); - string[] secondPointStringArray = secondPoint.ToString("0.00000000000000").Split(','); + string[] firstPointStringArray = firstPoint.ToString("0.00000000000000", CultureInfo.InvariantCulture).Split('.'); + string[] secondPointStringArray = secondPoint.ToString("0.00000000000000", CultureInfo.InvariantCulture).Split('.'); string intPartFirst = firstPointStringArray[0]; string intPartSecond = secondPointStringArray[0]; - if (firstPointStringArray[0].Length > secondPointStringArray[0].Length) + + while (intPartSecond.Length != intPartFirst.Length) { - for (int i = 0; i < firstPointStringArray[0].Length - secondPointStringArray[0].Length; i++) + if (intPartFirst.Length > intPartSecond.Length) { intPartSecond = $"0{intPartSecond}"; } - } - else - { - for (int i = 0; i < secondPointStringArray[0].Length - firstPointStringArray[0].Length; i++) + else { intPartFirst = $"0{intPartFirst}"; }