Enum Geometry

Source
pub enum Geometry<T: CoordNum = f64> {
    Point(Point<T>),
    Line(Line<T>),
    LineString(LineString<T>),
    Polygon(Polygon<T>),
    MultiPoint(MultiPoint<T>),
    MultiLineString(MultiLineString<T>),
    MultiPolygon(MultiPolygon<T>),
    GeometryCollection(GeometryCollection<T>),
    Rect(Rect<T>),
    Triangle(Triangle<T>),
}
Expand description

An enum representing any possible geometry type.

All geometry variants (Point, LineString, etc.) can be converted to a Geometry using Into::into. Conversely, TryFrom::try_from can be used to convert a Geometry back to one of it’s specific enum members.

§Example

use std::convert::TryFrom;
use geo_types::{Point, point, Geometry, GeometryCollection};
let p = point!(x: 1.0, y: 1.0);
let pe: Geometry = p.into();
let pn = Point::try_from(pe).unwrap();

Variants§

§

Point(Point<T>)

§

Line(Line<T>)

§

LineString(LineString<T>)

§

Polygon(Polygon<T>)

§

MultiPoint(MultiPoint<T>)

§

MultiLineString(MultiLineString<T>)

§

MultiPolygon(MultiPolygon<T>)

§

GeometryCollection(GeometryCollection<T>)

§

Rect(Rect<T>)

§

Triangle(Triangle<T>)

Implementations§

Source§

impl<T: CoordNum> Geometry<T>

Source

pub fn into_point(self) -> Option<Point<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Point>

If this Geometry is a Point, then return that, else None.

§Examples
use geo_types::*;
use std::convert::TryInto;

let g = Geometry::Point(Point::new(0., 0.));
let p2: Point<f32> = g.try_into().unwrap();
assert_eq!(p2, Point::new(0., 0.,));
Source

pub fn into_line_string(self) -> Option<LineString<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<LineString>

If this Geometry is a LineString, then return that LineString, else None.

Source

pub fn into_line(self) -> Option<Line<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Line>

If this Geometry is a Line, then return that Line, else None.

Source

pub fn into_polygon(self) -> Option<Polygon<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Polygon>

If this Geometry is a Polygon, then return that, else None.

Source

pub fn into_multi_point(self) -> Option<MultiPoint<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPoint>

If this Geometry is a MultiPoint, then return that, else None.

Source

pub fn into_multi_line_string(self) -> Option<MultiLineString<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiLineString>

If this Geometry is a MultiLineString, then return that, else None.

Source

pub fn into_multi_polygon(self) -> Option<MultiPolygon<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPolygon>

If this Geometry is a MultiPolygon, then return that, else None.

Trait Implementations§

Source§

impl<T> AbsDiffEq for Geometry<T>
where T: CoordNum + AbsDiffEq<Epsilon = T>,

Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

Equality assertion with an absolute limit.

§Examples
use geo_types::{Geometry, polygon};

let a: Geometry<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7., y: 9.), (x: 0., y: 0.)].into();
let b: Geometry<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7.01, y: 9.), (x: 0., y: 0.)].into();

approx::assert_abs_diff_eq!(a, b, epsilon=0.1);
approx::assert_abs_diff_ne!(a, b, epsilon=0.001);
Source§

type Epsilon = T

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
Source§

impl<T: Clone + CoordNum> Clone for Geometry<T>

Source§

fn clone(&self) -> Geometry<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: CoordNum> Debug for Geometry<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: CoordNum> From<Line<T>> for Geometry<T>

Source§

fn from(x: Line<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordNum> From<LineString<T>> for Geometry<T>

Source§

fn from(x: LineString<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordNum> From<MultiLineString<T>> for Geometry<T>

Source§

fn from(x: MultiLineString<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordNum> From<MultiPoint<T>> for Geometry<T>

Source§

fn from(x: MultiPoint<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordNum> From<MultiPolygon<T>> for Geometry<T>

Source§

fn from(x: MultiPolygon<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordNum> From<Point<T>> for Geometry<T>

Source§

fn from(x: Point<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordNum> From<Polygon<T>> for Geometry<T>

Source§

fn from(x: Polygon<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordNum> From<Rect<T>> for Geometry<T>

Source§

fn from(x: Rect<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordNum> From<Triangle<T>> for Geometry<T>

Source§

fn from(x: Triangle<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + CoordNum> Hash for Geometry<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T: PartialEq + CoordNum> PartialEq for Geometry<T>

Source§

fn eq(&self, other: &Geometry<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> RelativeEq for Geometry<T>
where T: CoordNum + RelativeEq<Epsilon = T>,

Source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

Equality assertion within a relative limit.

§Examples
use geo_types::{Geometry, polygon};

let a: Geometry<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7., y: 9.), (x: 0., y: 0.)].into();
let b: Geometry<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7.01, y: 9.), (x: 0., y: 0.)].into();

approx::assert_relative_eq!(a, b, max_relative=0.1);
approx::assert_relative_ne!(a, b, max_relative=0.001);
Source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of RelativeEq::relative_eq.
Source§

impl<T: CoordNum> TryFrom<Geometry<T>> for Line<T>

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: CoordNum> TryFrom<Geometry<T>> for LineString<T>

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: CoordNum> TryFrom<Geometry<T>> for MultiLineString<T>

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: CoordNum> TryFrom<Geometry<T>> for MultiPoint<T>

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: CoordNum> TryFrom<Geometry<T>> for MultiPolygon<T>

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: CoordNum> TryFrom<Geometry<T>> for Point<T>

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: CoordNum> TryFrom<Geometry<T>> for Polygon<T>

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: CoordNum> TryFrom<Geometry<T>> for Rect<T>

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: CoordNum> TryFrom<Geometry<T>> for Triangle<T>

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.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T> UlpsEq for Geometry<T>
where T: CoordNum + UlpsEq<Epsilon = T>,

Source§

fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

Approximate equality assertion for floating point geometries based on the number of representable floats that fit between the two numbers being compared.

“relative_eq” might be more intuitive, but it does floating point math in its error calculation, introducing its own error into the error calculation.

Working with ulps avoids this problem. max_ulps means “how many floating points are representable that fit between these two numbers”, which lets us tune how “sloppy” we’re willing to be while avoiding any danger of floating point rounding in the comparison itself.

§Examples
use geo_types::{Geometry, Point};

let a: Geometry = Point::new(1.0, 1.0).into();
let b: Geometry = Point::new(1.0 + 4.0 * f64::EPSILON, 1.0 + 4.0 * f64::EPSILON).into();

approx::assert_ulps_eq!(a, b);
approx::assert_ulps_ne!(a, b, max_ulps=3);
approx::assert_ulps_eq!(a, b, max_ulps=5);
§References

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
Source§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of UlpsEq::ulps_eq.
Source§

impl<T: Eq + CoordNum> Eq for Geometry<T>

Source§

impl<T: CoordNum> StructuralPartialEq for Geometry<T>

Auto Trait Implementations§

§

impl<T> Freeze for Geometry<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Geometry<T>
where T: RefUnwindSafe,

§

impl<T> Send for Geometry<T>
where T: Send,

§

impl<T> Sync for Geometry<T>
where T: Sync,

§

impl<T> Unpin for Geometry<T>
where T: Unpin,

§

impl<T> UnwindSafe for Geometry<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.