Last active
July 21, 2016 19:22
-
-
Save tmcw/748ee9a6ce783e2ac6cd71f77d6b0a8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// currently gives answer in meters | |
fn haversine_distance(&self, p: &Point<T>) -> T { | |
let R = 6373000; | |
// issue is on the next line: Point<T> has a method .y() and a method | |
// .x() and both return <T>, where T has the trait bounds | |
// Float + ToPrimitive. But `to_radians` is not part of those trait | |
// bounds and I'm not sure how to use the built-in function without | |
// hardcoding or casting to f64 or f32 | |
let a = ((self.y() - p.y()).to_radians() / 2).sin().powi(2) + | |
(((self.x() - p.x()).to_radians() / 2).sin().powi(2) * | |
self.y().cos() * p.y().cos()); | |
R * 2 * a.sqrt().atan2((1 - a).sqrt()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
warning: unused manifest key: package.keyword | |
warning: unused manifest key: package.keyword | |
warning: unused manifest key: package.keyword | |
warning: unused manifest key: package.keyword | |
Compiling geo v0.2.2 (file:///Users/tmcw/src/rust-geo) | |
src/algorithm/distance.rs:38:37: 38:47 error: no method named `to_radians` found for type `T` in the current scope | |
src/algorithm/distance.rs:38 let a = ((self.y() - p.y()).to_radians() / 2).sin().powi(2) + | |
^~~~~~~~~~ | |
src/algorithm/distance.rs:38:37: 38:47 help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `to_radians`, perhaps you need to implement it: | |
src/algorithm/distance.rs:38:37: 38:47 help: candidate #1: `core::num::Float` | |
src/algorithm/distance.rs:39:36: 39:46 error: no method named `to_radians` found for type `T` in the current scope | |
src/algorithm/distance.rs:39 (((self.x() - p.x()).to_radians() / 2).sin().powi(2) * | |
^~~~~~~~~~ | |
src/algorithm/distance.rs:39:36: 39:46 help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `to_radians`, perhaps you need to implement it: | |
src/algorithm/distance.rs:39:36: 39:46 help: candidate #1: `core::num::Float` | |
error: aborting due to 2 previous errors | |
src/algorithm/distance.rs:38:37: 38:47 error: no method named `to_radians` found for type `T` in the current scope | |
src/algorithm/distance.rs:38 let a = ((self.y() - p.y()).to_radians() / 2).sin().powi(2) + | |
^~~~~~~~~~ | |
src/algorithm/distance.rs:38:37: 38:47 help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `to_radians`, perhaps you need to implement it: | |
src/algorithm/distance.rs:38:37: 38:47 help: candidate #1: `core::num::Float` | |
src/algorithm/distance.rs:39:36: 39:46 error: no method named `to_radians` found for type `T` in the current scope | |
src/algorithm/distance.rs:39 (((self.x() - p.x()).to_radians() / 2).sin().powi(2) * | |
^~~~~~~~~~ | |
src/algorithm/distance.rs:39:36: 39:46 help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `to_radians`, perhaps you need to implement it: | |
src/algorithm/distance.rs:39:36: 39:46 help: candidate #1: `core::num::Float` | |
error: aborting due to 2 previous errors | |
error: Could not compile `geo`. | |
To learn more, run the command again with --verbose. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment