diff --git a/NetFabric.Angle.Shared/Angle.Net.cs b/NetFabric.Angle.Shared/Angle.Net.cs index 6960398..ecfa05e 100644 --- a/NetFabric.Angle.Shared/Angle.Net.cs +++ b/NetFabric.Angle.Shared/Angle.Net.cs @@ -1,7 +1,9 @@ using System; +using System.Diagnostics; namespace NetFabric { + [DebuggerTypeProxy(typeof(AngleDebugView))] public partial struct Angle : IEquatable , IComparable diff --git a/NetFabric.Angle.Shared/Angle.cs b/NetFabric.Angle.Shared/Angle.cs index 7b7f290..c55c6b4 100644 --- a/NetFabric.Angle.Shared/Angle.cs +++ b/NetFabric.Angle.Shared/Angle.cs @@ -1,11 +1,12 @@ using System; -using System.Globalization; +using System.Diagnostics; namespace NetFabric { /// /// Represents an angle. /// + [DebuggerDisplay("{ToDegrees()}°")] public partial struct Angle { /// @@ -801,7 +802,7 @@ string FormatString(string format, IFormatProvider formatProvider) case 'R': return FormatString(ToRadians(), doubleFormat, formatProvider); case 'D': - return FormatString(ToDegrees(), doubleFormat, formatProvider); + return FormatString(ToDegrees(), doubleFormat, formatProvider) + "°"; case 'M': { int degrees; diff --git a/NetFabric.Angle.Shared/AngleDebugView.cs b/NetFabric.Angle.Shared/AngleDebugView.cs new file mode 100644 index 0000000..9e7a255 --- /dev/null +++ b/NetFabric.Angle.Shared/AngleDebugView.cs @@ -0,0 +1,24 @@ +using System; + +namespace NetFabric +{ + public class AngleDebugView + { + readonly Angle angle; + + public AngleDebugView(Angle angle) + { + this.angle = angle; + } + + public string Radians { get { return angle.ToString("R"); } } + + public string Degrees { get { return angle.ToString("D"); } } + + public string DegreesMinutes { get { return angle.ToString("M"); } } + + public string DegreesMinutesSeconds { get { return angle.ToString("S"); } } + + public string Gradians { get { return angle.ToString("G"); } } + } +} diff --git a/NetFabric.Angle.Shared/NetFabric.Angle.Shared.projitems b/NetFabric.Angle.Shared/NetFabric.Angle.Shared.projitems index c3c8cd7..c60128e 100644 --- a/NetFabric.Angle.Shared/NetFabric.Angle.Shared.projitems +++ b/NetFabric.Angle.Shared/NetFabric.Angle.Shared.projitems @@ -11,6 +11,7 @@ + diff --git a/NetFabric.Angle.UnitTests/AngleTest.cs b/NetFabric.Angle.UnitTests/AngleTest.cs index 7119da2..a98cbaa 100644 --- a/NetFabric.Angle.UnitTests/AngleTest.cs +++ b/NetFabric.Angle.UnitTests/AngleTest.cs @@ -536,37 +536,37 @@ public void ToStringIsDefinedCorrectly() Assert.AreEqual("3.14159265358979", Angle.Straight.ToString()); Assert.AreEqual("3.14159265358979", Angle.Straight.ToString("R")); - Assert.AreEqual("180", Angle.Straight.ToString("D")); + Assert.AreEqual("180°", Angle.Straight.ToString("D")); Assert.AreEqual("12° 34.56'", Angle.FromDegrees(12, 34.56).ToString("M")); Assert.AreEqual("12° 34' 56.7800000000018\"", Angle.FromDegrees(12, 34, 56.78).ToString("S")); Assert.AreEqual("200", Angle.Straight.ToString("G")); Assert.AreEqual("3,14159265358979", Angle.Straight.ToString("R", new CultureInfo("pt-PT"))); - Assert.AreEqual("180", Angle.Straight.ToString("D", new CultureInfo("pt-PT"))); + Assert.AreEqual("180°", Angle.Straight.ToString("D", new CultureInfo("pt-PT"))); Assert.AreEqual("12° 34,56'", Angle.FromDegrees(12, 34.56).ToString("M", new CultureInfo("pt-PT"))); Assert.AreEqual("12° 34' 56,7800000000018\"", Angle.FromDegrees(12, 34, 56.78).ToString("S", new CultureInfo("pt-PT"))); Assert.AreEqual("200", Angle.Straight.ToString("G", new CultureInfo("pt-PT"))); Assert.AreEqual("Radians: 3.14159265358979", String.Format("Radians: {0:R}", Angle.Straight)); - Assert.AreEqual("Degrees: 180", String.Format("Degrees: {0:D}", Angle.Straight)); + Assert.AreEqual("Degrees: 180°", String.Format("Degrees: {0:D}", Angle.Straight)); Assert.AreEqual("Degrees: 12° 34.56'", String.Format("Degrees: {0:M}", Angle.FromDegrees(12, 34.56))); Assert.AreEqual("Degrees: 12° 34' 56.7800000000018\"", String.Format("Degrees: {0:S}", Angle.FromDegrees(12, 34, 56.78))); Assert.AreEqual("Gradians: 200", String.Format("Gradians: {0:G}", Angle.Straight)); Assert.AreEqual("3.14", Angle.Straight.ToString("R2")); - Assert.AreEqual("180.00", Angle.Straight.ToString("D2")); + Assert.AreEqual("180.00°", Angle.Straight.ToString("D2")); Assert.AreEqual("12° 34.56'", Angle.FromDegrees(12, 34.56).ToString("M2")); Assert.AreEqual("12° 34' 56.78\"", Angle.FromDegrees(12, 34, 56.78).ToString("S2")); Assert.AreEqual("200.00", Angle.Straight.ToString("G2")); Assert.AreEqual("3,14", Angle.Straight.ToString("R2", new CultureInfo("pt-PT"))); - Assert.AreEqual("180,00", Angle.Straight.ToString("D2", new CultureInfo("pt-PT"))); + Assert.AreEqual("180,00°", Angle.Straight.ToString("D2", new CultureInfo("pt-PT"))); Assert.AreEqual("12° 34,56'", Angle.FromDegrees(12, 34.56).ToString("M2", new CultureInfo("pt-PT"))); 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(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: 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 c3dfe48..6b16e31 100644 --- a/NetFabric.Angle.nuspec +++ b/NetFabric.Angle.nuspec @@ -16,7 +16,7 @@ The explicit declaration of the units in creation and reading methods reduces th Includes linear interpolation, reduction, reference angle, comparison, classification and trigonometry operations. -+ Added string format ++ Added debug visualization 2016 Antão Almada en-US