Skip to content

Commit

Permalink
Linestring to use IPosition in Is_Closed
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-lethargic committed Jun 15, 2017
1 parent 3d72d06 commit 0d43f01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/GeoJSON.Net.Tests/Geometry/LineStringTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using GeoJSON.Net.Geometry;
using Newtonsoft.Json;
Expand Down Expand Up @@ -39,6 +40,7 @@ public void Is_Not_Closed()

Assert.IsFalse(lineString.IsClosed());
}


[Test]
public void Can_Serialize()
Expand Down Expand Up @@ -81,6 +83,19 @@ public void Can_Deserialize()
Assert.AreEqual(expectedLineString.Coordinates[0].Longitude, actualLineString.Coordinates[0].Longitude);
}

[Test]
public void Constructor_No_Coordinates_Throws_Exception()
{
var coordinates = new List<IPosition>();
Assert.Throws<ArgumentOutOfRangeException>(() => new LineString(coordinates));
}

[Test]
public void Constructor_Null_Coordinates_Throws_Exception()
{
Assert.Throws<ArgumentNullException>(() => new LineString(null));
}

private LineString GetLineString(double offset = 0.0)
{
var coordinates = new List<IPosition>
Expand Down
16 changes: 5 additions & 11 deletions src/GeoJSON.Net/Geometry/LineString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,12 @@ public LineString(IEnumerable<IPosition> coordinates)
/// </returns>
public bool IsClosed()
{
var firstCoordinate = Coordinates[0] as Position;
var firstCoordinate = Coordinates[0];
var lastCoordinate = Coordinates[Coordinates.Count - 1];

if (firstCoordinate != null)
{
var lastCoordinate = Coordinates[Coordinates.Count - 1] as Position;

return firstCoordinate.Latitude == lastCoordinate.Latitude
&& firstCoordinate.Longitude == lastCoordinate.Longitude
&& firstCoordinate.Altitude == lastCoordinate.Altitude;
}

return Coordinates[0].Equals(Coordinates[Coordinates.Count - 1]);
return firstCoordinate.Longitude.Equals(lastCoordinate.Longitude)
&& firstCoordinate.Latitude.Equals(lastCoordinate.Latitude)
&& firstCoordinate.Altitude.Equals(lastCoordinate.Altitude);
}

/// <summary>
Expand Down

0 comments on commit 0d43f01

Please sign in to comment.