-
Notifications
You must be signed in to change notification settings - Fork 481
/
Point.cs
129 lines (117 loc) · 4.32 KB
/
Point.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.Spatial
{
using System;
using System.Runtime.Serialization;
using Newtonsoft.Json;
/// <summary>
/// Point geometry class in the Azure Cosmos DB service.
/// </summary>
[DataContract]
public sealed class Point : Geometry, IEquatable<Point>
{
/// <summary>
/// Initializes a new instance of the <see cref="Point" /> class in the Azure Cosmos DB service.
/// </summary>
/// <param name="longitude">
/// Longitude of the point.
/// </param>
/// <param name="latitude">
/// Latitude of the point.
/// </param>
public Point(double longitude, double latitude)
: this(new Position(longitude, latitude), new GeometryParams())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Point" /> class in the Azure Cosmos DB service.
/// </summary>
/// <param name="position">
/// Position of the point.
/// </param>
public Point(Position position)
: this(position, new GeometryParams())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Point" /> class in the Azure Cosmos DB service.
/// </summary>
/// <param name="position">
/// Point coordinates.
/// </param>
/// <param name="geometryParams">
/// Additional geometry parameters.
/// </param>
public Point(Position position, GeometryParams geometryParams)
: base(GeometryType.Point, geometryParams)
{
if (position == null)
{
throw new ArgumentNullException("position");
}
this.Position = position;
}
/// <summary>
/// Initializes a new instance of the <see cref="Point"/> class in the Azure Cosmos DB service.
/// </summary>
/// <remarks>
/// This constructor is used only during deserialization.
/// </remarks>
internal Point()
: base(GeometryType.Point, new GeometryParams())
{
}
/// <summary>
/// Gets point coordinates in the Azure Cosmos DB service.
/// </summary>
/// <value>
/// Coordinates of the point.
/// </value>
[DataMember(Name = "coordinates")]
[JsonProperty("coordinates", Required = Required.Always, Order = 1)]
public Position Position { get; private set; }
/// <summary>
/// Determines if this <see cref="Point"/> is equal to <paramref name="other" /> in the Azure Cosmos DB service.
/// </summary>
/// <param name="other"><see cref="Point"/> to compare to this <see cref="Point"/>.</param>
/// <returns><c>true</c> if objects are equal. <c>false</c> otherwise.</returns>
public bool Equals(Point other)
{
if (object.ReferenceEquals(null, other))
{
return false;
}
if (object.ReferenceEquals(this, other))
{
return true;
}
return base.Equals(other) && this.Position.Equals(other.Position);
}
/// <summary>
/// Determines whether the specified <see cref="Point" /> is equal to the current <see cref="Point" /> in the Azure Cosmos DB service.
/// </summary>
/// <returns>
/// true if the specified object is equal to the current object; otherwise, false.
/// </returns>
/// <param name="obj">The object to compare with the current object. </param>
public override bool Equals(object obj)
{
return this.Equals(obj as Point);
}
/// <summary>
/// Serves as a hash function for the <see cref="Point" /> type in the Azure Cosmos DB service.
/// </summary>
/// <returns>
/// A hash code for the current geometry.
/// </returns>
public override int GetHashCode()
{
unchecked
{
return (base.GetHashCode() * 397) ^ this.Position.GetHashCode();
}
}
}
}