Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2287 - 1

2
namespace GMap.NET
3
{
4
   using System;
5
   using System.Globalization;
6
 
7
   /// <summary>
8
   /// the point of coordinates
9
   /// </summary>
10
   [Serializable]
11
   public struct PointLatLng
12
   {
13
      public static readonly PointLatLng Empty = new PointLatLng();
14
      private double lat;
15
      private double lng;
16
 
17
      bool NotEmpty;
18
 
19
      public PointLatLng(double lat, double lng)
20
      {
21
         this.lat = lat;
22
         this.lng = lng;
23
         NotEmpty = true;
24
      }
25
 
26
      /// <summary>
27
      /// returns true if coordinates wasn't assigned
28
      /// </summary>
29
      public bool IsEmpty
30
      {
31
         get
32
         {
33
            return !NotEmpty;
34
         }
35
      }
36
 
37
      public double Lat
38
      {
39
         get
40
         {
41
            return this.lat;
42
         }
43
         set
44
         {
45
            this.lat = value;
46
            NotEmpty = true;
47
         }
48
      }
49
 
50
      public double Lng
51
      {
52
         get
53
         {
54
            return this.lng;
55
         }
56
         set
57
         {
58
            this.lng = value;
59
            NotEmpty = true;
60
         }
61
      }
62
 
63
      public static PointLatLng operator +(PointLatLng pt, SizeLatLng sz)
64
      {
65
         return Add(pt, sz);
66
      }
67
 
68
      public static PointLatLng operator -(PointLatLng pt, SizeLatLng sz)
69
      {
70
         return Subtract(pt, sz);
71
      }
72
 
73
      public static SizeLatLng operator -(PointLatLng pt1, PointLatLng pt2)
74
      {
75
          return new SizeLatLng(pt1.Lat - pt2.Lat, pt2.Lng - pt1.Lng);
76
      }
77
 
78
      public static bool operator ==(PointLatLng left, PointLatLng right)
79
      {
80
         return ((left.Lng == right.Lng) && (left.Lat == right.Lat));
81
      }
82
 
83
      public static bool operator !=(PointLatLng left, PointLatLng right)
84
      {
85
         return !(left == right);
86
      }
87
 
88
      public static PointLatLng Add(PointLatLng pt, SizeLatLng sz)
89
      {
90
         return new PointLatLng(pt.Lat - sz.HeightLat, pt.Lng + sz.WidthLng);
91
      }
92
 
93
      public static PointLatLng Subtract(PointLatLng pt, SizeLatLng sz)
94
      {
95
         return new PointLatLng(pt.Lat + sz.HeightLat, pt.Lng - sz.WidthLng);
96
      }
97
 
98
      public override bool Equals(object obj)
99
      {
100
         if(!(obj is PointLatLng))
101
         {
102
            return false;
103
         }
104
         PointLatLng tf = (PointLatLng)obj;
105
         return (((tf.Lng == this.Lng) && (tf.Lat == this.Lat)) && tf.GetType().Equals(base.GetType()));
106
      }
107
 
108
      public void Offset(PointLatLng pos)
109
      {
110
         this.Offset(pos.Lat, pos.Lng);
111
      }
112
 
113
      public void Offset(double lat, double lng)
114
      {
115
         this.Lng += lng;
116
         this.Lat -= lat;
117
      }
118
 
119
      public override int GetHashCode()
120
      {
121
         return (this.Lng.GetHashCode() ^ this.Lat.GetHashCode());
122
      }
123
 
124
      public override string ToString()
125
      {
126
         return string.Format(CultureInfo.CurrentCulture, "{{Lat={0}, Lng={1}}}", this.Lat, this.Lng);
127
      }
128
   }
129
}