[−][src]Struct latlon::Point
A single point in 2D space.
Points can be created using the Point::new
constructor,
the [point!
] macro, or from a Coordinate
, two-element
tuples, or arrays – see the From
impl section for a
complete list.
Semantics
The interior of the point is itself (a singleton set),
and its boundary is empty. A point is valid if and
only if the Coordinate
is valid.
Examples
use geo_types::{Coordinate, Point}; let p1: Point<f64> = (0., 1.).into(); let c = Coordinate { x: 10., y: 20. }; let p2: Point<f64> = c.into();
Implementations
impl<T> Point<T> where
T: CoordNum,
[src]
T: CoordNum,
pub fn new(x: T, y: T) -> Point<T>
[src]
Creates a new point.
Examples
use geo_types::Point; let p = Point::new(1.234, 2.345); assert_eq!(p.x(), 1.234); assert_eq!(p.y(), 2.345);
pub fn x(self) -> T
[src]
Returns the x/horizontal component of the point.
Examples
use geo_types::Point; let p = Point::new(1.234, 2.345); assert_eq!(p.x(), 1.234);
pub fn set_x(&mut self, x: T) -> &mut Point<T>
[src]
Sets the x/horizontal component of the point.
Examples
use geo_types::Point; let mut p = Point::new(1.234, 2.345); p.set_x(9.876); assert_eq!(p.x(), 9.876);
pub fn y(self) -> T
[src]
Returns the y/vertical component of the point.
Examples
use geo_types::Point; let p = Point::new(1.234, 2.345); assert_eq!(p.y(), 2.345);
pub fn set_y(&mut self, y: T) -> &mut Point<T>
[src]
Sets the y/vertical component of the point.
Examples
use geo_types::Point; let mut p = Point::new(1.234, 2.345); p.set_y(9.876); assert_eq!(p.y(), 9.876);
pub fn x_y(self) -> (T, T)
[src]
Returns a tuple that contains the x/horizontal & y/vertical component of the point.
Examples
use geo_types::Point; let mut p = Point::new(1.234, 2.345); let (x, y) = p.x_y(); assert_eq!(y, 2.345); assert_eq!(x, 1.234);
pub fn lng(self) -> T
[src]
Returns the longitude/horizontal component of the point.
Examples
use geo_types::Point; let p = Point::new(1.234, 2.345); assert_eq!(p.lng(), 1.234);
pub fn set_lng(&mut self, lng: T) -> &mut Point<T>
[src]
Sets the longitude/horizontal component of the point.
Examples
use geo_types::Point; let mut p = Point::new(1.234, 2.345); p.set_lng(9.876); assert_eq!(p.lng(), 9.876);
pub fn lat(self) -> T
[src]
Returns the latitude/vertical component of the point.
Examples
use geo_types::Point; let p = Point::new(1.234, 2.345); assert_eq!(p.lat(), 2.345);
pub fn set_lat(&mut self, lat: T) -> &mut Point<T>
[src]
Sets the latitude/vertical component of the point.
Examples
use geo_types::Point; let mut p = Point::new(1.234, 2.345); p.set_lat(9.876); assert_eq!(p.lat(), 9.876);
impl<T> Point<T> where
T: CoordNum,
[src]
T: CoordNum,
pub fn dot(self, other: Point<T>) -> T
[src]
Returns the dot product of the two points:
dot = x1 * x2 + y1 * y2
Examples
use geo_types::{Coordinate, Point}; let point = Point(Coordinate { x: 1.5, y: 0.5 }); let dot = point.dot(Point(Coordinate { x: 2.0, y: 4.5 })); assert_eq!(dot, 5.25);
pub fn cross_prod(self, point_b: Point<T>, point_c: Point<T>) -> T
[src]
Returns the cross product of 3 points. A positive value implies
self
→ point_b
→ point_c
is counter-clockwise, negative implies
clockwise.
Examples
use geo_types::{Coordinate, Point}; let point_a = Point(Coordinate { x: 1., y: 2. }); let point_b = Point(Coordinate { x: 3., y: 5. }); let point_c = Point(Coordinate { x: 7., y: 12. }); let cross = point_a.cross_prod(point_b, point_c); assert_eq!(cross, 2.0)
impl<T> Point<T> where
T: CoordFloat,
[src]
T: CoordFloat,
pub fn to_degrees(self) -> Point<T>
[src]
Converts the (x,y) components of Point to degrees
Example
use geo_types::Point; let p = Point::new(1.234, 2.345); let (x, y): (f32, f32) = p.to_degrees().x_y(); assert_eq!(x.round(), 71.0); assert_eq!(y.round(), 134.0);
pub fn to_radians(self) -> Point<T>
[src]
Converts the (x,y) components of Point to radians
Example
use geo_types::Point; let p = Point::new(180.0, 341.5); let (x, y): (f32, f32) = p.to_radians().x_y(); assert_eq!(x.round(), 3.0); assert_eq!(y.round(), 6.0);
Trait Implementations
impl<T> Add<Point<T>> for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
type Output = Point<T>
The resulting type after applying the +
operator.
pub fn add(self, rhs: Point<T>) -> Point<T>
[src]
Add a point to the given point.
Examples
use geo_types::Point; let p = Point::new(1.25, 2.5) + Point::new(1.5, 2.5); assert_eq!(p.x(), 2.75); assert_eq!(p.y(), 5.0);
impl<T> Clone for Point<T> where
T: Clone + CoordNum,
[src]
T: Clone + CoordNum,
impl<T> Copy for Point<T> where
T: Copy + CoordNum,
[src]
T: Copy + CoordNum,
impl<T> Debug for Point<T> where
T: Debug + CoordNum,
[src]
T: Debug + CoordNum,
impl<T> Div<T> for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
type Output = Point<T>
The resulting type after applying the /
operator.
pub fn div(self, rhs: T) -> Point<T>
[src]
Scaler division of a point
Examples
use geo_types::Point; let p = Point::new(2.0, 3.0) / 2.0; assert_eq!(p.x(), 1.0); assert_eq!(p.y(), 1.5);
impl<T> Eq for Point<T> where
T: Eq + CoordNum,
[src]
T: Eq + CoordNum,
impl<T> From<[T; 2]> for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<T> From<(T, T)> for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<T> From<Coordinate<T>> for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
pub fn from(x: Coordinate<T>) -> Point<T>
[src]
impl<T> Hash for Point<T> where
T: Hash + CoordNum,
[src]
T: Hash + CoordNum,
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Mul<T> for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
type Output = Point<T>
The resulting type after applying the *
operator.
pub fn mul(self, rhs: T) -> Point<T>
[src]
Scaler multiplication of a point
Examples
use geo_types::Point; let p = Point::new(2.0, 3.0) * 2.0; assert_eq!(p.x(), 4.0); assert_eq!(p.y(), 6.0);
impl<T> Neg for Point<T> where
T: CoordNum + Neg<Output = T>,
[src]
T: CoordNum + Neg<Output = T>,
type Output = Point<T>
The resulting type after applying the -
operator.
pub fn neg(self) -> Point<T>
[src]
Returns a point with the x and y components negated.
Examples
use geo_types::Point; let p = -Point::new(-1.25, 2.5); assert_eq!(p.x(), 1.25); assert_eq!(p.y(), -2.5);
impl<T> PartialEq<Point<T>> for Point<T> where
T: PartialEq<T> + CoordNum,
[src]
T: PartialEq<T> + CoordNum,
impl<T> StructuralEq for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<T> StructuralPartialEq for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
impl<T> Sub<Point<T>> for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
type Output = Point<T>
The resulting type after applying the -
operator.
pub fn sub(self, rhs: Point<T>) -> Point<T>
[src]
Subtract a point from the given point.
Examples
use geo_types::Point; let p = Point::new(1.25, 3.0) - Point::new(1.5, 2.5); assert_eq!(p.x(), -0.25); assert_eq!(p.y(), 0.5);
impl<T> TryFrom<Geometry<T>> for Point<T> where
T: CoordNum,
[src]
T: CoordNum,
Auto Trait Implementations
impl<T> RefUnwindSafe for Point<T> where
T: RefUnwindSafe,
[src]
T: RefUnwindSafe,
impl<T> Send for Point<T> where
T: Send,
[src]
T: Send,
impl<T> Sync for Point<T> where
T: Sync,
[src]
T: Sync,
impl<T> Unpin for Point<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> UnwindSafe for Point<T> where
T: UnwindSafe,
[src]
T: UnwindSafe,
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>,