Crates.io | haversine-redux |
lib.rs | haversine-redux |
version | 0.2.1 |
source | src |
created_at | 2022-06-08 20:32:20.079268 |
updated_at | 2022-06-09 08:17:49.611712 |
description | Haversine formular library to determine the distances between two coordinates on the earth |
homepage | |
repository | https://github.com/swip3798/haversine-redux |
max_upload_size | |
id | 602245 |
size | 21,043 |
This is a small library to implement the haversine formular in rust. There is already an haversine crate out there (you can find it here), but that library hasn't been updated since 2015 and because of that, it has some issues, especially the missing documentation and a little bit tedious and inefficient API.
Because of that, here's a rewrite, with a more intuitive interface and optional support for #![no_std]
.
Add haversine-redux as a dependency to your project Cargo.toml file:
[dependencies]
haversine-redux = "0.2"
Example usage:
use haversine_redux::{Location, Unit};
fn main() {
let start = Location::new(38.898556, -77.037852);
let end = Location::new(38.897147, -77.043934);
// Kilometers
let km = start.distance_to(&end, Unit::Kilometer);
// OR
let km = start.kilometers_to(&end);
// Miles
let miles = start.distance_to(&end, Unit::Mile);
// OR
let miles = start.miles_to(&end);
// To use the haversine formular with a custom sphere which is not the earth use the CustomSphere unit and add the radius
let custom = start.distance_to(&end, Unit::CustomSphere(50.0));
}
#![no_std]
To enable no_std support, just add the no_std
feature to the haversine-redux dependency:
[dependencies]
haversine-redux = {version = "0.2", features = ["no_std"]}
This will load the dependency libm for the implementations of mathematical functions like sin, cos or atan2.
This library is dual-licensed under the MIT and the Apache 2.0 License.