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

FIX Densify trait to avoid panic with empty line string #1082

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions geo/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

## Unreleased

* Add `DensifyHaversine` trait to densify spherical line geometry
* Add `LineStringSegmentize` trait to split a single `LineString` into `n` `LineStrings` as a `MultiLineString`
* Fix `Densify` trait to avoid panic with empty line string.
* <https://github.com/georust/geo/pull/1082>
* Add `DensifyHaversine` trait to densify spherical line geometry.
* <https://github.com/georust/geo/pull/1081>
* Add `LineStringSegmentize` trait to split a single `LineString` into `n` `LineStrings` as a `MultiLineString`.
* <https://github.com/georust/geo/pull/1055>
* Add `EuclideanDistance` implementations for all remaining geometries.
* <https://github.com/georust/geo/pull/1029>
* Add `HausdorffDistance` algorithm trait to calculate the Hausdorff distance between any two geometries.
* <https://github.com/georust/geo/pull/1041>
* Add `matches` method to IntersectionMatrix for ergonomic de-9im comparisons.
* <https://github.com/georust/geo/pull/1043>
* Simplify `CoordsIter` and `MinimumRotatedRect` `trait`s with GATs by removing an unneeded trait lifetime
* Simplify `CoordsIter` and `MinimumRotatedRect` `trait`s with GATs by removing an unneeded trait lifetime.
* <https://github.com/georust/geo/pull/908>
* Add `ToDegrees` and `ToRadians` traits.
* <https://github.com/georust/geo/pull/1070>
Expand Down
13 changes: 13 additions & 0 deletions geo/src/algorithm/densify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ where
type Output = LineString<T>;

fn densify(&self, max_distance: T) -> Self::Output {
if self.0.is_empty() {
return LineString::new(vec![]);
}

let mut new_line = vec![];

self.lines()
.for_each(|line| densify_line(line, &mut new_line, max_distance));
// we're done, push the last coordinate on to finish
Expand Down Expand Up @@ -207,6 +212,14 @@ mod tests {
assert_eq!(densified, correct_polygon);
}

#[test]
fn test_empty_linestring_densify() {
let linestring = LineString::<f64>::new(vec![]);
let max_dist = 2.0;
let densified = linestring.densify(max_dist);
assert!(densified.0.is_empty());
}

#[test]
fn test_linestring_densify() {
let linestring: LineString<f64> =
Expand Down