Skip to content

Commit 3254bac

Browse files
Hunt MattHunt Matt
authored andcommitted
Removed some redundant code and started to tidy comments
1 parent 6718441 commit 3254bac

12 files changed

Lines changed: 151 additions & 123 deletions

src/GeoJSON.Net/GeoJSONObjectType.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,87 @@
33
// Copyright © Joerg Battermann 2014
44
// </copyright>
55
// <summary>
6-
// Defines the GeoJSON Objects types as defined in the <see cref="https://tools.ietf.org/html/rfc7946#section-3">RFC 7946</see>.
6+
// Defines the GeoJSON Objects types as defined in RFC 7946 https://tools.ietf.org/html/rfc7946#section-3
77
// </summary>
88
// --------------------------------------------------------------------------------------------------------------------
99

1010
namespace GeoJSON.Net
1111
{
1212
/// <summary>
13-
/// Defines the GeoJSON Objects types as defined in the <see cref="https://tools.ietf.org/html/rfc7946#section-3">RFC 7946</see>.
13+
/// Defines the GeoJSON Objects types.
1414
/// </summary>
1515
public enum GeoJSONObjectType
1616
{
1717
/// <summary>
18-
/// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.2">Point</see> type.
18+
/// Defines the Point type.
1919
/// </summary>
20+
/// <remarks>
21+
/// See https://tools.ietf.org/html/rfc7946#section-3.1.2
22+
/// </remarks>
2023
Point,
2124

2225
/// <summary>
23-
/// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.3">MultiPoint</see> type.
26+
/// Defines the MultiPoint type.
2427
/// </summary>
28+
/// <remarks>
29+
/// See https://tools.ietf.org/html/rfc7946#section-3.1.3
30+
/// </remarks>
2531
MultiPoint,
2632

2733
/// <summary>
28-
/// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.4">LineString</see> type.
34+
/// Defines the LineString type.
2935
/// </summary>
36+
/// <remarks>
37+
/// See https://tools.ietf.org/html/rfc7946#section-3.1.4
38+
/// </remarks>
3039
LineString,
3140

3241
/// <summary>
33-
/// Defines the <see chref="https://tools.ietf.org/html/rfc7946#section-3.1.5">MultiLineString</see> type.
42+
/// Defines the MultiLineString type.
3443
/// </summary>
44+
/// <remarks>
45+
/// See https://tools.ietf.org/html/rfc7946#section-3.1.5
46+
/// </remarks>
3547
MultiLineString,
3648

3749
/// <summary>
38-
/// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.6">Polygon</see> type.
50+
/// Defines the Polygon type.
3951
/// </summary>
52+
/// <remarks>
53+
/// See https://tools.ietf.org/html/rfc7946#section-3.1.6
54+
/// </remarks>
4055
Polygon,
4156

4257
/// <summary>
43-
/// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.7">MultiPolygon</see> type.
58+
/// Defines the MultiPolygon type.
4459
/// </summary>
60+
/// <remarks>
61+
/// See https://tools.ietf.org/html/rfc7946#section-3.1.7
62+
/// </remarks>
4563
MultiPolygon,
4664

4765
/// <summary>
48-
/// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.8">GeometryCollection</see> type.
66+
/// Defines the GeometryCollection type.
4967
/// </summary>
68+
/// <remarks>
69+
/// See https://tools.ietf.org/html/rfc7946#section-3.1.8
70+
/// </remarks>
5071
GeometryCollection,
5172

5273
/// <summary>
53-
/// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.2">Feature</see> type.
74+
/// Defines the Feature type.
5475
/// </summary>
76+
/// <remarks>
77+
/// See https://tools.ietf.org/html/rfc7946#section-3.2
78+
/// </remarks>
5579
Feature,
5680

5781
/// <summary>
58-
/// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.3">FeatureCollection</see> type.
82+
/// Defines the FeatureCollection type.
5983
/// </summary>
84+
/// <remarks>
85+
/// See https://tools.ietf.org/html/rfc7946#section-3.3
86+
/// </remarks>
6087
FeatureCollection
6188
}
6289
}

src/GeoJSON.Net/Geometry/GeographicPosition.cs

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
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

