FlatPoint

Struct FlatPoint 

Source
pub struct FlatPoint<T> {
    pub x: T,
    pub y: T,
}
Expand description

Representation of a geographical point on Earth as projected by a FlatProjection instance.

let (lon, lat) = (6.186389, 50.823194);

let proj = FlatProjection::new(6., 51.);

let flat_point = proj.project(lon, lat);

Fields§

§x: T

X-axis component of the flat-surface point in kilometers

§y: T

Y-axis component of the flat-surface point in kilometers

Implementations§

Source§

impl<T: Float> FlatPoint<T>

Source

pub fn distance(&self, other: &FlatPoint<T>) -> T

Calculates the approximate distance in kilometers from this FlatPoint to another.

let (lon1, lat1) = (6.186389, 50.823194);
let (lon2, lat2) = (6.953333, 51.301389);

let proj = FlatProjection::new(6.5, 51.05);

let p1 = proj.project(lon1, lat1);
let p2 = proj.project(lon2, lat2);

let distance = p1.distance(&p2);
// -> 75.648 km
Source

pub fn distance_squared(&self, other: &FlatPoint<T>) -> T

Calculates the approximate squared distance from this FlatPoint to another.

This method can be used for fast distance comparisons.

Source

pub fn bearing(&self, other: &FlatPoint<T>) -> T

Calculates the approximate average bearing in degrees between -180 and 180 from this FlatPoint to another.

let (lon1, lat1) = (6.186389, 50.823194);
let (lon2, lat2) = (6.953333, 51.301389);

let proj = FlatProjection::new(6.5, 51.05);

let p1 = proj.project(lon1, lat1);
let p2 = proj.project(lon2, lat2);

let bearing = p1.bearing(&p2);
// -> 45.3°
Source

pub fn distance_bearing(&self, other: &FlatPoint<T>) -> (T, T)

Calculates the approximate distance and average bearing from this FlatPoint to another.

let (lon1, lat1) = (6.186389, 50.823194);
let (lon2, lat2) = (6.953333, 51.301389);

let proj = FlatProjection::new(6.5, 51.05);

let p1 = proj.project(lon1, lat1);
let p2 = proj.project(lon2, lat2);

let (distance, bearing) = p1.distance_bearing(&p2);
// -> 75.648 km and 45.3°
Source

pub fn destination(&self, dist: T, bearing: T) -> FlatPoint<T>

Returns a new FlatPoint given distance and bearing from this FlatPoint.

let (lon, lat) = (30.5, 50.5);

let proj = FlatProjection::new(31., 50.);

let p1 = proj.project(lon, lat);
let (distance, bearing) = (1., 45.0);
let p2 = p1.destination(distance, bearing);
Source

pub fn offset(&self, dx: T, dy: T) -> FlatPoint<T>

Returns a new FlatPoint given easting and northing offsets (in kilometers) from this FlatPoint.

let (lon, lat) = (30.5, 50.5);

let proj = FlatProjection::new(31., 50.);

let p1 = proj.project(lon, lat);
let p2 = p1.offset(10., 10.);

Trait Implementations§

Source§

impl<T: Clone> Clone for FlatPoint<T>

Source§

fn clone(&self) -> FlatPoint<T>

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

impl<T: Debug> Debug for FlatPoint<T>

Source§

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

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

impl<T: PartialEq> PartialEq for FlatPoint<T>

Source§

fn eq(&self, other: &FlatPoint<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<T: PartialOrd> PartialOrd for FlatPoint<T>

Source§

fn partial_cmp(&self, other: &FlatPoint<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Copy> Copy for FlatPoint<T>

Source§

impl<T> StructuralPartialEq for FlatPoint<T>

Auto Trait Implementations§

§

impl<T> Freeze for FlatPoint<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for FlatPoint<T>
where T: RefUnwindSafe,

§

impl<T> Send for FlatPoint<T>
where T: Send,

§

impl<T> Sync for FlatPoint<T>
where T: Sync,

§

impl<T> Unpin for FlatPoint<T>
where T: Unpin,

§

impl<T> UnwindSafe for FlatPoint<T>
where T: UnwindSafe,

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.