Struct LonLat

Source
pub struct LonLat {
    pub lon: f64,
    pub lat: f64,
}
Expand description

This class represents a point on the unit sphere as a pair of latitude-longitude coordinates. Like the rest of the “geometry” package, the intent is to represent spherical geometry as a mathematical abstraction, so functions that are specifically related to the Earth’s geometry (e.g. easting/northing conversions) should be put elsewhere.

Fields§

§lon: f64

longitude in degrees

§lat: f64

latitude in degrees

Implementations§

Source§

impl LonLat

Source

pub fn new(lon: f64, lat: f64) -> Self

The default constructor sets the latitude and longitude to zero. This is mainly useful when declaring arrays, STL containers, etc.

Source

pub fn from_s2cellid(cellid: &S2CellId) -> LonLat

Convert a S2CellId to an LonLat

Source

pub fn from_s2_point(p: &S2Point) -> LonLat

Convert a direction vector (not necessarily unit length) to an LonLat.

Source

pub fn from_axis(&self, axis: u8) -> f64

return the value of the axis

Source

pub fn normalize(&mut self)

Normalize the coordinates to the range [-180, 180] and [-90, 90] deg.

Source

pub fn coords(self) -> (f64, f64)

Return the latitude or longitude coordinates in degrees.

Source

pub fn is_valid(&self) -> bool

Return true if the latitude is between -90 and 90 degrees inclusive and the longitude is between -180 and 180 degrees inclusive.

Source

pub fn to_point(&self) -> S2Point

Converts an LonLat to the equivalent unit-length vector. Unnormalized values (see Normalize()) are wrapped around the sphere as would be expected based on their definition as spherical angles. So for example the following pairs yield equivalent points (modulo numerical error): (90.5, 10) =~ (89.5, -170) (a, b) =~ (a + 360 * n, b) The maximum error in the result is 1.5 * DBL_EPSILON. (This does not include the error of converting degrees, E5, E6, or E7 to radians.)

Can be used just like an S2Point constructor. For example: S2Cap cap; cap.AddPoint(S2Point(latlon));

Source

pub fn to_point_gl(&self) -> S2Point

An alternative to to_point() that returns a GPU compatible vector.

Source

pub fn get_distance(&self, b: &LonLat) -> f64

Returns the distance (measured along the surface of the sphere) to the given LonLat, implemented using the Haversine formula. This is equivalent to

S1Angle(ToPoint(), o.ToPoint())

except that this function is slightly faster, and is also somewhat less accurate for distances approaching 180 degrees (see s1angle.h for details). Both LngLats must be normalized.

Trait Implementations§

Source§

impl Add<f64> for LonLat

Source§

type Output = LonLat

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for LonLat

Source§

type Output = LonLat

The resulting type after applying the + operator.
Source§

fn add(self, rhs: LonLat) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for LonLat

Source§

fn clone(&self) -> LonLat

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 Debug for LonLat

Source§

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

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

impl Default for LonLat

Source§

fn default() -> LonLat

Returns the “default value” for a type. Read more
Source§

impl Div<f64> for LonLat

Source§

type Output = LonLat

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for LonLat

Source§

type Output = LonLat

The resulting type after applying the / operator.
Source§

fn div(self, rhs: LonLat) -> Self::Output

Performs the / operation. Read more
Source§

impl From<&LonLat> for S2Point

Source§

fn from(lonlat: &LonLat) -> Self

Converts to this type from the input type.
Source§

impl From<&S2CellId> for LonLat

Source§

fn from(c: &S2CellId) -> Self

Converts to this type from the input type.
Source§

impl From<&S2Point> for LonLat

Source§

fn from(p: &S2Point) -> Self

Converts to this type from the input type.
Source§

impl From<LonLat> for S2CellId

Source§

fn from(value: LonLat) -> Self

Converts to this type from the input type.
Source§

impl Mul<LonLat> for f64

Source§

type Output = LonLat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: LonLat) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f64> for LonLat

Source§

type Output = LonLat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for LonLat

Source§

type Output = LonLat

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Ord for LonLat

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for LonLat

Source§

fn eq(&self, other: &LonLat) -> 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 PartialOrd for LonLat

Source§

fn partial_cmp(&self, other: &Self) -> 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 Sub<f64> for LonLat

Source§

type Output = LonLat

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for LonLat

Source§

type Output = LonLat

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: LonLat) -> Self::Output

Performs the - operation. Read more
Source§

impl Copy for LonLat

Source§

impl Eq for LonLat

Source§

impl StructuralPartialEq for LonLat

Auto Trait Implementations§

§

impl Freeze for LonLat

§

impl RefUnwindSafe for LonLat

§

impl Send for LonLat

§

impl Sync for LonLat

§

impl Unpin for LonLat

§

impl UnwindSafe for LonLat

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.