pub struct LonLat<M: Clone + Default = MValue>(pub VectorPoint<M>);Expand description
§Longitude-Latitude Point container
§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.
This struct implements the GetXY and GetM traits.
§Usage
Methods that are available:
LonLat::new: Create a new LonLatLonLat::take: Take ownership of the underlying VectorPointLonLat::lon: Return the longitude in degreesLonLat::lat: Return the latitude in degreesLonLat::from_s2cellid: Convert aS2CellIdto an LonLatLonLat::from_s2_point: Convert aS2Pointto an LonLatLonLat::normalize: Normalize the coordinates to the range [-180, 180] and [-90, 90] deg.LonLat::coords: Return the latitude or longitude coordinates in degrees.LonLat::to_angles: Return the latitude and longitude coordinates in radians.LonLat::is_valid: Return true if the latitude is between -90 and 90 degrees inclusive and the longitude is between -180 and 180 degrees inclusive.LonLat::to_point: Converts an LonLat to the equivalent unit-length vector.LonLat::to_point_gl: An alternative toLonLat::to_pointthat returns a GPU compatible vector.LonLat::get_distance:Returns the distance (measured along the surface of the sphere) to the given LonLat.LonLat::get_bearing: Returns the bearing from the first point to the second point.
Tuple Fields§
§0: VectorPoint<M>Implementations§
Source§impl<M: Clone + Default> LonLat<M>
impl<M: Clone + Default> LonLat<M>
Sourcepub fn take(&mut self) -> VectorPoint<M>
pub fn take(&mut self) -> VectorPoint<M>
Take the underlying VectorPoint
Sourcepub fn from_s2cellid(cellid: S2CellId) -> Self
pub fn from_s2cellid(cellid: S2CellId) -> Self
Convert a S2CellId to an LonLat
Sourcepub fn from_s2_point(p: &S2Point) -> Self
pub fn from_s2_point(p: &S2Point) -> Self
Convert a direction vector (not necessarily unit length) to an LonLat.
Sourcepub fn normalize(&mut self)
pub fn normalize(&mut self)
Normalize the coordinates to the range [-180, 180] and [-90, 90] deg.
Sourcepub fn to_angles(&self) -> (S1Angle, S1Angle)
pub fn to_angles(&self) -> (S1Angle, S1Angle)
Return the latitude and longitude coordinates in radians.
Sourcepub fn is_valid(&self) -> bool
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.
Sourcepub fn to_point(&self) -> S2Point
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));
Sourcepub fn to_point_gl(&self) -> S2Point
pub fn to_point_gl(&self) -> S2Point
An alternative to to_point() that returns a GPU compatible vector.
Sourcepub fn get_distance<M2: Clone + Default>(&self, b: &LonLat<M2>) -> f64
pub fn get_distance<M2: Clone + Default>(&self, b: &LonLat<M2>) -> 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 Ord for LonLat
impl Ord for LonLat
Source§impl PartialOrd for LonLat
impl PartialOrd for LonLat
impl Eq for LonLat
impl<M: Clone + Default> StructuralPartialEq for LonLat<M>
Auto Trait Implementations§
impl<M> Freeze for LonLat<M>where
M: Freeze,
impl<M> RefUnwindSafe for LonLat<M>where
M: RefUnwindSafe,
impl<M> Send for LonLat<M>where
M: Send,
impl<M> Sync for LonLat<M>where
M: Sync,
impl<M> Unpin for LonLat<M>where
M: Unpin,
impl<M> UnwindSafe for LonLat<M>where
M: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more