Skip to content

Commit

Permalink
add check in linestring impl for empty geometry. add associated test
Browse files Browse the repository at this point in the history
  • Loading branch information
JosiahParry committed Oct 6, 2023
1 parent c04eecb commit f170bbe
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion geo/src/algorithm/densify_haversine.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use num_traits::FromPrimitive;

use crate::{
CoordFloat, Line, LineString, MultiLineString, MultiPolygon, Point, Polygon, Rect, Triangle,
CoordFloat, CoordsIter, Line, LineString, MultiLineString, MultiPolygon, Point, Polygon, Rect,
Triangle,
};

use crate::{HaversineIntermediate, HaversineLength};
Expand Down Expand Up @@ -119,6 +120,10 @@ where
type Output = LineString<T>;

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

let mut new_line = vec![];
self.lines()
.for_each(|line| densify_line(line, &mut new_line, max_distance));
Expand Down Expand Up @@ -248,4 +253,11 @@ mod tests {
let dense = line.densify_haversine(100000.0);
assert_relative_eq!(dense, output);
}

#[test]
fn test_empty_linestring() {
let linestring: LineString<f64> = LineString::new(vec![]);
let dense = linestring.densify_haversine(10.0);
assert_eq!(0, dense.coords_count());
}
}

0 comments on commit f170bbe

Please sign in to comment.