Skip to content

Commit

Permalink
Move all geometries impls into impl Distance for Euclidean
Browse files Browse the repository at this point in the history
As part of aligning all our line measure traits (see
#1181), all the Point x Point
distance calculations had been moved into `line_measures::metric_spaces`.

Euclidean space is the only space that implements distance calculations
on *non* point geometries. This commit moves all those calculations onto
the `line_measures::metric_spaces::Euclidean` so that we can fully
deprecate the existing EuclideanDistance trait.
  • Loading branch information
michaelkirk committed Oct 22, 2024
1 parent cf37789 commit f791198
Show file tree
Hide file tree
Showing 14 changed files with 1,274 additions and 235 deletions.
10 changes: 3 additions & 7 deletions geo/benches/euclidean_distance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{criterion_group, criterion_main};
use geo::algorithm::{ConvexHull, EuclideanDistance};
use geo::algorithm::{ConvexHull, Distance, Euclidean};
use geo::{polygon, Polygon};

fn criterion_benchmark(c: &mut criterion::Criterion) {
Expand Down Expand Up @@ -37,9 +37,7 @@ fn criterion_benchmark(c: &mut criterion::Criterion) {
(x: -6.064453, y: 68.49604),
];
bencher.iter(|| {
criterion::black_box(
criterion::black_box(&poly1).euclidean_distance(criterion::black_box(&poly2)),
);
criterion::black_box(Euclidean::distance(&poly1, &poly2));
});
});

Expand Down Expand Up @@ -81,9 +79,7 @@ fn criterion_benchmark(c: &mut criterion::Criterion) {
]
.convex_hull();
bencher.iter(|| {
criterion::black_box(
criterion::black_box(&poly1).euclidean_distance(criterion::black_box(&poly2)),
);
criterion::black_box(Euclidean::distance(&poly1, &poly2));
});
},
);
Expand Down
16 changes: 8 additions & 8 deletions geo/src/algorithm/concave_hull.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::convex_hull::qhull;
use crate::utils::partial_min;
use crate::{
coord, Centroid, Coord, CoordNum, Euclidean, EuclideanDistance, GeoFloat, Length, Line,
LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon,
coord, Centroid, Coord, CoordNum, Distance, Euclidean, GeoFloat, Length, Line, LineString,
MultiLineString, MultiPoint, MultiPolygon, Point, Polygon,
};
use rstar::{RTree, RTreeNum};
use std::collections::VecDeque;
Expand Down Expand Up @@ -134,8 +134,8 @@ where
let closest_point =
candidates.fold(Point::new(point.x, point.y), |acc_point, candidate| {
let candidate_point = Point::new(candidate.x, candidate.y);
if line.euclidean_distance(&acc_point)
> line.euclidean_distance(&candidate_point)
if Euclidean::distance(&line, &acc_point)
> Euclidean::distance(&line, &candidate_point)
{
candidate_point
} else {
Expand All @@ -154,8 +154,8 @@ where
let closest_edge_option = match peeked_edge {
None => None,
Some(&edge) => Some(edges_nearby_point.fold(*edge, |acc, candidate| {
if closest_point.euclidean_distance(&acc)
> closest_point.euclidean_distance(candidate)
if Euclidean::distance(&closest_point, &acc)
> Euclidean::distance(&closest_point, candidate)
{
*candidate
} else {
Expand All @@ -164,8 +164,8 @@ where
})),
};
let decision_distance = partial_min(
closest_point.euclidean_distance(&line.start_point()),
closest_point.euclidean_distance(&line.end_point()),
Euclidean::distance(&closest_point, &line.start_point()),
Euclidean::distance(&closest_point, &line.end_point()),
);
if let Some(closest_edge) = closest_edge_option {
let far_enough = edge_length / decision_distance > concavity;
Expand Down
Loading

0 comments on commit f791198

Please sign in to comment.