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 9035452
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 280 deletions.
14 changes: 14 additions & 0 deletions geo/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@
line_string.length::<Haversine>();
```
* <https://github.com/georust/geo/pull/1228>
* Deprecated `DensifyHaversine`
* BREAKING: `Densify::densify` is no longer strictly Euclidean, and now accepts a generic line measure parameter.
```
// Before
line_string.densify();
line_string.densify_haversine();
// After
line_string.densify::<Euclidean>();
line_string.densify::<Haversine>();
// Additional measures are now supported
line_string.densify::<Geodesic>();
line_string.densify::<Rhumb>();
```
* Change IntersectionMatrix::is_equal_topo to now consider empty geometries as equal.
* <https://github.com/georust/geo/pull/1223>
* Fix `(LINESTRING EMPTY).contains(LINESTRING EMPTY)` and `(MULTIPOLYGON EMPTY).contains(MULTIPOINT EMPTY)` which previously
Expand Down
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 9035452

Please sign in to comment.