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

Implement LineString simplification #55

Merged
merged 5 commits into from
Aug 8, 2016

Conversation

urschrei
Copy link
Member

@urschrei urschrei commented Aug 5, 2016

This trait currently uses the Ramer–Douglas–Peucker algorithm to
simplify a LineString (see #54), while preserving its overall shape.

This is WIP, for two reasons:

  • rdp() currently uses unwrap(), because the first() and last() methods on slices return Option. It's not immediately clear to me how these could fail in this context, but all input is welcome.
  • point_line_distance() and rdp() are implemented as helper functions, and called by the Simplify trait. This is mainly because rdp() is recursive and uses sub-slices of its initial input, which AFAICS can't be easily obtained from a LineString.

This trait currently uses the Ramer–Douglas–Peucker algorithm to
simplify a LineString, while preserving its overall shape
assert_eq!(dist, 0.7071067811865475);
}
#[test]
fn rdp_test() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a test doing simplify on an empty LineString?

Copy link
Member

Choose a reason for hiding this comment

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

Or should we expect all LineStrings to have at least two points? If so, we should make it explicit in the doc comment and add an assert.

Copy link
Member Author

@urschrei urschrei Aug 5, 2016

Choose a reason for hiding this comment

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

Hmm. A 2-point LineString can't be simplified anyway, and both it and an empty LineString are valid, so it makes sense to me to just return them both unmodified.

Return it unmodified
These can't be simplified, so the output should be identical to the input
@frewsxcv
Copy link
Member

frewsxcv commented Aug 8, 2016

Everything here looks good to me, is this still a WIP?

@urschrei
Copy link
Member Author

urschrei commented Aug 8, 2016

No, I'm pretty happy with it. How do you feel about the thoroughness of the tests, though? I feel like some tests for pathological input (tiny epsilon, gigantic LineString) would probably be a good idea at some point, although in the latter case that should probably happen further up the chain.

@frewsxcv
Copy link
Member

frewsxcv commented Aug 8, 2016

Sounds great, thanks for this! 🎊

@frewsxcv frewsxcv merged commit b911469 into georust:master Aug 8, 2016
@urschrei
Copy link
Member Author

urschrei commented Aug 8, 2016

\o/

@frewsxcv
Copy link
Member

frewsxcv commented Aug 8, 2016

:D

One of these I want to get some sort of basic Rust GUI for geo data (maybe written in conrod) so that we can visualize all these rust-geo algorithms and operations.

@urschrei urschrei deleted the simplify_linestring branch March 14, 2017 18:13
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.

2 participants