Skip to content

Commit

Permalink
fixup: impl Interpolate for CoordFloat, not just f64
Browse files Browse the repository at this point in the history
This was a copy/paste error from the impl on Geodesic which truly does
only support f64 - for Haversine and Rhumb though, we can support any
CoordFloat+FromPrimitive
  • Loading branch information
michaelkirk committed Oct 7, 2024
1 parent 0b8c444 commit 58d4e28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
16 changes: 6 additions & 10 deletions geo/src/algorithm/line_measures/metric_spaces/haversine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<F: CoordFloat + FromPrimitive> Distance<F, Point<F>, Point<F>> for Haversin
/// Interpolate Point(s) along a [great circle].
///
/// [great circle]: https://en.wikipedia.org/wiki/Great_circle
impl InterpolatePoint<f64> for Haversine {
impl<F: CoordFloat + FromPrimitive> InterpolatePoint<F> for Haversine {
/// Returns a new Point along a [great circle] between two existing points.
///
/// # Examples
Expand All @@ -150,11 +150,7 @@ impl InterpolatePoint<f64> for Haversine {
/// ```
///
/// [great circle]: https://en.wikipedia.org/wiki/Great_circle
fn point_at_ratio_between(
start: Point<f64>,
end: Point<f64>,
ratio_from_start: f64,
) -> Point<f64> {
fn point_at_ratio_between(start: Point<F>, end: Point<F>, ratio_from_start: F) -> Point<F> {
crate::algorithm::HaversineIntermediate::haversine_intermediate(
&start,
&end,
Expand All @@ -173,11 +169,11 @@ impl InterpolatePoint<f64> for Haversine {
/// [great circle]: https://en.wikipedia.org/wiki/Great_circle
/// [haversine formula]: https://en.wikipedia.org/wiki/Haversine_formula
fn points_along_line(
start: Point<f64>,
end: Point<f64>,
max_distance: f64,
start: Point<F>,
end: Point<F>,
max_distance: F,
include_ends: bool,
) -> impl Iterator<Item = Point<f64>> {
) -> impl Iterator<Item = Point<F>> {
crate::algorithm::HaversineIntermediate::haversine_intermediate_fill(
&start,
&end,
Expand Down
16 changes: 6 additions & 10 deletions geo/src/algorithm/line_measures/metric_spaces/rhumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<F: CoordFloat + FromPrimitive> Distance<F, Point<F>, Point<F>> for Rhumb {
/// Interpolate Point(s) along a [rhumb line].
///
/// [rhumb line]: https://en.wikipedia.org/wiki/Rhumb_line
impl InterpolatePoint<f64> for Rhumb {
impl<F: CoordFloat + FromPrimitive> InterpolatePoint<F> for Rhumb {
/// Returns a new Point along a [rhumb line] between two existing points.
///
/// # Examples
Expand All @@ -141,11 +141,7 @@ impl InterpolatePoint<f64> for Rhumb {
/// ```
///
/// [rhumb line]: https://en.wikipedia.org/wiki/Rhumb_line
fn point_at_ratio_between(
start: Point<f64>,
end: Point<f64>,
ratio_from_start: f64,
) -> Point<f64> {
fn point_at_ratio_between(start: Point<F>, end: Point<F>, ratio_from_start: F) -> Point<F> {
crate::algorithm::RhumbIntermediate::rhumb_intermediate(&start, &end, ratio_from_start)
}

Expand All @@ -159,11 +155,11 @@ impl InterpolatePoint<f64> for Rhumb {
///
/// [rhumb line]: https://en.wikipedia.org/wiki/Rhumb_line
fn points_along_line(
start: Point<f64>,
end: Point<f64>,
max_distance: f64,
start: Point<F>,
end: Point<F>,
max_distance: F,
include_ends: bool,
) -> impl Iterator<Item = Point<f64>> {
) -> impl Iterator<Item = Point<F>> {
crate::algorithm::RhumbIntermediate::rhumb_intermediate_fill(
&start,
&end,
Expand Down

0 comments on commit 58d4e28

Please sign in to comment.