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>
impl<T: CoordNum> Geometry<T>
Sourcepub fn into_point(self) -> Option<Point<T>>
👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Point>
pub fn into_point(self) -> Option<Point<T>>
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.,));
Sourcepub fn into_line_string(self) -> Option<LineString<T>>
👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<LineString>
pub fn into_line_string(self) -> Option<LineString<T>>
If this Geometry is a LineString, then return that LineString, else None.
Sourcepub fn into_line(self) -> Option<Line<T>>
👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Line>
pub fn into_line(self) -> Option<Line<T>>
If this Geometry is a Line, then return that Line, else None.
Sourcepub fn into_polygon(self) -> Option<Polygon<T>>
👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Polygon>
pub fn into_polygon(self) -> Option<Polygon<T>>
If this Geometry is a Polygon, then return that, else None.
Sourcepub fn into_multi_point(self) -> Option<MultiPoint<T>>
👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPoint>
pub fn into_multi_point(self) -> Option<MultiPoint<T>>
If this Geometry is a MultiPoint, then return that, else None.
Sourcepub fn into_multi_line_string(self) -> Option<MultiLineString<T>>
👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiLineString>
pub fn into_multi_line_string(self) -> Option<MultiLineString<T>>
If this Geometry is a MultiLineString, then return that, else None.
Sourcepub fn into_multi_polygon(self) -> Option<MultiPolygon<T>>
👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPolygon>
pub fn into_multi_polygon(self) -> Option<MultiPolygon<T>>
If this Geometry is a MultiPolygon, then return that, else None.
Trait Implementations§
Source§impl<T> AbsDiffEq for Geometry<T>
impl<T> AbsDiffEq for Geometry<T>
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
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§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq
.Source§impl<T: CoordNum> From<LineString<T>> for Geometry<T>
impl<T: CoordNum> From<LineString<T>> for Geometry<T>
Source§fn from(x: LineString<T>) -> Self
fn from(x: LineString<T>) -> Self
Source§impl<T: CoordNum> From<MultiLineString<T>> for Geometry<T>
impl<T: CoordNum> From<MultiLineString<T>> for Geometry<T>
Source§fn from(x: MultiLineString<T>) -> Self
fn from(x: MultiLineString<T>) -> Self
Source§impl<T: CoordNum> From<MultiPoint<T>> for Geometry<T>
impl<T: CoordNum> From<MultiPoint<T>> for Geometry<T>
Source§fn from(x: MultiPoint<T>) -> Self
fn from(x: MultiPoint<T>) -> Self
Source§impl<T: CoordNum> From<MultiPolygon<T>> for Geometry<T>
impl<T: CoordNum> From<MultiPolygon<T>> for Geometry<T>
Source§fn from(x: MultiPolygon<T>) -> Self
fn from(x: MultiPolygon<T>) -> Self
Source§impl<T> RelativeEq for Geometry<T>where
T: CoordNum + RelativeEq<Epsilon = T>,
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
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
fn default_max_relative() -> Self::Epsilon
Source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq
.Source§impl<T: CoordNum> TryFrom<Geometry<T>> for Line<T>
Convert a Geometry enum into its inner type.
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§impl<T: CoordNum> TryFrom<Geometry<T>> for LineString<T>
Convert a Geometry enum into its inner type.
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§impl<T: CoordNum> TryFrom<Geometry<T>> for MultiLineString<T>
Convert a Geometry enum into its inner type.
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§impl<T: CoordNum> TryFrom<Geometry<T>> for MultiPoint<T>
Convert a Geometry enum into its inner type.
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§impl<T: CoordNum> TryFrom<Geometry<T>> for MultiPolygon<T>
Convert a Geometry enum into its inner type.
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§impl<T: CoordNum> TryFrom<Geometry<T>> for Point<T>
Convert a Geometry enum into its inner type.
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§impl<T: CoordNum> TryFrom<Geometry<T>> for Polygon<T>
Convert a Geometry enum into its inner type.
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§impl<T: CoordNum> TryFrom<Geometry<T>> for Rect<T>
Convert a Geometry enum into its inner type.
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§impl<T: CoordNum> TryFrom<Geometry<T>> for Triangle<T>
Convert a Geometry enum into its inner type.
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§impl<T> UlpsEq for Geometry<T>
impl<T> UlpsEq for Geometry<T>
Source§fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool
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/