Made some changes to make my code more 'idiomatically C#.'

Patrick Branch [2016-07-30 10:46:55]
Made some changes to make my code more 'idiomatically C#.'
Filename
PokemonGo/RocketAPI/Client.cs
PokemonGo/RocketAPI/ICoordinate.cs
PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj
PokemonGo/RocketAPI/ProtoAdditions.cs
PokemonGo/RocketAPI/Window/LocationManager.cs
PokemonGo/RocketAPI/Window/MapForm.cs
diff --git a/PokemonGo/RocketAPI/Client.cs b/PokemonGo/RocketAPI/Client.cs
index 94ccfa9..00482da 100644
--- a/PokemonGo/RocketAPI/Client.cs
+++ b/PokemonGo/RocketAPI/Client.cs
@@ -416,14 +416,20 @@ namespace PokemonGo.RocketAPI
                         releasePokemonRequest);
         }

-        public double getCurrentLat()
+        public double CurrentLatitude
         {
-            return this._currentLat;
+            get
+            {
+                return this._currentLat;
+            }
         }

-        public double getCurrentLong()
+        public double CurrentLongitude
         {
-            return this._currentLng;
+            get
+            {
+                return this._currentLng;
+            }
         }

         public async Task<PlayerUpdateResponse> UpdatePlayerLocation(double lat, double lng)
diff --git a/PokemonGo/RocketAPI/ICoordinate.cs b/PokemonGo/RocketAPI/ICoordinate.cs
new file mode 100644
index 0000000..7acfc1c
--- /dev/null
+++ b/PokemonGo/RocketAPI/ICoordinate.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PokemonGo.RocketAPI
+{
+    public interface ICoordinate
+    {
+        double Latitude { get; }
+        double Longitude { get; }
+    }
+    public interface MetricSpace<T>
+    {
+        double distance(T t1, T t2);
+    }
+    public class CoordinateMetric : MetricSpace<ICoordinate>
+    {
+        public double distance(ICoordinate c1, ICoordinate c2)
+        {
+            double R = 6371;
+            Func<double, double> toRad = x => x * (Math.PI / 180);
+            double dLat = toRad(c2.Latitude - c1.Latitude);
+            double dLong = toRad(c2.Latitude - c2.Longitude);
+            double lat1 = toRad(c1.Latitude);
+            double lat2 = toRad(c2.Latitude);
+            double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
+                Math.Sin(dLong / 2) * Math.Sin(dLong / 2) * Math.Cos(lat1) * Math.Cos(lat2);
+            double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
+            return R * c;
+        }
+    }
+}
diff --git a/PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj b/PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj
index abde253..a7c2734 100644
--- a/PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj
+++ b/PokemonGo/RocketAPI/PokemonGo.RocketAPI.csproj
@@ -68,6 +68,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="ICoordinate.cs" />
     <Compile Include="Enums\AuthType.cs" />
     <Compile Include="Enums\MiscEnums.cs" />
     <Compile Include="Enums\RequestType.cs" />
@@ -92,6 +93,7 @@
     <Compile Include="Extensions\HttpClientExtensions.cs" />
     <Compile Include="Helpers\RandomHelper.cs" />
     <Compile Include="Helpers\RequestBuilder.cs" />
+    <Compile Include="ProtoAdditions.cs" />
     <Compile Include="Resources.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
diff --git a/PokemonGo/RocketAPI/ProtoAdditions.cs b/PokemonGo/RocketAPI/ProtoAdditions.cs
new file mode 100644
index 0000000..fc5ce6d
--- /dev/null
+++ b/PokemonGo/RocketAPI/ProtoAdditions.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PokemonGo.RocketAPI.GeneratedCode
+{
+    public partial class FortData : ICoordinate { }
+
+    public partial class MapPokemon : ICoordinate { }
+
+    public partial class WildPokemon : ICoordinate { }
+
+    public partial class SpawnPoint : ICoordinate { }
+
+}
diff --git a/PokemonGo/RocketAPI/Window/LocationManager.cs b/PokemonGo/RocketAPI/Window/LocationManager.cs
index 065febc..7813250 100644
--- a/PokemonGo/RocketAPI/Window/LocationManager.cs
+++ b/PokemonGo/RocketAPI/Window/LocationManager.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using PokemonGo.RocketAPI;

 namespace PokemonGo.RocketAPI.Window
 {
@@ -19,7 +20,7 @@ namespace PokemonGo.RocketAPI.Window

         public double getDistance(double lat, double lng)
         {
-            Coordinate currentLoc = new Coordinate(client.getCurrentLat(), client.getCurrentLong());
+            Coordinate currentLoc = new Coordinate(client.CurrentLatitude, client.CurrentLongitude);
             return currentLoc.distanceFrom(new Coordinate(lat, lng));
         }

@@ -29,33 +30,35 @@ namespace PokemonGo.RocketAPI.Window
             await Task.Delay((int)Math.Ceiling(waitTime));
             await client.UpdatePlayerLocation(lat, lng);
         }
+    }

-        public struct Coordinate
+    public class Coordinate : Tuple<double, double>, ICoordinate
+    {
+        public Coordinate(double item1, double item2) : base(item1, item2)
         {
+        }

-            public Coordinate(double lat, double lng)
+        public double Latitude
+        {
+            get
             {
-                this.latitude = lat;
-                this.longitude = lng;
+                return this.Item1;
             }
-            public double latitude;
-            public double longitude;
-
-            //returns distance in kilometers
-            public double distanceFrom(Coordinate c2)
+        }
+        public double Longitude
+        {
+            get
             {
-                double R = 6371;
-                Func<double, double> toRad = x => x * (Math.PI / 180);
-                double dLat = toRad(c2.latitude - this.latitude);
-                double dLong = toRad(c2.longitude - c2.longitude);
-                double lat1 = toRad(this.latitude);
-                double lat2 = toRad(c2.latitude);
-                double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
-                    Math.Sin(dLong / 2) * Math.Sin(dLong / 2) * Math.Cos(lat1) * Math.Cos(lat2);
-                double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
-                return R * c;
+                return this.Item2;
             }
         }
+
+        public double distanceFrom(ICoordinate c2)
+        {
+            return new CoordinateMetric().distance(this, c2);
+        }
+
+
     }

 }
diff --git a/PokemonGo/RocketAPI/Window/MapForm.cs b/PokemonGo/RocketAPI/Window/MapForm.cs
index 595a80b..cc49274 100644
--- a/PokemonGo/RocketAPI/Window/MapForm.cs
+++ b/PokemonGo/RocketAPI/Window/MapForm.cs
@@ -50,7 +50,7 @@ namespace PokemonGo.RocketAPI.Window

         private void tmrUpdate_Tick(object sender, EventArgs e)
         {
-            gMapControl1.Position = new PointLatLng(Client.getCurrentLat(), Client.getCurrentLong());
+            gMapControl1.Position = new PointLatLng(Client.CurrentLatitude, Client.CurrentLongitude);
         }
     }
 }
You may download the files in Public Git.