Skip to main content

Coordinate

Struct Coordinate 

Source
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 apart

Fields§

§latitude: f64

Degrees north of the equator, in [-90.0, 90.0].

§longitude: f64

Degrees east of the prime meridian, in [-180.0, 180.0].

Implementations§

Source§

impl Coordinate

Source

pub fn new(latitude: f64, longitude: f64) -> Self

Creates a coordinate from a latitude and longitude in decimal degrees.

§Arguments
  • latitude - degrees north of the equator.
  • longitude - degrees east of the prime meridian.
§Returns

The coordinate.

Source

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.

Source

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

Source§

fn clone(&self) -> Coordinate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Coordinate

Source§

impl Debug for Coordinate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Coordinate

Source§

fn eq(&self, other: &Coordinate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Coordinate

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.