Skip to content

Commit

Permalink
Merge pull request #4 from NetFabric/DebugVisualizer
Browse files Browse the repository at this point in the history
Added debugger vizualizing features
  • Loading branch information
aalmada committed May 11, 2016
2 parents 4d2bfe2 + 1f5f8b1 commit 9079a4a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
2 changes: 2 additions & 0 deletions NetFabric.Angle.Shared/Angle.Net.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Diagnostics;

namespace NetFabric
{
[DebuggerTypeProxy(typeof(AngleDebugView))]
public partial struct Angle
: IEquatable<Angle>
, IComparable
Expand Down
5 changes: 3 additions & 2 deletions NetFabric.Angle.Shared/Angle.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Globalization;
using System.Diagnostics;

namespace NetFabric
{
/// <summary>
/// Represents an angle.
/// </summary>
[DebuggerDisplay("{ToDegrees()}°")]
public partial struct Angle
{
/// <summary>
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions NetFabric.Angle.Shared/AngleDebugView.cs
Original file line number Diff line number Diff line change
@@ -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"); } }
}
}
1 change: 1 addition & 0 deletions NetFabric.Angle.Shared/NetFabric.Angle.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Angle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Angle.Net.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AngleDebugView.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AngleRangeAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.Net.cs" />
Expand Down
12 changes: 6 additions & 6 deletions NetFabric.Angle.UnitTests/AngleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion NetFabric.Angle.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</description>
<releaseNotes>
+ Added string format
+ Added debug visualization
</releaseNotes>
<copyright>2016 Antão Almada</copyright>
<language>en-US</language>
Expand Down

0 comments on commit 9079a4a

Please sign in to comment.