Skip to content

Commit

Permalink
FIX Densify trait to avoid panic with empty line string
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk committed Oct 6, 2023
1 parent 2c99be6 commit 2bfe303
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions geo/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

## Unreleased

* 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.
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

0 comments on commit 2bfe303

Please sign in to comment.