diff --git a/geo/CHANGES.md b/geo/CHANGES.md index ae6b19a23..f5a6c47b6 100644 --- a/geo/CHANGES.md +++ b/geo/CHANGES.md @@ -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. + * +* Add `DensifyHaversine` trait to densify spherical line geometry. + * +* Add `LineStringSegmentize` trait to split a single `LineString` into `n` `LineStrings` as a `MultiLineString`. + * * Add `EuclideanDistance` implementations for all remaining geometries. * * Add `HausdorffDistance` algorithm trait to calculate the Hausdorff distance between any two geometries. * * Add `matches` method to IntersectionMatrix for ergonomic de-9im comparisons. * -* 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. * * Add `ToDegrees` and `ToRadians` traits. * diff --git a/geo/src/algorithm/densify.rs b/geo/src/algorithm/densify.rs index e861efb45..2c158f03b 100644 --- a/geo/src/algorithm/densify.rs +++ b/geo/src/algorithm/densify.rs @@ -106,7 +106,12 @@ where type Output = LineString; 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 @@ -207,6 +212,14 @@ mod tests { assert_eq!(densified, correct_polygon); } + #[test] + fn test_empty_linestring_densify() { + let linestring = LineString::::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 =