From dd49ed5eb273cdc6253b644acf09c5c535850bb2 Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Fri, 6 May 2016 22:09:42 +0100 Subject: [PATCH] Updated .nuspec and README.md to include string format --- NetFabric.Angle.UnitTests/AngleTest.cs | 10 +++--- NetFabric.Angle.nuspec | 6 ++-- README.md | 42 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/NetFabric.Angle.UnitTests/AngleTest.cs b/NetFabric.Angle.UnitTests/AngleTest.cs index e77286a..7119da2 100644 --- a/NetFabric.Angle.UnitTests/AngleTest.cs +++ b/NetFabric.Angle.UnitTests/AngleTest.cs @@ -565,11 +565,11 @@ public void ToStringIsDefinedCorrectly() Assert.AreEqual("12° 34' 56,78\"", Angle.FromDegrees(12, 34, 56.78).ToString("S2", new CultureInfo("pt-PT"))); Assert.AreEqual("200,00", Angle.Straight.ToString("G2", new CultureInfo("pt-PT"))); - Assert.AreEqual("Radians: 3.14", String.Format("Radians: {0:R2}", Angle.Straight)); - Assert.AreEqual("Degrees: 180.00", String.Format("Degrees: {0:D2}", Angle.Straight)); - Assert.AreEqual("Degrees: 12° 34.56'", String.Format("Degrees: {0:M2}", Angle.FromDegrees(12, 34.56))); - Assert.AreEqual("Degrees: 12° 34' 56.78\"", String.Format("Degrees: {0:S2}", Angle.FromDegrees(12, 34, 56.78))); - Assert.AreEqual("Gradians: 200.00", String.Format("Gradians: {0:G2}", Angle.Straight)); + Assert.AreEqual("Radians: 3,14", String.Format(new CultureInfo("pt-PT"), "Radians: {0:R2}", Angle.Straight)); + Assert.AreEqual("Degrees: 180,00", String.Format(new CultureInfo("pt-PT"), "Degrees: {0:D2}", Angle.Straight)); + Assert.AreEqual("Degrees: 12° 34,56'", String.Format(new CultureInfo("pt-PT"), "Degrees: {0:M2}", Angle.FromDegrees(12, 34.56))); + Assert.AreEqual("Degrees: 12° 34' 56,78\"", String.Format(new CultureInfo("pt-PT"), "Degrees: {0:S2}", Angle.FromDegrees(12, 34, 56.78))); + Assert.AreEqual("Gradians: 200,00", String.Format(new CultureInfo("pt-PT"), "Gradians: {0:G2}", Angle.Straight)); } diff --git a/NetFabric.Angle.nuspec b/NetFabric.Angle.nuspec index 2bbf3c6..c3dfe48 100644 --- a/NetFabric.Angle.nuspec +++ b/NetFabric.Angle.nuspec @@ -13,12 +13,10 @@ Implements a structure representing an angle. The angle is represented internaly in radians but can be created and read in radians, degrees and gradians. Also supports arcminutes and arcseconds, useful for GPS coordinates. The explicit declaration of the units in creation and reading methods reduces the tipical confusion when dealing with angles. -Includes reduction, reference angle, comparison, classification and trigonometry operations. +Includes linear interpolation, reduction, reference angle, comparison, classification and trigonometry operations. -+ Added Lerp -+ Added SerializableAttribute when on .NET 3.5 -+ Added AngleRangeAttribute ++ Added string format 2016 Antão Almada en-US diff --git a/README.md b/README.md index 7e47504..890669e 100644 --- a/README.md +++ b/README.md @@ -170,3 +170,45 @@ var isAcute = Angle.IsAcute(Angle.FromDegrees(45.0)); // true var isAcute = Angle.IsAcute(Angle.FromDegrees(-45.0)); // true var isAcute = Angle.IsAcute(Angle.FromDegrees(315.0)); // false ``` + +### String format + +The ToString() method supports the following formats: + +```csharp +Angle.FromDegrees(45.0).ToString(); // 0.785398163397448 +Angle.FromDegrees(45.0).ToString("R"); // 0.785398163397448 +Angle.FromDegrees(45.0).ToString("D"); // 45 +Angle.FromDegrees(45.0).ToString("M"); // 45° 0' +Angle.FromDegrees(45.0).ToString("S"); // 45° 0' 0" +Angle.FromDegrees(45.0).ToString("G"); // 50 +``` + +Supports the number of decimal places: + +```csharp +Angle.FromDegrees(45.0).ToString("R3"); // 0.785 +Angle.FromDegrees(45.0).ToString("D3"); // 45.000 +Angle.FromDegrees(45.0).ToString("M3"); // 45° 0.000' +Angle.FromDegrees(45.0).ToString("S3"); // 45° 0' 0.000" +Angle.FromDegrees(45.0).ToString("G3"); // 50.000 +``` + +Supports culture (except for .NET Micro Framework): + +```csharp +Angle.FromDegrees(45.0).ToString("R3", new CultureInfo("pt-PT")); // 0,785 +Angle.FromDegrees(45.0).ToString("D3", new CultureInfo("pt-PT")); // 45,000 +Angle.FromDegrees(45.0).ToString("M3", new CultureInfo("pt-PT")); // 45° 0,000' +Angle.FromDegrees(45.0).ToString("S3", new CultureInfo("pt-PT")); // 45° 0' 0,000" +Angle.FromDegrees(45.0).ToString("G3", new CultureInfo("pt-PT")); // 50,000 +``` + +These formats can also be used in String.Format(): + +```csharp +String.Format("Radians: {0:R3}", Angle.FromDegrees(45.0)); // Radians: 0.785 +String.Format("Degrees: {0:S3}", Angle.FromDegrees(45.0)); // Degrees: 45° 0' 0.000" +String.Format(new CultureInfo("pt-PT"), "Degrees: {0:S3}", Angle.FromDegrees(45.0)); // Degrees: 45° 0' 0,000" +``` +