pub struct Coord<T: CoordNum = f64> {
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 Coord
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: T
§y: T
Implementations§
Trait Implementations§
source§impl<T: CoordNum> Add for Coord<T>
impl<T: CoordNum> Add for Coord<T>
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);
source§impl<'de, T> Deserialize<'de> for Coord<T>where
T: Deserialize<'de> + CoordNum,
impl<'de, T> Deserialize<'de> for Coord<T>where
T: Deserialize<'de> + CoordNum,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<T: CoordNum> Div<T> for Coord<T>
impl<T: CoordNum> Div<T> for Coord<T>
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);
source§impl<T: CoordNum> Mul<T> for Coord<T>
impl<T: CoordNum> Mul<T> for Coord<T>
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);
source§impl<T> Neg for Coord<T>
impl<T> Neg for Coord<T>
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);
source§impl<T: CoordNum> Sub for Coord<T>
impl<T: CoordNum> Sub for Coord<T>
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.);
impl<T: Copy + CoordNum> Copy for Coord<T>
impl<T: Eq + CoordNum> Eq for Coord<T>
impl<T: CoordNum> StructuralPartialEq for Coord<T>
Auto Trait Implementations§
impl<T> Freeze for Coord<T>where
T: Freeze,
impl<T> RefUnwindSafe for Coord<T>where
T: RefUnwindSafe,
impl<T> Send for Coord<T>where
T: Send,
impl<T> Sync for Coord<T>where
T: Sync,
impl<T> Unpin for Coord<T>where
T: Unpin,
impl<T> UnwindSafe for Coord<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)