pub struct Point<T = f64>(pub Coordinate<T>) 
where
    T: CoordNum
;
Expand description

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::{coord, Point};
let p1: Point = (0., 1.).into();
let c = coord! { x: 10., y: 20. };
let p2: Point = c.into();

Tuple Fields

0: Coordinate<T>

Implementations

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

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

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

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

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

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);
👎 Deprecated:

use Point::x instead, it’s less ambiguous

Returns the longitude/horizontal component of the point.

Examples
use geo_types::Point;

let p = Point::new(1.234, 2.345);

assert_eq!(p.x(), 1.234);
👎 Deprecated:

use Point::set_x instead, it’s less ambiguous

Sets the longitude/horizontal component of the point.

Examples
use geo_types::Point;

let mut p = Point::new(1.234, 2.345);
#[allow(deprecated)]
p.set_lng(9.876);

assert_eq!(p.x(), 9.876);
👎 Deprecated:

use Point::y instead, it’s less ambiguous

Returns the latitude/vertical component of the point.

Examples
use geo_types::Point;

let p = Point::new(1.234, 2.345);

assert_eq!(p.y(), 2.345);
👎 Deprecated:

use Point::set_y instead, it’s less ambiguous

Sets the latitude/vertical component of the point.

Examples
use geo_types::Point;

let mut p = Point::new(1.234, 2.345);
#[allow(deprecated)]
p.set_lat(9.876);

assert_eq!(p.y(), 9.876);

Returns the dot product of the two points: dot = x1 * x2 + y1 * y2

Examples
use geo_types::{point, Point};

let point = point! { x: 1.5, y: 0.5 };
let dot = point.dot(point! { x: 2.0, y: 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.

Note on Robustness

This function is not robust against floating-point errors. The geo crate offers robust predicates for standard numeric types using the Kernel trait, and these should be preferred if possible.

Examples
use geo_types::point;

let point_a = point! { x: 1., y: 2. };
let point_b = point! { x: 3., y: 5. };
let point_c = point! { x: 7., y: 12. };

let cross = point_a.cross_prod(point_b, point_c);

assert_eq!(cross, 2.0)

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

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

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

The resulting type after applying the + operator.

Add a point to the given point and assign it to the original point.

Examples
use geo_types::Point;

let mut p = Point::new(1.25, 2.5);
p += Point::new(1.5, 2.5);

assert_eq!(p.x(), 2.75);
assert_eq!(p.y(), 5.0);

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

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

The resulting type after applying the / operator.

Scaler division of a point in place

Examples
use geo_types::Point;

let mut p = Point::new(2.0, 3.0);
p /= 2.0;

assert_eq!(p.x(), 1.0);
assert_eq!(p.y(), 1.5);

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

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

The resulting type after applying the * operator.

Scaler multiplication of a point in place

Examples
use geo_types::Point;

let mut p = Point::new(2.0, 3.0);
p *= 2.0;

assert_eq!(p.x(), 4.0);
assert_eq!(p.y(), 6.0);

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

The resulting type after applying the - operator.

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

This method tests for !=.

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

The resulting type after applying the - operator.

Subtract a point from the given point and assign it to the original point.

Examples
use geo_types::Point;

let mut p = Point::new(1.25, 2.5);
p -= Point::new(1.5, 2.5);

assert_eq!(p.x(), -0.25);
assert_eq!(p.y(), 0.0);

Convert a Geometry enum into its inner type.

Fails if the enum case does not match the type you are trying to convert it to.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more