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

Rewrite Polygon structure to enforce closed LineString rings. #337

Merged
merged 2 commits into from
Jan 23, 2019

Conversation

frewsxcv
Copy link
Member

Prior to this pull request, the exterior and interior fields on a Polygon were public, allowing users to modify their Coordinates as they saw fit.

To ensure all rings in a Polygons remain closed, this pull request:

  • privatizes the exterior and interior fields
  • adds getters/mutators
  • closes all LineString rings upon construction or after mutation

Fixes #166.

]);
let poly = Polygon::new(linestring, vec![inner_linestring]);
assert!(poly.contains(&Point::new(0.25, 0.25)));
assert!(!poly.contains(&Point::new(0.25, 0.25)));
Copy link
Member Author

Choose a reason for hiding this comment

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

Confusingly, as a result of closing the ring, this went from true to false 🤔

@urschrei
Copy link
Member

Won't we need an (optional) validation step as part of this? It's relatively straightforward to inadvertently create an invalid geometry (e.g. using https://gist.github.com/urschrei/aa95f3681a09ff1a9d82935ff82ae9c4 as the exterior ring). Not validating isn't strictly worse than what we do now, but auto-closing could be seen as implying validity…

@frewsxcv
Copy link
Member Author

Won't we need an (optional) validation step as part of this? It's relatively straightforward to inadvertently create an invalid geometry (e.g. using https://gist.github.com/urschrei/aa95f3681a09ff1a9d82935ff82ae9c4 as the exterior ring). Not validating isn't strictly worse than what we do now, but auto-closing could be seen as implying validity…

Oh for sure, we still need to address the validity issue. It's certainly still possible to create invalid geometries with this crate. For instance, in addition to your example, it's still possible to create a LineString with zero coordinates, which we shouldn't allow and would be easy to check.

To address your concerns, do you think it'd be sufficient to add a disclaimer in the docs warning that there are currently no geometric validity checks in-place?

@urschrei
Copy link
Member

do you think it'd be sufficient to add a disclaimer in the docs warning that there are currently no geometric validity checks in-place?

Absolutely – being clear in the docs is all we can do anyway. It's a great feature, I didn't mean to imply we shouldn't land it!

@frewsxcv
Copy link
Member Author

@urschrei How does 7e2e9da sound?

@urschrei
Copy link
Member

Perfect!

@frewsxcv
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Jan 23, 2019
337: Rewrite Polygon structure to enforce closed LineString rings. r=frewsxcv a=frewsxcv

Prior to this pull request, the `exterior` and `interior` fields on a `Polygon` were public, allowing users to modify their `Coordinate`s as they saw fit.

To ensure all rings in a `Polygon`s remain closed, this pull request:

- privatizes the `exterior` and `interior` fields
- adds getters/mutators
- closes all `LineString` rings upon construction or after mutation

Fixes #166.

Co-authored-by: Corey Farwell <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jan 23, 2019

Build succeeded

@bors bors bot merged commit 7e2e9da into master Jan 23, 2019
@frewsxcv frewsxcv deleted the frewsxcv-close branch January 23, 2019 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do polygons need to be closed?
2 participants