Expand description
Fast, accurate geographic and planar distance calculations.
This crate provides distance calculation functions for geographic coordinates using both geodesic (Earth-aware) and Euclidean (flat-plane) algorithms.
§Quick Start
use rapidgeo_distance::{LngLat, geodesic, euclid};
let sf = LngLat::new_deg(-122.4194, 37.7749); // San Francisco
let nyc = LngLat::new_deg(-74.0060, 40.7128); // New York City
// Haversine: Fast, ±0.5% accuracy for distances <1000km
let distance = geodesic::haversine(sf, nyc);
println!("Distance: {:.1} km", distance / 1000.0);
// Euclidean: Very fast but inaccurate for large distances
let euclidean = euclid::distance_euclid(sf, nyc);
println!("Euclidean: {:.6}°", euclidean);§Algorithm Selection
| Algorithm | Speed | Accuracy | Best For |
|---|---|---|---|
| Haversine | Fast | ±0.5% | General use, distances <1000km |
| Vincenty | Slow | ±1mm | High precision, any distance |
| Euclidean | Fastest | Poor | Small areas, relative comparisons |
§Coordinate System
All coordinates use the lng, lat ordering convention (longitude first, latitude second). Coordinates are stored in decimal degrees and converted to radians internally as needed. The geodesic calculations assume the WGS84 ellipsoid.
§Modules
geodesic: Earth-aware distance calculations using geodesic algorithmseuclid: Fast planar distance calculations using Euclidean geometrybatch: Parallel batch operations (requiresbatchfeature)
Modules§
- batch
- Batch processing for high-performance distance calculations.
- detection
- Smart coordinate format detection with early termination optimization.
- euclid
- Euclidean (flat-plane) distance calculations.
- format_
batch - formats
- geodesic
- Geodesic (Earth-aware) distance calculations.
Structs§
- LngLat
- A geographic coordinate in decimal degrees.