From 3a455454f0f4aae90c074cc5310dab14acc8c3e5 Mon Sep 17 00:00:00 2001 From: j0rn Date: Mon, 15 Oct 2018 13:03:08 +0200 Subject: [PATCH 1/2] Write float values using the invariant culture. --- src/ImageSharp/ColorSpaces/CieLab.cs | 3 ++- src/ImageSharp/ColorSpaces/CieLch.cs | 3 ++- src/ImageSharp/ColorSpaces/CieLchuv.cs | 3 ++- src/ImageSharp/ColorSpaces/CieLuv.cs | 3 ++- .../ColorSpaces/CieXyChromaticityCoordinates.cs | 3 ++- src/ImageSharp/ColorSpaces/CieXyy.cs | 3 ++- src/ImageSharp/ColorSpaces/CieXyz.cs | 3 ++- src/ImageSharp/ColorSpaces/Cmyk.cs | 3 ++- src/ImageSharp/ColorSpaces/Hsl.cs | 3 ++- src/ImageSharp/ColorSpaces/Hsv.cs | 3 ++- src/ImageSharp/ColorSpaces/HunterLab.cs | 3 ++- src/ImageSharp/ColorSpaces/LinearRgb.cs | 3 ++- src/ImageSharp/ColorSpaces/Lms.cs | 3 ++- src/ImageSharp/ColorSpaces/Rgb.cs | 3 ++- src/ImageSharp/ColorSpaces/YCbCr.cs | 3 ++- src/ImageSharp/Common/Helpers/FloatToStringUtil.cs | 11 +++++++++++ 16 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 src/ImageSharp/Common/Helpers/FloatToStringUtil.cs diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index 230ea0bdc..d7af04120 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -127,7 +128,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLab({this.L:#0.##}, {this.A:#0.##}, {this.B:#0.##})"; + public override string ToString() => $"CieLab({FloatToString(this.L, this.A, this.B)})"; /// public override bool Equals(object obj) => obj is CieLab other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index 2c8f030e2..b0192b214 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -129,7 +130,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLch({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})"; + public override string ToString() => $"CieLch({FloatToString(this.L, this.C, this.H)})"; /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index 2aaff48a0..3e0d654dd 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -128,7 +129,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLchuv({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})"; + public override string ToString() => $"CieLchuv({FloatToString(this.L, this.C, this.H)})"; /// public override bool Equals(object obj) => obj is CieLchuv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index 9aac268e1..e0c17224d 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -128,7 +129,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLuv({this.L:#0.##}, {this.U:#0.##}, {this.V:#0.##})"; + public override string ToString() => $"CieLuv({FloatToString(this.L, this.U, this.V)})"; /// public override bool Equals(object obj) => obj is CieLuv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs index 06aaafb55..e29411f67 100644 --- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs @@ -3,6 +3,7 @@ using System; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; // ReSharper disable CompareOfFloatsByEqualityOperator namespace SixLabors.ImageSharp.ColorSpaces @@ -67,7 +68,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); /// - public override string ToString() => $"CieXyChromaticityCoordinates({this.X:#0.##}, {this.Y:#0.##})"; + public override string ToString() => $"CieXyChromaticityCoordinates({FloatToString(this.X, this.Y)})"; /// public override bool Equals(object obj) => obj is CieXyChromaticityCoordinates other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs index 44696a9db..a036e89c3 100644 --- a/src/ImageSharp/ColorSpaces/CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/CieXyy.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -91,7 +92,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieXyy({this.X:#0.##}, {this.Y:#0.##}, {this.Yl:#0.##})"; + public override string ToString() => $"CieXyy({FloatToString(this.X, this.Y, this.Yl)})"; /// public override bool Equals(object obj) => obj is CieXyy other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index 4fed9f4ed..f6d6e285e 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -94,7 +95,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieXyz({this.X:#0.##}, {this.Y:#0.##}, {this.Z:#0.##})"; + public override string ToString() => $"CieXyz({FloatToString(this.X, this.Y, this.Z)})"; /// public override bool Equals(object obj) => obj is CieXyz other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index 1d64e1995..e351642de 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -99,7 +100,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Cmyk({this.C:#0.##}, {this.M:#0.##}, {this.Y:#0.##}, {this.K:#0.##})"; + public override string ToString() => $"Cmyk({FloatToString(this.C, this.M, this.Y, this.K)})"; /// public override bool Equals(object obj) => obj is Cmyk other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index acc735bc5..5684d8184 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -92,7 +93,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Hsl({this.H:#0.##}, {this.S:#0.##}, {this.L:#0.##})"; + public override string ToString() => $"Hsl({FloatToString(this.H, this.S, this.L)})"; /// public override bool Equals(object obj) => obj is Hsl other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index caabe9b4b..9d40a6d3f 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -90,7 +91,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Hsv({this.H:#0.##}, {this.S:#0.##}, {this.V:#0.##})"; + public override string ToString() => $"Hsv({FloatToString(this.H, this.S, this.V)})"; /// public override bool Equals(object obj) => obj is Hsv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index ed30fa93b..3e336ca68 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -126,7 +127,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"HunterLab({this.L:#0.##}, {this.A:#0.##}, {this.B:#0.##})"; + public override string ToString() => $"HunterLab({FloatToString(this.L, this.A, this.B)})"; /// public override bool Equals(object obj) => obj is HunterLab other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index 09a2d83cb..c376a4d1d 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -5,6 +5,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -134,7 +135,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"LinearRgb({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##})"; + public override string ToString() => $"LinearRgb({FloatToString(this.R, this.G, this.B)})"; /// public override bool Equals(object obj) => obj is LinearRgb other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs index 59a4069b0..823d1c1e1 100644 --- a/src/ImageSharp/ColorSpaces/Lms.cs +++ b/src/ImageSharp/ColorSpaces/Lms.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -95,7 +96,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Lms({this.L:#0.##}, {this.M:#0.##}, {this.S:#0.##})"; + public override string ToString() => $"Lms({FloatToString(this.L, this.M, this.S)})"; /// public override bool Equals(object obj) => obj is Lms other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index 070083051..5ccabdfaa 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -6,6 +6,7 @@ using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation; using SixLabors.ImageSharp.PixelFormats; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -155,7 +156,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Rgb({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##})"; + public override string ToString() => $"Rgb({FloatToString(this.R, this.G, this.B)})"; /// public override bool Equals(object obj) => obj is Rgb other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index 7bc59ee76..bbf3f9db2 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -4,6 +4,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -91,7 +92,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"YCbCr({this.Y}, {this.Cb}, {this.Cr})"; + public override string ToString() => $"YCbCr({FloatToString(this.Y, this.Cb, this.Cr)})"; /// public override bool Equals(object obj) => obj is YCbCr other && this.Equals(other); diff --git a/src/ImageSharp/Common/Helpers/FloatToStringUtil.cs b/src/ImageSharp/Common/Helpers/FloatToStringUtil.cs new file mode 100644 index 000000000..fbb3f8750 --- /dev/null +++ b/src/ImageSharp/Common/Helpers/FloatToStringUtil.cs @@ -0,0 +1,11 @@ +using System.Globalization; +using System.Linq; + +namespace SixLabors.ImageSharp.Common.Helpers +{ + internal static class FloatToStringUtil + { + internal static string FloatToString(params float[] values) + => string.Join(", ", values.Select(v => v.ToString("#0.##", CultureInfo.InvariantCulture)).ToArray()); + } +} From fd9e8dc7dec6f6e10bbbd616ef1b4d27c7dffd8f Mon Sep 17 00:00:00 2001 From: j0rn Date: Tue, 16 Oct 2018 10:23:03 +0200 Subject: [PATCH 2/2] Using FormattableString.Invariant. --- src/ImageSharp/ColorSpaces/CieLab.cs | 3 +-- src/ImageSharp/ColorSpaces/CieLch.cs | 3 +-- src/ImageSharp/ColorSpaces/CieLchuv.cs | 3 +-- src/ImageSharp/ColorSpaces/CieLuv.cs | 3 +-- .../ColorSpaces/CieXyChromaticityCoordinates.cs | 3 +-- src/ImageSharp/ColorSpaces/CieXyy.cs | 3 +-- src/ImageSharp/ColorSpaces/CieXyz.cs | 3 +-- src/ImageSharp/ColorSpaces/Cmyk.cs | 3 +-- src/ImageSharp/ColorSpaces/Hsl.cs | 3 +-- src/ImageSharp/ColorSpaces/Hsv.cs | 3 +-- src/ImageSharp/ColorSpaces/HunterLab.cs | 3 +-- src/ImageSharp/ColorSpaces/LinearRgb.cs | 3 +-- src/ImageSharp/ColorSpaces/Lms.cs | 3 +-- src/ImageSharp/ColorSpaces/Rgb.cs | 3 +-- src/ImageSharp/ColorSpaces/YCbCr.cs | 3 +-- src/ImageSharp/Common/Helpers/FloatToStringUtil.cs | 11 ----------- 16 files changed, 15 insertions(+), 41 deletions(-) delete mode 100644 src/ImageSharp/Common/Helpers/FloatToStringUtil.cs diff --git a/src/ImageSharp/ColorSpaces/CieLab.cs b/src/ImageSharp/ColorSpaces/CieLab.cs index d7af04120..ea6df86e2 100644 --- a/src/ImageSharp/ColorSpaces/CieLab.cs +++ b/src/ImageSharp/ColorSpaces/CieLab.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -128,7 +127,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLab({FloatToString(this.L, this.A, this.B)})"; + public override string ToString() => FormattableString.Invariant($"CieLab({this.L:#0.##}, {this.A:#0.##}, {this.B:#0.##})"); /// public override bool Equals(object obj) => obj is CieLab other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieLch.cs b/src/ImageSharp/ColorSpaces/CieLch.cs index b0192b214..f1a7425e9 100644 --- a/src/ImageSharp/ColorSpaces/CieLch.cs +++ b/src/ImageSharp/ColorSpaces/CieLch.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -130,7 +129,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLch({FloatToString(this.L, this.C, this.H)})"; + public override string ToString() => FormattableString.Invariant($"CieLch({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})"); /// [MethodImpl(InliningOptions.ShortMethod)] diff --git a/src/ImageSharp/ColorSpaces/CieLchuv.cs b/src/ImageSharp/ColorSpaces/CieLchuv.cs index 3e0d654dd..256b5dc0f 100644 --- a/src/ImageSharp/ColorSpaces/CieLchuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLchuv.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -129,7 +128,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLchuv({FloatToString(this.L, this.C, this.H)})"; + public override string ToString() => FormattableString.Invariant($"CieLchuv({this.L:#0.##}, {this.C:#0.##}, {this.H:#0.##})"); /// public override bool Equals(object obj) => obj is CieLchuv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieLuv.cs b/src/ImageSharp/ColorSpaces/CieLuv.cs index e0c17224d..8fe073d6b 100644 --- a/src/ImageSharp/ColorSpaces/CieLuv.cs +++ b/src/ImageSharp/ColorSpaces/CieLuv.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -129,7 +128,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieLuv({FloatToString(this.L, this.U, this.V)})"; + public override string ToString() => FormattableString.Invariant($"CieLuv({this.L:#0.##}, {this.U:#0.##}, {this.V:#0.##})"); /// public override bool Equals(object obj) => obj is CieLuv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs index e29411f67..f625bb761 100644 --- a/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs +++ b/src/ImageSharp/ColorSpaces/CieXyChromaticityCoordinates.cs @@ -3,7 +3,6 @@ using System; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; // ReSharper disable CompareOfFloatsByEqualityOperator namespace SixLabors.ImageSharp.ColorSpaces @@ -68,7 +67,7 @@ namespace SixLabors.ImageSharp.ColorSpaces public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); /// - public override string ToString() => $"CieXyChromaticityCoordinates({FloatToString(this.X, this.Y)})"; + public override string ToString() => FormattableString.Invariant($"CieXyChromaticityCoordinates({this.X:#0.##}, {this.Y:#0.##})"); /// public override bool Equals(object obj) => obj is CieXyChromaticityCoordinates other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyy.cs b/src/ImageSharp/ColorSpaces/CieXyy.cs index a036e89c3..7137360e9 100644 --- a/src/ImageSharp/ColorSpaces/CieXyy.cs +++ b/src/ImageSharp/ColorSpaces/CieXyy.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -92,7 +91,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieXyy({FloatToString(this.X, this.Y, this.Yl)})"; + public override string ToString() => FormattableString.Invariant($"CieXyy({this.X:#0.##}, {this.Y:#0.##}, {this.Yl:#0.##})"); /// public override bool Equals(object obj) => obj is CieXyy other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/CieXyz.cs b/src/ImageSharp/ColorSpaces/CieXyz.cs index f6d6e285e..c0ed35660 100644 --- a/src/ImageSharp/ColorSpaces/CieXyz.cs +++ b/src/ImageSharp/ColorSpaces/CieXyz.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -95,7 +94,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"CieXyz({FloatToString(this.X, this.Y, this.Z)})"; + public override string ToString() => FormattableString.Invariant($"CieXyz({this.X:#0.##}, {this.Y:#0.##}, {this.Z:#0.##})"); /// public override bool Equals(object obj) => obj is CieXyz other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Cmyk.cs b/src/ImageSharp/ColorSpaces/Cmyk.cs index e351642de..634667c0c 100644 --- a/src/ImageSharp/ColorSpaces/Cmyk.cs +++ b/src/ImageSharp/ColorSpaces/Cmyk.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -100,7 +99,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Cmyk({FloatToString(this.C, this.M, this.Y, this.K)})"; + public override string ToString() => FormattableString.Invariant($"Cmyk({this.C:#0.##}, {this.M:#0.##}, {this.Y:#0.##}, {this.K:#0.##})"); /// public override bool Equals(object obj) => obj is Cmyk other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Hsl.cs b/src/ImageSharp/ColorSpaces/Hsl.cs index 5684d8184..f6e531df3 100644 --- a/src/ImageSharp/ColorSpaces/Hsl.cs +++ b/src/ImageSharp/ColorSpaces/Hsl.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -93,7 +92,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Hsl({FloatToString(this.H, this.S, this.L)})"; + public override string ToString() => FormattableString.Invariant($"Hsl({this.H:#0.##}, {this.S:#0.##}, {this.L:#0.##})"); /// public override bool Equals(object obj) => obj is Hsl other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Hsv.cs b/src/ImageSharp/ColorSpaces/Hsv.cs index 9d40a6d3f..631f03d09 100644 --- a/src/ImageSharp/ColorSpaces/Hsv.cs +++ b/src/ImageSharp/ColorSpaces/Hsv.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -91,7 +90,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Hsv({FloatToString(this.H, this.S, this.V)})"; + public override string ToString() => FormattableString.Invariant($"Hsv({this.H:#0.##}, {this.S:#0.##}, {this.V:#0.##})"); /// public override bool Equals(object obj) => obj is Hsv other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/HunterLab.cs b/src/ImageSharp/ColorSpaces/HunterLab.cs index 3e336ca68..f4fa29d31 100644 --- a/src/ImageSharp/ColorSpaces/HunterLab.cs +++ b/src/ImageSharp/ColorSpaces/HunterLab.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -127,7 +126,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"HunterLab({FloatToString(this.L, this.A, this.B)})"; + public override string ToString() => FormattableString.Invariant($"HunterLab({this.L:#0.##}, {this.A:#0.##}, {this.B:#0.##})"); /// public override bool Equals(object obj) => obj is HunterLab other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/LinearRgb.cs b/src/ImageSharp/ColorSpaces/LinearRgb.cs index c376a4d1d..ec6d18be2 100644 --- a/src/ImageSharp/ColorSpaces/LinearRgb.cs +++ b/src/ImageSharp/ColorSpaces/LinearRgb.cs @@ -5,7 +5,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -135,7 +134,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"LinearRgb({FloatToString(this.R, this.G, this.B)})"; + public override string ToString() => FormattableString.Invariant($"LinearRgb({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##})"); /// public override bool Equals(object obj) => obj is LinearRgb other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Lms.cs b/src/ImageSharp/ColorSpaces/Lms.cs index 823d1c1e1..0a8b7aa7b 100644 --- a/src/ImageSharp/ColorSpaces/Lms.cs +++ b/src/ImageSharp/ColorSpaces/Lms.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -96,7 +95,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Lms({FloatToString(this.L, this.M, this.S)})"; + public override string ToString() => FormattableString.Invariant($"Lms({this.L:#0.##}, {this.M:#0.##}, {this.S:#0.##})"); /// public override bool Equals(object obj) => obj is Lms other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/Rgb.cs b/src/ImageSharp/ColorSpaces/Rgb.cs index 5ccabdfaa..97fafbaf3 100644 --- a/src/ImageSharp/ColorSpaces/Rgb.cs +++ b/src/ImageSharp/ColorSpaces/Rgb.cs @@ -6,7 +6,6 @@ using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation; using SixLabors.ImageSharp.PixelFormats; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -156,7 +155,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"Rgb({FloatToString(this.R, this.G, this.B)})"; + public override string ToString() => FormattableString.Invariant($"Rgb({this.R:#0.##}, {this.G:#0.##}, {this.B:#0.##})"); /// public override bool Equals(object obj) => obj is Rgb other && this.Equals(other); diff --git a/src/ImageSharp/ColorSpaces/YCbCr.cs b/src/ImageSharp/ColorSpaces/YCbCr.cs index bbf3f9db2..6aa191c2d 100644 --- a/src/ImageSharp/ColorSpaces/YCbCr.cs +++ b/src/ImageSharp/ColorSpaces/YCbCr.cs @@ -4,7 +4,6 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; -using static SixLabors.ImageSharp.Common.Helpers.FloatToStringUtil; namespace SixLabors.ImageSharp.ColorSpaces { @@ -92,7 +91,7 @@ namespace SixLabors.ImageSharp.ColorSpaces } /// - public override string ToString() => $"YCbCr({FloatToString(this.Y, this.Cb, this.Cr)})"; + public override string ToString() => FormattableString.Invariant($"YCbCr({this.Y}, {this.Cb}, {this.Cr})"); /// public override bool Equals(object obj) => obj is YCbCr other && this.Equals(other); diff --git a/src/ImageSharp/Common/Helpers/FloatToStringUtil.cs b/src/ImageSharp/Common/Helpers/FloatToStringUtil.cs deleted file mode 100644 index fbb3f8750..000000000 --- a/src/ImageSharp/Common/Helpers/FloatToStringUtil.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Globalization; -using System.Linq; - -namespace SixLabors.ImageSharp.Common.Helpers -{ - internal static class FloatToStringUtil - { - internal static string FloatToString(params float[] values) - => string.Join(", ", values.Select(v => v.ToString("#0.##", CultureInfo.InvariantCulture)).ToArray()); - } -}