haversine-redux

Crates.iohaversine-redux
lib.rshaversine-redux
version0.2.1
sourcesrc
created_at2022-06-08 20:32:20.079268
updated_at2022-06-09 08:17:49.611712
descriptionHaversine formular library to determine the distances between two coordinates on the earth
homepage
repositoryhttps://github.com/swip3798/haversine-redux
max_upload_size
id602245
size21,043
Christian Schweigel (swip3798)

documentation

https://docs.rs/haversine-redux

README

Haversine Formular in Rust

Documentation Crates.io License Build

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].

Usage

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));
}

Optional support for #![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.

Licensing

This library is dual-licensed under the MIT and the Apache 2.0 License.

Commit count: 15

cargo fmt