pub struct Coordinate<T = f64> where
    T: CoordNum
{ pub x: T, pub y: T, }
Expand description

A lightweight struct used to store coordinates on the 2-dimensional Cartesian plane.

Unlike Point (which in the future may contain additional information such as an envelope, a precision model, and spatial reference system information), a Coordinate only contains ordinate values and accessor methods.

This type implements the vector space operations: Add, Sub, Neg, Zero, Mul<T>, and Div<T> traits.

Semantics

This type does not represent any geospatial primitive, but is used in their definitions. The only requirement is that the coordinates it contains are valid numbers (for eg. not f64::NAN).

Fields

x: Ty: T

Implementations

Returns a tuple that contains the x/horizontal & y/vertical component of the coordinate.

Examples
use geo_types::coord;

let c = coord! {
    x: 40.02f64,
    y: 116.34,
};
let (x, y) = c.x_y();

assert_eq!(y, 116.34);
assert_eq!(x, 40.02f64);

Create a coordinate at the origin.

Examples

use geo_types::Coordinate;
use num_traits::Zero;

let p: Coordinate = Zero::zero();

assert_eq!(p.x, 0.);
assert_eq!(p.y, 0.);

Trait Implementations

Add two coordinates.

Examples

use geo_types::coord;

let p = coord! { x: 1.25, y: 2.5 };
let q = coord! { x: 1.5, y: 2.5 };
let sum = p + q;

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

The resulting type after applying the + operator.

Performs the + operation. Read more

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

Divide coordinate wise by a scalar.

Examples

use geo_types::coord;

let p = coord! { x: 5., y: 10. };
let q = p / 4.;

assert_eq!(q.x, 1.25);
assert_eq!(q.y, 2.5);

The resulting type after applying the / operator.

Performs the / operation. Read more

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

Multiply coordinate wise by a scalar.

Examples

use geo_types::coord;

let p = coord! { x: 1.25, y: 2.5 };
let q = p * 4.;

assert_eq!(q.x, 5.0);
assert_eq!(q.y, 10.0);

The resulting type after applying the * operator.

Performs the * operation. Read more

Negate a coordinate.

Examples

use geo_types::coord;

let p = coord! { x: 1.25, y: 2.5 };
let q = -p;

assert_eq!(q.x, -p.x);
assert_eq!(q.y, -p.y);

The resulting type after applying the - operator.

Performs the unary - operation. Read more

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

This method tests for !=.

Subtract a coordinate from another.

Examples

use geo_types::coord;

let p = coord! { x: 1.5, y: 2.5 };
let q = coord! { x: 1.25, y: 2.5 };
let diff = p - q;

assert_eq!(diff.x, 0.25);
assert_eq!(diff.y, 0.);

The resulting type after applying the - operator.

Performs the - operation. Read more

Returns the additive identity element of Self, 0. Read more

Returns true if self is equal to the additive identity.

Sets self to the additive identity element of Self, 0.

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