33// Copyright © Joerg Battermann 2014
44// </copyright>
55// <summary>
6- // Defines the Geographic Position type <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.1">GeographicPosition</see>.
6+ // Defines the Geographic Position type GeographicPosition.
7+ // See https://tools.ietf.org/html/rfc7946#section-3.1.1
78// </summary>
89// --------------------------------------------------------------------------------------------------------------------
910
1516namespace GeoJSON . Net . Geometry
1617{
1718 /// <summary>
18- /// Defines the Geographic Position type
19- /// <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.1">Position</see>.
19+ /// Defines the Geographic Position type.
2020 /// </summary>
21+ /// <remarks>
22+ /// See https://tools.ietf.org/html/rfc7946#section-3.1.1
23+ /// </remarks>
2124 public class GeographicPosition : Position , IEqualityComparer < GeographicPosition > , IEquatable < GeographicPosition >
2225 {
2326 private static readonly NullableDoubleTenDecimalPlaceComparer DoubleComparer = new NullableDoubleTenDecimalPlaceComparer ( ) ;
2427
28+ private readonly double ? [ ] _coordinates ;
29+
2530 /// <summary>
26- /// Initializes a new instance of the <see cref="GeographicPosition" /> class.
31+ /// Initializes a new instance of the <see cref="GeographicPosition" /> class.
2732 /// </summary>
2833 /// <param name="latitude">The latitude.</param>
2934 /// <param name="longitude">The longitude.</param>
@@ -37,7 +42,7 @@ public GeographicPosition(double latitude, double longitude, double? altitude =
3742 }
3843
3944 /// <summary>
40- /// Initializes a new instance of the <see cref="GeographicPosition" /> class.
45+ /// Initializes a new instance of the <see cref="GeographicPosition" /> class.
4146 /// </summary>
4247 /// <param name="latitude">The latitude, e.g. '38.889722'.</param>
4348 /// <param name="longitude">The longitude, e.g. '-77.008889'.</param>
@@ -47,35 +52,35 @@ public GeographicPosition(string latitude, string longitude, string altitude = n
4752 {
4853 if ( latitude == null )
4954 {
50- throw new ArgumentNullException ( " latitude" ) ;
55+ throw new ArgumentNullException ( nameof ( latitude ) ) ;
5156 }
5257
5358 if ( longitude == null )
5459 {
55- throw new ArgumentNullException ( " longitude" ) ;
60+ throw new ArgumentNullException ( nameof ( longitude ) ) ;
5661 }
5762
5863 if ( string . IsNullOrWhiteSpace ( latitude ) )
5964 {
60- throw new ArgumentOutOfRangeException ( " latitude" , "May not be empty." ) ;
65+ throw new ArgumentOutOfRangeException ( nameof ( latitude ) , "May not be empty." ) ;
6166 }
6267
6368 if ( string . IsNullOrWhiteSpace ( longitude ) )
6469 {
65- throw new ArgumentOutOfRangeException ( " longitude" , "May not be empty." ) ;
70+ throw new ArgumentOutOfRangeException ( nameof ( longitude ) , "May not be empty." ) ;
6671 }
6772
6873 double lat ;
6974 double lon ;
7075
7176 if ( ! double . TryParse ( latitude , NumberStyles . Float , CultureInfo . InvariantCulture , out lat ) || Math . Abs ( lat ) > 90 )
7277 {
73- throw new ArgumentOutOfRangeException ( " latitude" , "Latitude must be a proper lat (+/- double) value between -90 and 90." ) ;
78+ throw new ArgumentOutOfRangeException ( nameof ( latitude ) , "Latitude must be a proper lat (+/- double) value between -90 and 90." ) ;
7479 }
7580
7681 if ( ! double . TryParse ( longitude , NumberStyles . Float , CultureInfo . InvariantCulture , out lon ) || Math . Abs ( lon ) > 180 )
7782 {
78- throw new ArgumentOutOfRangeException ( " longitude" , "Longitude must be a proper lon (+/- double) value between -180 and 180." ) ;
83+ throw new ArgumentOutOfRangeException ( nameof ( longitude ) , "Longitude must be a proper lon (+/- double) value between -180 and 180." ) ;
7984 }
8085
8186 Latitude = lat ;
@@ -86,64 +91,55 @@ public GeographicPosition(string latitude, string longitude, string altitude = n
8691 double alt ;
8792 if ( ! double . TryParse ( altitude , NumberStyles . Float , CultureInfo . InvariantCulture , out alt ) )
8893 {
89- throw new ArgumentOutOfRangeException ( " altitude" , "Altitude must be a proper altitude (m(eter) as double) value, e.g. '6500'." ) ;
94+ throw new ArgumentOutOfRangeException ( nameof ( altitude ) , "Altitude must be a proper altitude (m(eter) as double) value, e.g. '6500'." ) ;
9095 }
9196
9297 Altitude = alt ;
9398 }
9499 }
95100
96101 /// <summary>
97- /// Prevents a default instance of the <see cref="GeographicPosition" /> class from being created.
102+ /// Prevents a default instance of the <see cref="GeographicPosition" /> class from being created.
98103 /// </summary>
99104 private GeographicPosition ( )
100- : base ( )
101105 {
102- Coordinates = new double ? [ 3 ] ;
106+ _coordinates = new double ? [ 3 ] ;
103107 }
104108
105109 /// <summary>
106- /// Gets the altitude.
110+ /// Gets the altitude.
107111 /// </summary>
108112 public double ? Altitude
109113 {
110- get { return Coordinates [ 2 ] ; }
111- private set { Coordinates [ 2 ] = value ; }
114+ get { return _coordinates [ 2 ] ; }
115+ private set { _coordinates [ 2 ] = value ; }
112116 }
113117
114118 /// <summary>
115- /// Gets the latitude.
119+ /// Gets the latitude.
116120 /// </summary>
117121 /// <value>The latitude.</value>
118122 public double Latitude
119123 {
120- get { return Coordinates [ 0 ] . GetValueOrDefault ( ) ; }
121- private set { Coordinates [ 0 ] = value ; }
124+ get { return _coordinates [ 0 ] . GetValueOrDefault ( ) ; }
125+ private set { _coordinates [ 0 ] = value ; }
122126 }
123127
124128 /// <summary>
125- /// Gets the longitude.
129+ /// Gets the longitude.
126130 /// </summary>
127131 /// <value>The longitude.</value>
128132 public double Longitude
129133 {
130- get { return Coordinates [ 1 ] . GetValueOrDefault ( ) ; }
131- private set { Coordinates [ 1 ] = value ; }
134+ get { return _coordinates [ 1 ] . GetValueOrDefault ( ) ; }
135+ private set { _coordinates [ 1 ] = value ; }
132136 }
133-
134- /// <summary>
135- /// Gets or sets the coordinates, is a 2-size array
136- /// </summary>
137- /// <value>
138- /// The coordinates.
139- /// </value>
140- private double ? [ ] Coordinates { get ; set ; }
141137
142138 /// <summary>
143- /// Returns a <see cref="string" /> that represents this instance.
139+ /// Returns a <see cref="string" /> that represents this instance.
144140 /// </summary>
145141 /// <returns>
146- /// A <see cref="string" /> that represents this instance.
142+ /// A <see cref="string" /> that represents this instance.
147143 /// </returns>
148144 public override string ToString ( )
149145 {
@@ -191,7 +187,7 @@ public bool Equals(GeographicPosition left, GeographicPosition right)
191187 {
192188 return false ;
193189 }
194- return left . Coordinates . SequenceEqual ( right . Coordinates , DoubleComparer ) ;
190+ return left != null && left . _coordinates . SequenceEqual ( right . _coordinates , DoubleComparer ) ;
195191 }
196192
197193 /// <summary>
@@ -208,7 +204,7 @@ public bool Equals(GeographicPosition left, GeographicPosition right)
208204 public override int GetHashCode ( )
209205 {
210206 int hash = 1 ;
211- foreach ( var item in Coordinates )
207+ foreach ( var item in _coordinates )
212208 {
213209 hash = ( hash * 397 ) ^ item . GetHashCode ( ) ;
214210 }
0 commit comments