-
Notifications
You must be signed in to change notification settings - Fork 205
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 indices #402
Simplify indices #402
Conversation
Algorithms that can result in simplified geometries should have functions that return the indices of the simplified input geometry – this is particularly useful for users in an FFI context, where the source geometries may have different data structures – returning only indices allows these users to use their language-specific filter/mask functions to construct / mutate their input geometries. The revised implementation doesn't show a significant benchmark difference.
This trait allows RDP simplification operations on LineStrings to return indices instead of the points themselves
d176add
to
5cba225
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great idea! lgtm ✅
@@ -63,7 +63,8 @@ pub mod private_utils; | |||
#[macro_use] | |||
extern crate approx; | |||
|
|||
mod test { | |||
#[cfg(test)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
/// Simplifies a geometry, returning the retained _indices_ of the input. | ||
/// | ||
/// This operation uses the [Ramer–Douglas–Peucker algorithm](https://en.wikipedia.org/wiki/Ramer–Douglas–Peucker_algorithm) | ||
/// and does not guarantee that the returned geometry is valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding docs!
geo/src/algorithm/simplify.rs
Outdated
&self | ||
.clone() | ||
.into_points() | ||
.iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of self.clone().into_points().iter()
, you can avoid the memory allocation by doing self.points_iter()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
They're Copy types anyway, so this shouldn't make any difference perf-wise, and it allows us to do away with lifetime complexity and avoid an allocation in simplify_idx
bors r+ |
402: Simplify indices r=urschrei a=urschrei This PR adds a new trait to the `simplify` and `simplifyVW` modules: `SimplifyIdx` and `SimplifyVwIdx`. Both traits do the same thing: they run the respective simplification algorithm, but return the _indices_ of the simplified `LineString`, instead of the simplified geometry. This is mostly in response to ongoing requests from FFI consumers: because their use-cases don't necessarily map onto the Simple Features geometry model, returning geometries is less useful than returning indices, which can be used as mask values / input into native filter functions. The only current drawback to these new traits is that because they return `Vec<usize>`, they're only implemented for `LineString`. If there's a more flexible way to do it, I'd love to extend it to some other geometries. This change introduces some additional indirection for the RDP implementation, but `cargo bench` hasn't shown a perf hit… Co-authored-by: Stephan Hügel <shugel@tcd.ie> Co-authored-by: Stephan Hügel <urschrei@gmail.com>
Build succeeded |
403: Doc updates r=urschrei a=urschrei (To be merged after #402) This PR adds top-level docs (mostly the same as what's currently in the README), and the following changes: - Revised `LineString` docs - Revised `Point` docs - Revised module docs to better distinguish `closest_point` and `euclidean_distance` - Revised `chamberlain_duquette` docs - Revised `haversine_destination` module doc - Note existence of some non-euclidean distance algorithms - Detail optional features - Make GeoJSON interop more obvious. This is somewhat redundant, since the GeoJSON crate says the same thing, but we don't know what crate people will see first, so I think it's OK - Hidden the `PointsIter` struct from docs.rs Co-authored-by: Stephan Hügel <shugel@tcd.ie>
This PR adds a new trait to the
simplify
andsimplifyVW
modules:SimplifyIdx
andSimplifyVwIdx
.Both traits do the same thing: they run the respective simplification algorithm, but return the indices of the simplified
LineString
, instead of the simplified geometry. This is mostly in response to ongoing requests from FFI consumers: because their use-cases don't necessarily map onto the Simple Features geometry model, returning geometries is less useful than returning indices, which can be used as mask values / input into native filter functions.The only current drawback to these new traits is that because they return
Vec<usize>
, they're only implemented forLineString
. If there's a more flexible way to do it, I'd love to extend it to some other geometries.This change introduces some additional indirection for the RDP implementation, but
cargo bench
hasn't shown a perf hit…