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]

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);

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);

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);

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);

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);

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);

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);

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);

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);

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);

Returns the cross product of 3 points. A positive value implies selfpoint_bpoint_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]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Clone> Clone for Point<T> where
    T: CoordinateType
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Copy> Copy for Point<T> where
    T: CoordinateType
[src]

impl<T: Debug> Debug for Point<T> where
    T: CoordinateType
[src]

Formats the value using the given formatter. Read more

impl<T: CoordinateType> From<Coordinate<T>> for Point<T>
[src]

Performs the conversion.

impl<T: CoordinateType> From<(T, T)> for Point<T>
[src]

Performs the conversion.

impl<T> Neg for Point<T> where
    T: CoordinateType + Neg<Output = T> + ToPrimitive
[src]

The resulting type after applying the - operator.

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]

The resulting type after applying the + operator.

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]

The resulting type after applying the - operator.

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]

Performs the conversion.

impl<T: CoordinateType> From<Point<T>> for Geometry<T>
[src]

Performs the conversion.

Auto Trait Implementations

impl<T> Send for Point<T> where
    T: Send

impl<T> Sync for Point<T> where
    T: Sync