@@ -15,15 +16,19 @@
1516
namespace 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
}

src/GeoJSON.Net/Geometry/GeometryCollection.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// Copyright © Joerg Battermann 2014
44
// </copyright>
55
// <summary>
6-
// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.8">GeometryCollection</see> type.
6+
// Defines the GeometryCollection type.
7+
// See https://tools.ietf.org/html/rfc7946#section-3.1.8
78
// </summary>
89
// --------------------------------------------------------------------------------------------------------------------
910

@@ -16,23 +17,25 @@
1617
namespace GeoJSON.Net.Geometry
1718
{
1819
/// <summary>
19-
/// Defines the <see cref="https://tools.ietf.org/html/rfc7946#section-3.1.8">GeometryCollection</see> type.
20+
/// Defines the GeometryCollection type.
2021
/// </summary>
22+
/// <remarks>
23+
/// See https://tools.ietf.org/html/rfc7946#section-3.1.8
24+
/// </remarks>
2125
public class GeometryCollection : GeoJSONObject, IGeometryObject, IEqualityComparer<GeometryCollection>, IEquatable<GeometryCollection>
2226
{
2327
/// <summary>
24-
/// Initializes a new instance of the <see cref="GeometryCollection" /> class.
28+
/// Initializes a new instance of the <see cref="GeometryCollection" /> class.
2529
/// </summary>
2630
public GeometryCollection() : this(new List<IGeometryObject>())
2731
{
2832
}
2933

3034
/// <summary>
31-
/// Initializes a new instance of the <see cref="GeometryCollection" /> class.
35+
/// Initializes a new instance of the <see cref="GeometryCollection" /> class.
3236
/// </summary>
3337
/// <param name="geometries">The geometries contained in this GeometryCollection.</param>
3438
public GeometryCollection(List<IGeometryObject> geometries)
35-
: base()
3639
{
3740
if (geometries == null)
3841
{
@@ -44,7 +47,7 @@ public GeometryCollection(List<IGeometryObject> geometries)
4447
}
4548

4649
/// <summary>
47-
/// Gets the list of Polygons enclosed in this MultiPolygon.
50+
/// Gets the list of Polygons enclosed in this MultiPolygon.
4851
/// </summary>
4952
[JsonProperty(PropertyName = "geometries", Required = Required.Always)]
5053
[JsonConverter(typeof(GeometryConverter))]
@@ -93,7 +96,7 @@ public bool Equals(GeometryCollection left, GeometryCollection right)
9396
{
9497
return false;
9598
}
96-
return left.Equals(right);
99+
return left != null && left.Equals(right);
97100
}
98101

99102
/// <summary>

src/GeoJSON.Net/Geometry/IGeometryObject.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// <copyright file="IGeometryObject.cs" company="Joerg Battermann">
33
// Copyright © Joerg Battermann 2014
44
// </copyright>
5-
// <summary>
6-
// Defines the IGeometryObject type.
7-
// </summary>
85
// --------------------------------------------------------------------------------------------------------------------
96

107
namespace GeoJSON.Net.Geometry
@@ -15,10 +12,13 @@ namespace GeoJSON.Net.Geometry
1512
public interface IGeometryObject
1613
{
1714
/// <summary>
18-
/// Gets the (mandatory) type of the <see cref="https://tools.ietf.org/html/rfc7946#section-3.1">GeoJSON Object</see>.
19-
/// However, for <see cref="https://tools.ietf.org/html/rfc7946#section-3.1">GeoJSON Objects</see> only
20-
/// the 'Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon', or 'GeometryCollection' types are allowed.
15+
/// Gets the (mandatory) type of the GeoJSON Object.
16+
/// However, for GeoJSON Objects only the 'Point', 'MultiPoint', 'LineString', 'MultiLineString',
17+
/// 'Polygon', 'MultiPolygon', or 'GeometryCollection' types are allowed.
2118
/// </summary>
19+
/// <remarks>
20+
/// See https://tools.ietf.org/html/rfc7946#section-3.1
21+
/// </remarks>
2222
/// <value>
2323
/// The type of the object.
2424
/// </value>

0 commit comments

Comments
 (0)