From c70fd9478389fecadf2bc3ce91992f259727f8ff Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 22 Nov 2026 00:14:49 +0100 Subject: [PATCH] fix(sonar): numbers read from the file are compared within a tolerance Equals is as exact as == to SonarCloud (S1244). Two numbers count as the same within a billionth of the larger one, and mousescale's second number as 0.5 within a billionth. Co-Authored-By: Claude Opus 5.5 --- StarterNG/Application/SettingsStore.cs | 6 +++++- StarterNG/Infrastructure/Settings/SettingsSerializer.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/StarterNG/Application/SettingsStore.cs b/StarterNG/Application/SettingsStore.cs index 008f99e..6c7d358 100644 --- a/StarterNG/Application/SettingsStore.cs +++ b/StarterNG/Application/SettingsStore.cs @@ -370,6 +370,10 @@ public sealed class SettingsStore return s; } + // Two numbers written apart that the file and the screen mean alike: 45 and 45.0, 0.1 and 1e-1. + private static bool SameNumber(double x, double y) => + Math.Abs(x - y) <= 1e-9 * Math.Max(1, Math.Max(Math.Abs(x), Math.Abs(y))); + // The same value in other words: yes and tak, 45 and 45.0. private static bool SameValue(string raw, string shown) { @@ -382,7 +386,7 @@ public sealed class SettingsStore if (string.Equals(a[i], b[i], StringComparison.OrdinalIgnoreCase)) continue; if (double.TryParse(a[i], NumberStyles.Float, CultureInfo.InvariantCulture, out double x) && - double.TryParse(b[i], NumberStyles.Float, CultureInfo.InvariantCulture, out double y) && x.Equals(y)) + double.TryParse(b[i], NumberStyles.Float, CultureInfo.InvariantCulture, out double y) && SameNumber(x, y)) continue; if (Bool(a[i]) is { } p && p == Bool(b[i])) continue; diff --git a/StarterNG/Infrastructure/Settings/SettingsSerializer.cs b/StarterNG/Infrastructure/Settings/SettingsSerializer.cs index b7ec0a6..5fc60b7 100644 --- a/StarterNG/Infrastructure/Settings/SettingsSerializer.cs +++ b/StarterNG/Infrastructure/Settings/SettingsSerializer.cs @@ -443,7 +443,7 @@ public sealed class SettingsSerializer return tokens.Length >= 2 && TryParseMouseScale(tokens[0], out _) && TryParseMouseScale(tokens[1], out double y) && - Math.Abs(y).Equals(SimulatorSettings.MouseScaleY); + Math.Abs(Math.Abs(y) - SimulatorSettings.MouseScaleY) < 1e-9; } private static bool TryParseMouseScale(string token, out double scale) =>