Guest User

Untitled

a guest
Jul 21st, 2011
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. public struct GeoCoordinate : IEquatable<GeoCoordinate>
  2. {
  3.     private const float SecondsInDegree = 3600f;
  4.  
  5.     private readonly float latitude;  // Expressed in seconds of degree, positive values for north
  6.     private readonly float longitude; // Expressed in seconds of degree, positive values for east
  7.  
  8.     /// <summary>
  9.     /// Initializes a new instance of the <see cref="GeoCoordinate"/> class with the specified latitude and longitude.
  10.     /// </summary>
  11.     /// <param name="latitude">The latitude in degrees.</param>
  12.     /// <param name="longitude">The longitude in degrees.</param>
  13.     public GeoCoordinate(float latitude, float longitude) : this()
  14.     {
  15.         this.latitude = latitude * SecondsInDegree;
  16.         this.longitude = longitude * SecondsInDegree;
  17.     }
  18.  
  19.     public float Latitude
  20.     {
  21.         get { return latitude; }
  22.     }
  23.  
  24.     public float Longitude
  25.     {
  26.         get { return longitude; }
  27.     }
  28.  
  29.  
  30.     public override bool Equals(object other)
  31.     {
  32.         if (other == null || other.GetType() != typeof(GeoCoordinate)) {
  33.             return false;
  34.         }
  35.  
  36.         return this.Equals((GeoCoordinate)other);
  37.  
  38.     }
  39.  
  40.     public bool Equals(GeoCoordinate other)
  41.     {
  42.         return this.latitude == other.latitude && this.longitude == other.longitude;
  43.     }
  44.  
  45.     public override int GetHashCode()
  46.     {
  47.         return latitude.GetHashCode() ^ longitude.GetHashCode();
  48.     }
  49.  
  50.     public static bool operator==(GeoCoordinate lhs, GeoCoordinate rhs)
  51.     {
  52.         return lhs.Equals(rhs);
  53.     }
  54.  
  55.     public static bool operator!=(GeoCoordinate lhs, GeoCoordinate rhs)
  56.     {
  57.         return !lhs.Equals(rhs);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment