|
21 | 21 | namespace MongoDB.Driver
|
22 | 22 | {
|
23 | 23 | /// <summary>
|
24 |
| - /// Represents a GeoNearLocation (either a legacy coordinate pair or a GeoJsonPoint). |
| 24 | + /// Represents a GeoNearPoint (wraps either an XYPoint or a GeoJsonPoint). |
25 | 25 | /// </summary>
|
26 | 26 | public abstract class GeoNearPoint
|
27 | 27 | {
|
28 |
| - // public static methods |
| 28 | + // implicit conversions |
29 | 29 | /// <summary>
|
30 |
| - /// Creates a GeoNearLocation.GeoJson{TCoordinates} from a GeoJsonPoint{TCoordinates}. |
| 30 | + /// Implicit conversion to wrap an XYPoint in a GeoNearPoint value. |
31 | 31 | /// </summary>
|
32 |
| - /// <typeparam name="TCoordinates">The type of the coordinates.</typeparam> |
33 |
| - /// <param name="point">The GeoJson point.</param> |
34 |
| - /// <returns>A GeoNearLocation.GeoJson{TCoordinates}.</returns> |
35 |
| - public static GeoNearPoint.GeoJson<TCoordinates> From<TCoordinates>(GeoJsonPoint<TCoordinates> point) where TCoordinates : GeoJsonCoordinates |
| 32 | + /// <param name="value">The value.</param> |
| 33 | + /// <returns>A GeoNearPoint value.</returns> |
| 34 | + public static implicit operator GeoNearPoint(XYPoint value) |
36 | 35 | {
|
37 |
| - return new GeoJson<TCoordinates>(point); |
| 36 | + return new Legacy(value); |
38 | 37 | }
|
39 | 38 |
|
40 | 39 | /// <summary>
|
41 |
| - /// Creates a GeoNearPoint from legacy x and y coordinates. |
| 40 | + /// Implicit conversion to wrap a 2D GeoJson point in a GeoNearPoint value. |
42 | 41 | /// </summary>
|
43 |
| - /// <param name="x">The x value.</param> |
44 |
| - /// <param name="y">The y value.</param> |
45 |
| - /// <returns></returns> |
46 |
| - public static GeoNearPoint.Legacy From(double x, double y) |
| 42 | + /// <param name="value">The value.</param> |
| 43 | + /// <returns>A GeoNearPoint value.</returns> |
| 44 | + public static implicit operator GeoNearPoint(GeoJsonPoint<GeoJson2DCoordinates> value) |
| 45 | + { |
| 46 | + return new GeoJson<GeoJson2DCoordinates>(value); |
| 47 | + } |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Implicit conversion to wrap a 2D GeoJson point in a GeoNearPoint value. |
| 51 | + /// </summary> |
| 52 | + /// <param name="value">The value.</param> |
| 53 | + /// <returns>A GeoNearPoint value.</returns> |
| 54 | + public static implicit operator GeoNearPoint(GeoJsonPoint<GeoJson2DGeographicCoordinates> value) |
47 | 55 | {
|
48 |
| - return new Legacy(x, y); |
| 56 | + return new GeoJson<GeoJson2DGeographicCoordinates>(value); |
49 | 57 | }
|
50 | 58 |
|
51 |
| - // public methods |
52 | 59 | /// <summary>
|
53 |
| - /// Converts the GeoNearLocation into a BsonValue for the GeoNear command. |
| 60 | + /// Implicit conversion to wrap a 2D GeoJson point in a GeoNearPoint value. |
| 61 | + /// </summary> |
| 62 | + /// <param name="value">The value.</param> |
| 63 | + /// <returns>A GeoNearPoint value.</returns> |
| 64 | + public static implicit operator GeoNearPoint(GeoJsonPoint<GeoJson2DProjectedCoordinates> value) |
| 65 | + { |
| 66 | + return new GeoJson<GeoJson2DProjectedCoordinates>(value); |
| 67 | + } |
| 68 | + |
| 69 | + // internal methods |
| 70 | + /// <summary> |
| 71 | + /// Converts the GeoNearPoint into a BsonValue for the GeoNear command. |
54 | 72 | /// </summary>
|
55 | 73 | /// <returns></returns>
|
56 |
| - public abstract BsonValue ToGeoNearCommandField(); |
| 74 | + internal abstract BsonValue ToGeoNearCommandValue(); |
57 | 75 |
|
58 | 76 | // nested classes
|
59 | 77 | /// <summary>
|
60 |
| - /// Represents a GeoNearLocation expressed as a legacy coordinate pair. |
| 78 | + /// Represents a GeoNearPoint that wraps an XYPoint. |
61 | 79 | /// </summary>
|
62 | 80 | public class Legacy : GeoNearPoint
|
63 | 81 | {
|
64 | 82 | // private fields
|
65 |
| - private readonly double _x; |
66 |
| - private readonly double _y; |
| 83 | + private readonly XYPoint _value; |
67 | 84 |
|
68 | 85 | // constructors
|
69 | 86 | /// <summary>
|
70 | 87 | /// Initializes a new instance of the <see cref="Legacy"/> class.
|
71 | 88 | /// </summary>
|
72 |
| - /// <param name="x">The x value.</param> |
73 |
| - /// <param name="y">The y value.</param> |
74 |
| - public Legacy(double x, double y) |
| 89 | + /// <param name="value">The value.</param> |
| 90 | + public Legacy(XYPoint value) |
75 | 91 | {
|
76 |
| - _x = x; |
77 |
| - _y = y; |
| 92 | + _value = value; |
78 | 93 | }
|
79 | 94 |
|
80 | 95 | // public properties
|
81 | 96 | /// <summary>
|
82 |
| - /// Gets the X value. |
83 |
| - /// </summary> |
84 |
| - /// <value> |
85 |
| - /// The X value. |
86 |
| - /// </value> |
87 |
| - public double X |
88 |
| - { |
89 |
| - get { return _x; } |
90 |
| - } |
91 |
| - |
92 |
| - /// <summary> |
93 |
| - /// Gets the Y value. |
| 97 | + /// Gets the value. |
94 | 98 | /// </summary>
|
95 | 99 | /// <value>
|
96 |
| - /// The Y value. |
| 100 | + /// The value. |
97 | 101 | /// </value>
|
98 |
| - public double Y |
| 102 | + public XYPoint Value |
99 | 103 | {
|
100 |
| - get { return _y; } |
| 104 | + get { return _value; } |
101 | 105 | }
|
102 | 106 |
|
103 |
| - // public methods |
| 107 | + // internal methods |
104 | 108 | /// <summary>
|
105 |
| - /// Converts the GeoNearLocation into a BsonValue for the GeoNear command. |
| 109 | + /// Converts the GeoNearPoint into a BsonValue for the GeoNear command. |
106 | 110 | /// </summary>
|
107 |
| - /// <returns></returns> |
108 |
| - public override BsonValue ToGeoNearCommandField() |
| 111 | + /// <returns>A BsonValue.</returns> |
| 112 | + internal override BsonValue ToGeoNearCommandValue() |
109 | 113 | {
|
110 |
| - return new BsonArray { _x, _y }; |
| 114 | + return new BsonArray { _value.X, _value.Y }; |
111 | 115 | }
|
112 | 116 | }
|
113 | 117 |
|
114 | 118 | /// <summary>
|
115 |
| - /// Represents a GeoNearLocation expressed as a GeoJsonPoint. |
| 119 | + /// Represents a GeoNearPoint that wraps a GeoJsonPoint. |
116 | 120 | /// </summary>
|
117 | 121 | /// <typeparam name="TCoordinates">The type of the coordinates.</typeparam>
|
118 | 122 | public class GeoJson<TCoordinates> : GeoNearPoint where TCoordinates : GeoJsonCoordinates
|
119 | 123 | {
|
120 | 124 | // private fields
|
121 |
| - private readonly GeoJsonPoint<TCoordinates> _point; |
| 125 | + private readonly GeoJsonPoint<TCoordinates> _value; |
122 | 126 |
|
123 | 127 | // constructors
|
124 | 128 | /// <summary>
|
125 | 129 | /// Initializes a new instance of the <see cref="GeoJson{TCoordinates}"/> class.
|
126 | 130 | /// </summary>
|
127 |
| - /// <param name="point">The point.</param> |
128 |
| - public GeoJson(GeoJsonPoint<TCoordinates> point) |
| 131 | + /// <param name="value">The value.</param> |
| 132 | + public GeoJson(GeoJsonPoint<TCoordinates> value) |
129 | 133 | {
|
130 |
| - _point = point; |
| 134 | + _value = value; |
131 | 135 | }
|
132 | 136 |
|
133 | 137 | // public properties
|
134 | 138 | /// <summary>
|
135 |
| - /// Gets the point. |
| 139 | + /// Gets the value. |
136 | 140 | /// </summary>
|
137 | 141 | /// <value>
|
138 |
| - /// The point. |
| 142 | + /// The value. |
139 | 143 | /// </value>
|
140 |
| - public GeoJsonPoint<TCoordinates> Point |
| 144 | + public GeoJsonPoint<TCoordinates> Value |
141 | 145 | {
|
142 |
| - get { return _point; } |
| 146 | + get { return _value; } |
143 | 147 | }
|
144 | 148 |
|
145 |
| - // public methods |
| 149 | + // internal methods |
146 | 150 | /// <summary>
|
147 |
| - /// Converts the GeoNearLocation into a BsonValue for the GeoNear command. |
| 151 | + /// Converts the GeoNearPoint into a BsonValue for the GeoNear command. |
148 | 152 | /// </summary>
|
149 |
| - /// <returns></returns> |
150 |
| - public override BsonValue ToGeoNearCommandField() |
| 153 | + /// <returns>A BsonValue.</returns> |
| 154 | + internal override BsonValue ToGeoNearCommandValue() |
151 | 155 | {
|
152 | 156 | var document = new BsonDocument();
|
153 | 157 | using (var writer = new BsonDocumentWriter(document, BsonDocumentWriterSettings.Defaults))
|
154 | 158 | {
|
155 |
| - new GeoJsonPointSerializer<TCoordinates>().Serialize(writer, typeof(GeoJsonPoint<TCoordinates>), _point, null); |
| 159 | + new GeoJsonPointSerializer<TCoordinates>().Serialize(writer, typeof(GeoJsonPoint<TCoordinates>), _value, null); |
156 | 160 | }
|
157 | 161 | return document;
|
158 | 162 | }
|
|
0 commit comments