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]

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]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.