Skip to content

Commit

Permalink
Merge pull request #1 from georust/point
Browse files Browse the repository at this point in the history
Initial implementation of Point
  • Loading branch information
frewsxcv committed Jan 17, 2015
2 parents 40257fe + f4e4a40 commit 38fe341
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
@@ -1,3 +1,5 @@
mod point;

#[test]
fn it_works() {
}
24 changes: 24 additions & 0 deletions src/point.rs
@@ -0,0 +1,24 @@
use std::num::Float;

#[derive(Clone)]
struct Point {
lng: f64,
lat: f64,
}

impl Point {
pub fn distance(self, point: Point) -> f64 {
let lng_sqrd = (point.lng - self.lng).powi(2);
let lat_sqrd = (point.lat - self.lat).powi(2);
(lng_sqrd + lat_sqrd).sqrt()
}
}

#[test]
fn test_distance() {
let point1 = Point {lng: 9., lat: 3.};
let point2 = Point {lng: 6., lat: -1.};
let distance = 5.;
assert_eq!(distance, point1.clone().distance(point2.clone()));
assert_eq!(distance, point2.clone().distance(point1.clone()));
}

0 comments on commit 38fe341

Please sign in to comment.