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
impl LonLat
Sourcepub fn new(lon: f64, lat: f64) -> Self
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.
Sourcepub fn from_s2cellid(cellid: &S2CellId) -> LonLat
pub fn from_s2cellid(cellid: &S2CellId) -> LonLat
Convert a S2CellId to an LonLat
Sourcepub fn from_s2_point(p: &S2Point) -> LonLat
pub fn from_s2_point(p: &S2Point) -> LonLat
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 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(&self, b: &LonLat) -> f64
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.