pub struct Coordinate {
pub latitude: f64,
pub longitude: f64,
}Expand description
A position on the Earth, in decimal degrees.
Latitude and longitude are kept as f64 because a GPS fix needs more precision
than f32 can hold: rounding a coordinate to f32 can move it tens of metres.
§Examples
Great-circle distance between two cities, in kilometres:
use pamoja_kit::Coordinate;
let nairobi = Coordinate::new(-1.2921, 36.8219);
let mombasa = Coordinate::new(-4.0435, 39.6682);
let km = nairobi.distance_to(mombasa) / 1000.0;
assert!((km - 440.0).abs() < 10.0); // about 440 km apartFields§
§latitude: f64Degrees north of the equator, in [-90.0, 90.0].
longitude: f64Degrees east of the prime meridian, in [-180.0, 180.0].
Implementations§
Source§impl Coordinate
impl Coordinate
Sourcepub fn distance_to(&self, other: Coordinate) -> f64
pub fn distance_to(&self, other: Coordinate) -> f64
Returns the distance to another coordinate in metres.
This is the great-circle distance: the shortest path over the surface of a spherical Earth. The technique one layer down is the haversine formula, which stays numerically stable for the short distances a field deployment cares about, down to points a few metres apart.
§Arguments
other- the coordinate to measure to.
§Returns
The distance in metres, always zero or positive.
Sourcepub fn bearing_to(&self, other: Coordinate) -> f64
pub fn bearing_to(&self, other: Coordinate) -> f64
Returns the initial bearing to another coordinate, in degrees clockwise from north.
This is the forward azimuth of the great-circle path: the compass heading to set off
on to reach other by the shortest route. Because a great circle curves, the bearing
changes along the way; this is the heading at the start. The result is normalised to
[0.0, 360.0), with 0 north, 90 east, 180 south, and 270 west.
§Arguments
other- the coordinate to head toward.
§Returns
The initial bearing in degrees, in [0.0, 360.0). When both points are the same the
result is 0.0.
Trait Implementations§
Source§impl Clone for Coordinate
impl Clone for Coordinate
Source§fn clone(&self) -> Coordinate
fn clone(&self) -> Coordinate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Coordinate
Source§impl Debug for Coordinate
impl Debug for Coordinate
Source§impl PartialEq for Coordinate
impl PartialEq for Coordinate
Source§fn eq(&self, other: &Coordinate) -> bool
fn eq(&self, other: &Coordinate) -> bool
self and other values to be equal, and is used by ==.