Struct rsgeo::prelude::Point [−][src]
pub struct Point { /* fields omitted */ }
Point data type
Including latitude
and longitude
as f32
Implementations
impl Point
[src]
pub fn new(lat: f32, long: f32) -> Result<Self, &'static str>
[src]
latitude
should be smaller than 90.0 and greater than -90.0
longitude
should be smaller than 180.0 and greater than -180.0
Example
use rsgeo::prelude::Point; let p1 = Point::new(30.12, 125.26).unwrap(); let p2 = Point::new(32.54, 107.15).unwrap(); let p3 = Point::new(30.12, 125.26).unwrap(); assert_ne!(p1, p2); assert_eq!(p1, p3);
pub fn distance(&self, other: &Self) -> f32
[src]
calculate distance between two points in earth sphere mode
Example
use rsgeo::prelude::Point; let p1 = Point::new(0.0, 0.0).unwrap(); let p2 = Point::new(0.0, 0.0).unwrap(); let p3 = Point::new(28.478, 179.395).unwrap(); let p4 = Point::new(28.33, -177.547).unwrap(); assert!(p1.distance(&p2).abs() < 0.001); assert!(p3.distance(&p4).abs() - 299878.88958 < 0.1);
pub fn distance_from_location(&self, other: &Location) -> f32
[src]
calculate distance between point and location
pub fn shortest_distance_from_trajectory(
&self,
other: &Trajectory
) -> Option<f32>
[src]
&self,
other: &Trajectory
) -> Option<f32>
calculate the shortest distance between point and trajectory
the time complexity is O(n)
,which n
is trajectory.len()
Example
use rsgeo::prelude::{Trajectory,Location,Point}; let p = Point::new(26.301,121.302).unwrap(); let loc1 = Location::new(Point::new(25.11,120.98).unwrap(),100); let loc2 = Location::new(Point::new(26.2,121.1).unwrap(),150); let loc3 = Location::new(Point::new(26.3,121.3).unwrap(),200); let mut t = Trajectory::with_capacity(3); t.push_location(&loc1); t.push_location(&loc2); t.push_location(&loc3); assert!((p.shortest_distance_from_trajectory(&t).unwrap() - p.distance_from_location(&loc3)).abs() < 1e-6);
pub fn degree(&self, other: &Point) -> f32
[src]
Calculate the degree which between the line and the north
degree in [-90.0,+90.0]
Example
use rsgeo::prelude::*; let p1 = Point::new(10.0,150.0).unwrap(); let p2 = Point::new(20.0,150.0).unwrap(); let p3 = Point::new(10.0,160.0).unwrap(); assert!((p1.degree(&p2)).abs() < 1e-5); assert!((p1.degree(&p3) - 90.0).abs() < 1e-5);
Trait Implementations
impl Clone for Point
[src]
impl Copy for Point
[src]
impl Debug for Point
[src]
impl Eq for Point
[src]
impl Hash for Point
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<Point> for Point
[src]
Auto Trait Implementations
impl RefUnwindSafe for Point
impl Send for Point
impl Sync for Point
impl Unpin for Point
impl UnwindSafe for Point
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,