Struct PlaneProjection

Source
pub struct PlaneProjection { /* private fields */ }
Expand description

A plane projection, useful for blazingly fast approximate distance calculations. Based on WGS84 ellipsoid model of the Earth, plane projection provides 0.1% precision on distances under 500km at latitudes up to the 65°. See https://blog.mapbox.com/fast-geodesic-approximations-with-cheap-ruler-106f229ad016 for more details about the principle and formulas behind.

use plane_projection::PlaneProjection;

let proj = PlaneProjection::new(55.65);
let distance = proj.distance((55.704141722528554, 13.191304107330561), (55.60330902847681, 13.001973666557435));
assert_eq!(distance as u32, 16373);

let heading = proj.heading((55.704141722528554, 13.191304107330561), (55.60330902847681, 13.001973666557435));
assert_eq!(heading as u32, 226);

Implementations§

Source§

impl PlaneProjection

Source

pub fn new(latitude: f64) -> Self

Creates a plane projection to the Earth at provided latitude.

Source

pub fn project(&self, ll: LatLon) -> (f64, f64)

Projects a coordinate from (latitude, longitude) to the plane projection space.

This function is intended for low-level coordinate manipulation (like vector math) in the projection space and should not be used unless the built-in methods like PlaneProjection::distance() and PlaneProjection::distance_to_segment() are insufficient for your use case.

Source

pub fn square_distance(&self, a: LatLon, b: LatLon) -> f64

Square distance in meters between two points in (lat, lon) format.

Source

pub fn distance(&self, a: LatLon, b: LatLon) -> f64

Distance in meters between two points in (lat, lon) format.

Source

pub fn square_distance_to_segment( &self, point: LatLon, segment: (LatLon, LatLon), ) -> f64

Square distance in meters from point to the segment.

Source

pub fn distance_to_segment( &self, point: LatLon, segment: (LatLon, LatLon), ) -> f64

Distance in meters from point to the segment.

Source

pub fn heading(&self, a: LatLon, b: LatLon) -> f32

Heading (azimuth) in degrees from point a to point b in the range [0.0, 360.0) degrees, measured clockwise from North: 0.0 is North, 90.0 is East, 180.0 is South and 270.0 is West.

Trait Implementations§

Source§

impl Clone for PlaneProjection

Source§

fn clone(&self) -> PlaneProjection

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.