Skip to content

Commit

Permalink
Unify Densify trait across metric spaces
Browse files Browse the repository at this point in the history
Just like #1228, but for Densify rather than Length.

This enables Geodesic, Haversine, Euclidean, and Rhumb Densification.

This required implementing InterpolatePoint for Euclidean.

Adjacent work:

deprecated legacy DensifyHaversine
linestring_segment is now implemented in terms of the new Densify

NOTE: linestring_segment would be a good future candidate for
a similar unification across all the metric spaces
  • Loading branch information
michaelkirk committed Oct 18, 2024
1 parent f683c7a commit 717e25e
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 280 deletions.
263 changes: 0 additions & 263 deletions geo/src/algorithm/densify.rs

This file was deleted.

9 changes: 9 additions & 0 deletions geo/src/algorithm/densify_haversine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use crate::{
Triangle,
};

#[deprecated(
since = "0.29.0",
note = "Please use the `line.densify::<Haversine>()` via the `Densify` trait instead."
)]
/// Returns a new spherical geometry containing both existing and new interpolated coordinates with
/// a maximum distance of `max_distance` between them.
///
Expand All @@ -21,6 +25,7 @@ use crate::{
/// # Examples
/// ```
/// use geo::{coord, Line, LineString};
/// #[allow(deprecated)]
/// use geo::DensifyHaversine;
///
/// let line = Line::new(coord! {x: 0.0, y: 0.0}, coord! { x: 0.0, y: 1.0 });
Expand Down Expand Up @@ -218,6 +223,7 @@ mod tests {
]
.into();

#[allow(deprecated)]
let dense = polygon.densify_haversine(50000.0);
assert_relative_eq!(dense.exterior(), &output_exterior);
}
Expand Down Expand Up @@ -250,6 +256,7 @@ mod tests {
]
.into();

#[allow(deprecated)]
let dense = linestring.densify_haversine(110.0);
assert_relative_eq!(dense, output);
}
Expand All @@ -258,13 +265,15 @@ mod tests {
fn test_line_densify() {
let output: LineString = vec![[0.0, 0.0], [0.0, 0.5], [0.0, 1.0]].into();
let line = Line::new(coord! {x: 0.0, y: 0.0}, coord! { x: 0.0, y: 1.0 });
#[allow(deprecated)]
let dense = line.densify_haversine(100000.0);
assert_relative_eq!(dense, output);
}

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

0 comments on commit 717e25e

Please sign in to comment.