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

Simplify now generates Polygon rings with at least four coordiantes #943

Merged
merged 5 commits into from
Dec 12, 2022

Conversation

frewsxcv
Copy link
Member

@frewsxcv frewsxcv commented Nov 30, 2022

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

Prior to this pull request, running Simplify on Polygon could generate rings with two coordinates, which would make it no longer a valid ring. This pull request updates Simplify to ensure resulting Polygon rings always have at least four coordinates.

Fixes #142

@frewsxcv frewsxcv changed the title Don't let Simplify generate Polygons with invalid rings. Simplify now always generates Polygon rings with at least four coordiantes Nov 30, 2022
@frewsxcv frewsxcv changed the title Simplify now always generates Polygon rings with at least four coordiantes Simplify now generates Polygon rings with at least four coordiantes Nov 30, 2022

// If `simplified_len` is now lower than the minimum number of indices needed, then don't
// perform the culling and return the original input.
if *simplified_len <= INITIAL_MIN {
Copy link
Member

@michaelkirk michaelkirk Nov 30, 2022

Choose a reason for hiding this comment

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

Can you imagine a situation where this returns a polygon with many more points than INITIAL_MIN?

I'm not very familiar with this algorithm, but it seems like a pathological 1000 coord polygon could be simplified in 1 step to 2 points, and then because that's below INITIAL_MIN, we'll instead return the original 1000 coord polygon. But I think I'd want to get a 4-pt polygon in that case.

Or maybe that's not possible and I am misunderstanding.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed we would ideally return a 4 coordinate polygon in that case, but I'm not sure how to modify this algorithm to make that happen, and which is maybe worthy of a separate issue. Unless you know a good solution for this case

Copy link
Member Author

Choose a reason for hiding this comment

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

@michaelkirk How do you feel about opening up a follow-up issue for optimizing in that scenario?

Copy link
Member

Choose a reason for hiding this comment

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

I'm happy for incremental improvements.

My hesitation is that for this change, I wonder if this new behavior could be worse for some people. Like I'm imagining getting an invalid small polygon might be better for some people than getting back a huge unsimplified polygon.

Copy link
Member

Choose a reason for hiding this comment

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

I actually don't feel that strongly about it, it's just what occurred to me. I'm happy to see it merged if you think it's an improvement.

@michaelkirk
Copy link
Member

bors d=frewsxcv

@bors
Copy link
Contributor

bors bot commented Dec 6, 2022

✌️ frewsxcv can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@frewsxcv
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Dec 12, 2022
943: `Simplify` now generates `Polygon` rings with at least four coordiantes r=frewsxcv a=frewsxcv

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/main/CODE_OF_CONDUCT.md).
- [ ] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

Prior to this pull request, running `Simplify` on `Polygon` could generate rings with two coordinates, which would make it no longer a valid ring. This pull request updates `Simplify` to ensure resulting `Polygon` rings always have at least four coordinates.

Fixes #142 

Co-authored-by: Corey Farwell <coreyf@rwell.org>
@bors
Copy link
Contributor

bors bot commented Dec 12, 2022

Build failed:

@frewsxcv
Copy link
Member Author

bors r=michaelkirk

bors bot added a commit that referenced this pull request Dec 12, 2022
943: `Simplify` now generates `Polygon` rings with at least four coordiantes r=michaelkirk a=frewsxcv

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/main/CODE_OF_CONDUCT.md).
- [ ] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

Prior to this pull request, running `Simplify` on `Polygon` could generate rings with two coordinates, which would make it no longer a valid ring. This pull request updates `Simplify` to ensure resulting `Polygon` rings always have at least four coordinates.

Fixes #142 

Co-authored-by: Corey Farwell <coreyf@rwell.org>
@bors
Copy link
Contributor

bors bot commented Dec 12, 2022

Build failed:

@frewsxcv
Copy link
Member Author

bors r=michaelkirk

@bors
Copy link
Contributor

bors bot commented Dec 12, 2022

Build succeeded:

@bors bors bot merged commit a8fabd4 into main Dec 12, 2022
@bors bors bot deleted the simplify-polygon branch December 12, 2022 05:12
bors bot added a commit that referenced this pull request Jan 9, 2023
953: Add missing changelog entry r=michaelkirk a=frewsxcv

Forgot to add this to #943

Co-authored-by: Corey Farwell <coreyf@rwell.org>
Co-authored-by: Michael Kirk <michael.code@endoftheworl.de>
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.

Using Simplification algorithm on a polygon can result in an invalid polygon
2 participants