Skip to content

Commit

Permalink
Adding check in closedLoop method to ensure no duplicate locations. (#…
Browse files Browse the repository at this point in the history
…224)

* Adding check in closedLoop method to ensure no duplicate locations.

* Updating equals statement.
  • Loading branch information
mgcuthbert authored and matthieun committed Sep 25, 2018
1 parent 2b343dc commit e2508ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/org/openstreetmap/atlas/geography/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ public Location center()
*/
public Iterable<Location> closedLoop()
{
return new MultiIterable<>(this, Iterables.from(this.first()));
if (!this.first().equals(this.last()))
{
return new MultiIterable<>(this, Iterables.from(this.first()));
}
return this;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/openstreetmap/atlas/geography/PolygonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,17 @@ public void testTriangulate()
Assert.assertEquals(3, triangle.size());
}
}

@Test
public void testClosedLoop()
{
final Polygon polygon = Polygon.SILICON_VALLEY;
final Polygon initialClosedLoop = new Polygon(polygon.closedLoop());
Assert.assertNotEquals(
"Last and Last - 1 locations for the polygon should not be duplicate.",
initialClosedLoop.last(), initialClosedLoop.get(initialClosedLoop.size() - 2));
final Polygon doubleClosedLoop = new Polygon(initialClosedLoop.closedLoop());
Assert.assertNotEquals("Last and Last - 1 locations for polygon should not be duplicate.",
doubleClosedLoop.last(), doubleClosedLoop.get(doubleClosedLoop.size() - 2));
}
}

0 comments on commit e2508ab

Please sign in to comment.