geographiclib-rs
A subset of geographiclib implemented in Rust.
Currently this implements the direct and the inverse geodesic calculations.
If instead you are looking for Rust bindings to Karney's C++ implementation, see https://crates.io/geographiclib.
Examples
// Determine the point 10000 km NE of JFK - the "direct" geodesic calculation.
use ;
let g = wgs84;
let jfk_lat = 40.64;
let jfk_lon = -73.78;
let northeast_azimuth = 45.0;
let = g.direct;
use assert_relative_eq;
assert_relative_eq!;
assert_relative_eq!;
assert_relative_eq!;
// Determine the distance between two points - the "inverse" geodesic calculation.
use ;
let g = wgs84;
let p1 = ;
let p2 = ;
let s12: f64 = g.inverse;
use assert_relative_eq;
assert_relative_eq!;
// Determine the perimeter and area of a polygon.
use ;
let g = wgs84;
let mut pa = new;
pa.add_point;
pa.add_point;
pa.add_point;
pa.add_point;
let = pa.compute;
use assert_relative_eq;
assert_relative_eq!;
assert_relative_eq!;
assert_eq!;
// Determine the distance between rovers Pathfinder and Curiosity on Mars
use ;
let mars = new;
let pathfinder = ;
let curiosity = ;
let distance_m: f64 = mars.inverse;
assert_eq!;
Features
accurate: Enabled by default. Use theaccuratecrate to provide high accuracy polygon areas and perimeters inPolygonArea. Can be disabled for better performance or whenPolygonAreais not being used.
Benchmarking
To compare the direct and inverse geodesic calculation against the geographiclib c bindings, run:
cargo bench
Which produces output like:
direct (c wrapper)/default
time: [23.420 µs 23.495 µs 23.578 µs]
direct (rust impl)/default
time: [23.894 µs 23.952 µs 24.017 µs]
inverse (c wrapper)/default
time: [42.505 µs 42.561 µs 42.627 µs]
inverse (rust impl)/default
time: [51.093 µs 51.174 µs 51.273 µs]
Showing that, at least in this benchmark, the Rust implementation is 2% slower for Direct geodesic calculations and 20% slower for Inverse calculations.