Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mkulke committed Jul 4, 2017
1 parent de023a6 commit 99306c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,24 @@ use types::Point;

/// Returns a new Point using the distance to the existing Point and a bearing for the direction
pub trait Destination<T: Float> {
pub trait HaversineDestination<T: Float> {
/// Returns a new Point using distance to the existing Point and a bearing for the direction
///
/// ```
/// # extern crate geo;
/// # #[macro_use] extern crate approx;
/// #
/// use geo::Point;
/// use geo::algorithm::destination::Destination;
/// use geo::algorithm::haversine_destination::HaversineDestination;
///
/// # fn main() {
/// let p_1 = Point::<f64>::new(9.177789688110352, 48.776781529534965);
/// let p_2 = p_1.destination(45., 10000.);
/// let p_2 = p_1.haversine_destination(45., 10000.);
/// assert_eq!(p_2, Point::<f64>::new(9.274410083250379, 48.84033282787534))
/// # }
/// ```
fn destination(&self, bearing: T, distance: T) -> Point<T>;
fn haversine_destination(&self, bearing: T, distance: T) -> Point<T>;
}

impl<T> Destination<T> for Point<T>
impl<T> HaversineDestination<T> for Point<T>
where T: Float + FromPrimitive
{
fn destination(&self, bearing: T, distance: T) -> Point<T> {
fn haversine_destination(&self, bearing: T, distance: T) -> Point<T> {
let center_lng = self.x().to_radians();
let center_lat = self.y().to_radians();
let bearing_rad = bearing.to_radians();
Expand All @@ -47,14 +42,14 @@ impl<T> Destination<T> for Point<T>
}

#[cfg(test)]
mod destination {
mod test {
use super::*;
use algorithm::haversine_distance::HaversineDistance;

#[test]
fn returns_a_new_point() {
let p_1 = Point::<f64>::new(9.177789688110352, 48.776781529534965);
let p_2 = p_1.destination(45., 10000.);
let p_2 = p_1.haversine_destination(45., 10000.);
assert_eq!(p_2, Point::<f64>::new(9.274410083250379, 48.84033282787534));
let distance = p_1.haversine_distance(&p_2);
assert_relative_eq!(distance, 10000., epsilon = 1.0e-6)
Expand Down
2 changes: 1 addition & 1 deletion src/algorithm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod length;
/// Returns the Euclidean distance between two geometries.
pub mod distance;
/// Returns a new Point using distance and bearing.
pub mod destination;
pub mod haversine_destination;
/// Returns the Haversine distance between two geometries.
pub mod haversine_distance;
/// Returns the Bbox of a geometry.
Expand Down

0 comments on commit 99306c9

Please sign in to comment.