mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-23 00:24:41 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -370,6 +370,10 @@ public sealed class SettingsStore
|
|||||||
return s;
|
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.
|
// The same value in other words: yes and tak, 45 and 45.0.
|
||||||
private static bool SameValue(string raw, string shown)
|
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))
|
if (string.Equals(a[i], b[i], StringComparison.OrdinalIgnoreCase))
|
||||||
continue;
|
continue;
|
||||||
if (double.TryParse(a[i], NumberStyles.Float, CultureInfo.InvariantCulture, out double x) &&
|
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;
|
continue;
|
||||||
if (Bool(a[i]) is { } p && p == Bool(b[i]))
|
if (Bool(a[i]) is { } p && p == Bool(b[i]))
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -443,7 +443,7 @@ public sealed class SettingsSerializer
|
|||||||
return tokens.Length >= 2 &&
|
return tokens.Length >= 2 &&
|
||||||
TryParseMouseScale(tokens[0], out _) &&
|
TryParseMouseScale(tokens[0], out _) &&
|
||||||
TryParseMouseScale(tokens[1], out double y) &&
|
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) =>
|
private static bool TryParseMouseScale(string token, out double scale) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user