Skip to content

Commit

Permalink
Updated .nuspec and README.md to include string format
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed May 6, 2016
1 parent 2805129 commit dd49ed5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
10 changes: 5 additions & 5 deletions NetFabric.Angle.UnitTests/AngleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

}

Expand Down
6 changes: 2 additions & 4 deletions NetFabric.Angle.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</description>
<releaseNotes>
+ Added Lerp
+ Added SerializableAttribute when on .NET 3.5
+ Added AngleRangeAttribute
+ Added string format
</releaseNotes>
<copyright>2016 Antão Almada</copyright>
<language>en-US</language>
Expand Down
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```

0 comments on commit dd49ed5

Please sign in to comment.