Skip to content

Commit

Permalink
Merge pull request #1082 from georust/mkirk/fix-densify
Browse files Browse the repository at this point in the history
FIX `Densify` trait to avoid panic with empty line string
  • Loading branch information
urschrei authored Oct 7, 2023
2 parents 2c99be6 + ad126cd commit d95daf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit d95daf8

Please sign in to comment.