Struct geo_types::Point [−][src]
pub struct Point<T>(pub Coordinate<T>)
where
T: CoordinateType;
A single Point in 2D space.
Points can be created using the new(x, y)
constructor, or from a Coordinate
or pair of points.
use geo_types::{Point, Coordinate}; let p1: Point<f64> = (0., 1.).into(); let c = Coordinate{ x: 10., y: 20.}; let p2: Point<f64> = c.into();
Methods
impl<T> Point<T> where
T: CoordinateType + ToPrimitive,
[src]
impl<T> Point<T> where
T: CoordinateType + ToPrimitive,
pub fn new(x: T, y: T) -> Point<T>
[src]
pub fn new(x: T, y: T) -> Point<T>
Creates a new point.
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]
pub fn x(&self) -> T
Returns the x/horizontal component of the point.
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]
pub fn set_x(&mut self, x: T) -> &mut Point<T>
Sets the x/horizontal component of the point.
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]
pub fn y(&self) -> T
Returns the y/vertical component of the point.
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]
pub fn set_y(&mut self, y: T) -> &mut Point<T>
Sets the y/vertical component of the point.
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 lng(&self) -> T
[src]
pub fn lng(&self) -> T
Returns the longitude/horizontal component of the point.
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]
pub fn set_lng(&mut self, lng: T) -> &mut Point<T>
Sets the longitude/horizontal component of the point.
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]
pub fn lat(&self) -> T
Returns the latitude/vertical component of the point.
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]
pub fn set_lat(&mut self, lat: T) -> &mut Point<T>
Sets the latitude/vertical component of the point.
use geo_types::Point; let mut p = Point::new(1.234, 2.345); p.set_lat(9.876); assert_eq!(p.lat(), 9.876);
pub fn dot(&self, point: &Point<T>) -> T
[src]
pub fn dot(&self, point: &Point<T>) -> T
Returns the dot product of the two points:
dot = x1 * x2 + y1 * y2
use geo_types::Point; let p = Point::new(1.5, 0.5); let dot = p.dot(&Point::new(2.0, 4.5)); assert_eq!(dot, 5.25);
pub fn cross_prod(&self, point_b: &Point<T>, point_c: &Point<T>) -> T where
T: Float,
[src]
pub fn cross_prod(&self, point_b: &Point<T>, point_c: &Point<T>) -> T where
T: Float,
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::Point; let p_a = Point::new(1.0, 2.0); let p_b = Point::new(3.0,5.0); let p_c = Point::new(7.0,12.0); let cross = p_a.cross_prod(&p_b, &p_c); assert_eq!(cross, 2.0)
Trait Implementations
impl<T: PartialEq> PartialEq for Point<T> where
T: CoordinateType,
[src]
impl<T: PartialEq> PartialEq for Point<T> where
T: CoordinateType,
fn eq(&self, other: &Point<T>) -> bool
[src]
fn eq(&self, other: &Point<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Point<T>) -> bool
[src]
fn ne(&self, other: &Point<T>) -> bool
This method tests for !=
.
impl<T: Clone> Clone for Point<T> where
T: CoordinateType,
[src]
impl<T: Clone> Clone for Point<T> where
T: CoordinateType,
fn clone(&self) -> Point<T>
[src]
fn clone(&self) -> Point<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T: Copy> Copy for Point<T> where
T: CoordinateType,
[src]
impl<T: Copy> Copy for Point<T> where
T: CoordinateType,
impl<T: Debug> Debug for Point<T> where
T: CoordinateType,
[src]
impl<T: Debug> Debug for Point<T> where
T: CoordinateType,
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T: CoordinateType> From<Coordinate<T>> for Point<T>
[src]
impl<T: CoordinateType> From<Coordinate<T>> for Point<T>
fn from(x: Coordinate<T>) -> Point<T>
[src]
fn from(x: Coordinate<T>) -> Point<T>
Performs the conversion.
impl<T: CoordinateType> From<(T, T)> for Point<T>
[src]
impl<T: CoordinateType> From<(T, T)> for Point<T>
impl<T> Neg for Point<T> where
T: CoordinateType + Neg<Output = T> + ToPrimitive,
[src]
impl<T> Neg for Point<T> where
T: CoordinateType + Neg<Output = T> + ToPrimitive,
type Output = Point<T>
The resulting type after applying the -
operator.
fn neg(self) -> Point<T>
[src]
fn neg(self) -> Point<T>
Returns a point with the x and y components negated.
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> Add for Point<T> where
T: CoordinateType + ToPrimitive,
[src]
impl<T> Add for Point<T> where
T: CoordinateType + ToPrimitive,
type Output = Point<T>
The resulting type after applying the +
operator.
fn add(self, rhs: Point<T>) -> Point<T>
[src]
fn add(self, rhs: Point<T>) -> Point<T>
Add a point to the given point.
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> Sub for Point<T> where
T: CoordinateType + ToPrimitive,
[src]
impl<T> Sub for Point<T> where
T: CoordinateType + ToPrimitive,
type Output = Point<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Point<T>) -> Point<T>
[src]
fn sub(self, rhs: Point<T>) -> Point<T>
Subtract a point from the given point.
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: CoordinateType> From<[T; 2]> for Point<T>
[src]
impl<T: CoordinateType> From<[T; 2]> for Point<T>
impl<T: CoordinateType> From<Point<T>> for Geometry<T>
[src]
impl<T: CoordinateType> From<Point<T>> for Geometry<T>