summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Maps/Position.cs
blob: 17a865232c6e47a719cd882eee00e267340e985b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
´╗┐using System;

namespace Xamarin.Forms.Maps
{
	public struct Position
	{
		public Position(double latitude, double longitude)
		{
			Latitude = Math.Min(Math.Max(latitude, -90.0), 90.0);
			Longitude = Math.Min(Math.Max(longitude, -180.0), 180.0);
		}

		public double Latitude { get; }

		public double Longitude { get; }

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj))
				return false;
			if (obj.GetType() != GetType())
				return false;
			var other = (Position)obj;
			return Latitude == other.Latitude && Longitude == other.Longitude;
		}

		public override int GetHashCode()
		{
			unchecked
			{
				int hashCode = Latitude.GetHashCode();
				hashCode = (hashCode * 397) ^ Longitude.GetHashCode();
				return hashCode;
			}
		}

		public static bool operator ==(Position left, Position right)
		{
			return Equals(left, right);
		}

		public static bool operator !=(Position left, Position right)
		{
			return !Equals(left, right);
		}
	}
}