Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding check in closedLoop method to ensure no duplicate locations. #224

Merged
merged 2 commits into from
Sep 25, 2018

Conversation

mgcuthbert
Copy link
Contributor

@mgcuthbert mgcuthbert commented Sep 24, 2018

Description:

This is a very minor update to how the closedLoop function on the polygon object works. Previously it was simply adding the first location to the end of the iteration. This update now just checks to make sure that the last object isn't already equal to the first object, that way we are not simply adding a duplicate location at the end of the iteration.

Potential Impact:

I am not sure if there would be any impact, it is unlikely that this scenario would even be hit under normal circumstances.

Unit Test Approach:

Added a unit test that makes sure that we aren't adding the location at the end if the polygon is already closed.

Test Results:

Test cases passed correctly, and also failed correctly when the update is not included.

Copy link
Contributor

@MikeGost MikeGost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question on equality, otherwise looks good.

@@ -152,7 +152,11 @@ public Location center()
*/
public Iterable<Location> closedLoop()
{
return new MultiIterable<>(this, Iterables.from(this.first()));
if (this.first() != this.last())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be !this.first().equals(this.last()), since the two Locations can be different objects in memory, but we care about actual equality at the latitude/longitude level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes definitely. I will update now.

Copy link
Contributor

@MikeGost MikeGost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the change @mgcuthbert!

Copy link
Collaborator

@matthieun matthieun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@matthieun matthieun merged commit e2508ab into osmlab:dev Sep 25, 2018
@matthieun matthieun added this to the 5.1.13 milestone Oct 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants