pub struct Polygon<T> where
T: CoordNum, { /* private fields */ }
Expand description
A bounded two-dimensional area.
A Polygon
’s outer boundary (exterior ring) is represented by a
LineString
. It may contain zero or more holes (interior rings), also
represented by LineString
s.
A Polygon
can be created with the Polygon::new
constructor or the [polygon!
] macro.
Semantics
The boundary of the polygon is the union of the boundaries of the exterior and interiors. The interior is all the points inside the polygon (not on the boundary).
The Polygon
structure guarantees that all exterior and interior rings will
be closed, such that the first and last Coordinate
of each ring has
the same value.
Validity
-
The exterior and interior rings must be valid
LinearRing
s (seeLineString
). -
No two rings in the boundary may cross, and may intersect at a
Point
only as a tangent. In other words, the rings must be distinct, and for every pair of common points in two of the rings, there must be a neighborhood (a topological open set) around one that does not contain the other point. -
The closure of the interior of the
Polygon
must equal thePolygon
itself. For instance, the exterior may not contain a spike. -
The interior of the polygon must be a connected point-set. That is, any two distinct points in the interior must admit a curve between these two that lies in the interior.
Refer to section 6.1.11.1 of the OGC-SFA for a formal
definition of validity. Besides the closed LineString
guarantee, the Polygon
structure does not enforce
validity at this time. For example, it is possible to
construct a Polygon
that has:
- fewer than 3 coordinates per
LineString
ring - interior rings that intersect other interior rings
- interior rings that extend beyond the exterior ring
LineString
closing operation
Some APIs on Polygon
result in a closing operation on a LineString
. The
operation is as follows:
If a LineString
’s first and last Coordinate
have different values, a
new Coordinate
will be appended to the LineString
with a value equal to
the first Coordinate
.
Implementations
sourceimpl<T> Polygon<T> where
T: CoordNum,
impl<T> Polygon<T> where
T: CoordNum,
sourcepub fn new(
exterior: LineString<T>,
interiors: Vec<LineString<T>, Global>
) -> Polygon<T>
pub fn new(
exterior: LineString<T>,
interiors: Vec<LineString<T>, Global>
) -> Polygon<T>
Create a new Polygon
with the provided exterior LineString
ring and
interior LineString
rings.
Upon calling new
, the exterior and interior LineString
rings will
be closed.
Examples
Creating a Polygon
with no interior rings:
use geo_types::{LineString, Polygon};
let polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![],
);
Creating a Polygon
with an interior ring:
use geo_types::{LineString, Polygon};
let polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])],
);
If the first and last Coordinate
s of the exterior or interior
LineString
s no longer match, those LineString
s will be closed:
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(LineString::from(vec![(0., 0.), (1., 1.), (1., 0.)]), vec![]);
assert_eq!(
polygon.exterior(),
&LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.),])
);
sourcepub fn into_inner(self) -> (LineString<T>, Vec<LineString<T>, Global>)
pub fn into_inner(self) -> (LineString<T>, Vec<LineString<T>, Global>)
Consume the Polygon
, returning the exterior LineString
ring and
a vector of the interior LineString
rings.
Examples
use geo_types::{LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])],
);
let (exterior, interiors) = polygon.into_inner();
assert_eq!(
exterior,
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.),])
);
assert_eq!(
interiors,
vec![LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])]
);
sourcepub fn exterior(&self) -> &LineString<T>
pub fn exterior(&self) -> &LineString<T>
Return a reference to the exterior LineString
ring.
Examples
use geo_types::{LineString, Polygon};
let exterior = LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]);
let polygon = Polygon::new(exterior.clone(), vec![]);
assert_eq!(polygon.exterior(), &exterior);
sourcepub fn exterior_mut<F>(&mut self, f: F) where
F: FnOnce(&mut LineString<T>),
pub fn exterior_mut<F>(&mut self, f: F) where
F: FnOnce(&mut LineString<T>),
Execute the provided closure f
, which is provided with a mutable
reference to the exterior LineString
ring.
After the closure executes, the exterior LineString
will be closed.
Examples
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![],
);
polygon.exterior_mut(|exterior| {
exterior.0[1] = coord! { x: 1., y: 2. };
});
assert_eq!(
polygon.exterior(),
&LineString::from(vec![(0., 0.), (1., 2.), (1., 0.), (0., 0.),])
);
If the first and last Coordinate
s of the exterior LineString
no
longer match, the LineString
will be closed:
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![],
);
polygon.exterior_mut(|exterior| {
exterior.0[0] = coord! { x: 0., y: 1. };
});
assert_eq!(
polygon.exterior(),
&LineString::from(vec![(0., 1.), (1., 1.), (1., 0.), (0., 0.), (0., 1.),])
);
sourcepub fn interiors(&self) -> &[LineString<T>]
pub fn interiors(&self) -> &[LineString<T>]
Return a slice of the interior LineString
rings.
Examples
use geo_types::{coord, LineString, Polygon};
let interiors = vec![LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])];
let polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
interiors.clone(),
);
assert_eq!(interiors, polygon.interiors());
sourcepub fn interiors_mut<F>(&mut self, f: F) where
F: FnOnce(&mut [LineString<T>]),
pub fn interiors_mut<F>(&mut self, f: F) where
F: FnOnce(&mut [LineString<T>]),
Execute the provided closure f
, which is provided with a mutable
reference to the interior LineString
rings.
After the closure executes, each of the interior LineString
s will be
closed.
Examples
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])],
);
polygon.interiors_mut(|interiors| {
interiors[0].0[1] = coord! { x: 0.8, y: 0.8 };
});
assert_eq!(
polygon.interiors(),
&[LineString::from(vec![
(0.1, 0.1),
(0.8, 0.8),
(0.9, 0.1),
(0.1, 0.1),
])]
);
If the first and last Coordinate
s of any interior LineString
no
longer match, those LineString
s will be closed:
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])],
);
polygon.interiors_mut(|interiors| {
interiors[0].0[0] = coord! { x: 0.1, y: 0.2 };
});
assert_eq!(
polygon.interiors(),
&[LineString::from(vec![
(0.1, 0.2),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
(0.1, 0.2),
])]
);
sourcepub fn interiors_push(&mut self, new_interior: impl Into<LineString<T>>)
pub fn interiors_push(&mut self, new_interior: impl Into<LineString<T>>)
Add an interior ring to the Polygon
.
The new LineString
interior ring will be closed:
Examples
use geo_types::{coord, LineString, Polygon};
let mut polygon = Polygon::new(
LineString::from(vec![(0., 0.), (1., 1.), (1., 0.), (0., 0.)]),
vec![],
);
assert_eq!(polygon.interiors().len(), 0);
polygon.interiors_push(vec![(0.1, 0.1), (0.9, 0.9), (0.9, 0.1)]);
assert_eq!(
polygon.interiors(),
&[LineString::from(vec![
(0.1, 0.1),
(0.9, 0.9),
(0.9, 0.1),
(0.1, 0.1),
])]
);
Trait Implementations
sourceimpl<T> AbsDiffEq<Polygon<T>> for Polygon<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum,
impl<T> AbsDiffEq<Polygon<T>> for Polygon<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum,
sourcefn abs_diff_eq(
&self,
other: &Polygon<T>,
epsilon: <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon
) -> bool
fn abs_diff_eq(
&self,
other: &Polygon<T>,
epsilon: <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon
) -> bool
Equality assertion with an absolute limit.
Examples
use geo_types::{Polygon, polygon};
let a: Polygon<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7., y: 9.), (x: 0., y: 0.)];
let b: Polygon<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7.01, y: 9.), (x: 0., y: 0.)];
approx::assert_abs_diff_eq!(a, b, epsilon=0.1);
approx::assert_abs_diff_ne!(a, b, epsilon=0.001);
type Epsilon = T
type Epsilon = T
Used for specifying relative comparisons.
sourcefn default_epsilon() -> <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon
fn default_epsilon() -> <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon
The default tolerance to use when testing values that are close together. Read more
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
The inverse of [AbsDiffEq::abs_diff_eq
].
sourceimpl<T> Area<T> for Polygon<T> where
T: CoordFloat,
impl<T> Area<T> for Polygon<T> where
T: CoordFloat,
Note. The implementation handles polygons whose holes do not all have the same orientation. The sign of the output is the same as that of the exterior shell.
fn signed_area(&self) -> T
fn unsigned_area(&self) -> T
sourceimpl<T> BoundingRect<T> for Polygon<T> where
T: CoordNum,
impl<T> BoundingRect<T> for Polygon<T> where
T: CoordNum,
sourceimpl<T> ChaikinSmoothing<T> for Polygon<T> where
T: CoordFloat + FromPrimitive,
impl<T> ChaikinSmoothing<T> for Polygon<T> where
T: CoordFloat + FromPrimitive,
sourcefn chaikin_smoothing(&self, n_iterations: usize) -> Self
fn chaikin_smoothing(&self, n_iterations: usize) -> Self
create a new geometry with the Chaikin smoothing being
applied n_iterations
times. Read more
sourceimpl<T> ChamberlainDuquetteArea<T> for Polygon<T> where
T: Float + CoordNum,
impl<T> ChamberlainDuquetteArea<T> for Polygon<T> where
T: Float + CoordNum,
fn chamberlain_duquette_signed_area(&self) -> T
fn chamberlain_duquette_unsigned_area(&self) -> T
sourceimpl<F: GeoFloat> ClosestPoint<F, Point<F>> for Polygon<F>
impl<F: GeoFloat> ClosestPoint<F, Point<F>> for Polygon<F>
sourcefn closest_point(&self, p: &Point<F>) -> Closest<F>
fn closest_point(&self, p: &Point<F>) -> Closest<F>
Find the closest point between self
and p
.
sourceimpl<T> ConcaveHull for Polygon<T> where
T: GeoFloat + RTreeNum,
impl<T> ConcaveHull for Polygon<T> where
T: GeoFloat + RTreeNum,
sourceimpl<T> Contains<Coordinate<T>> for Polygon<T> where
T: GeoNum,
impl<T> Contains<Coordinate<T>> for Polygon<T> where
T: GeoNum,
fn contains(&self, coord: &Coordinate<T>) -> bool
sourceimpl<T> Contains<LineString<T>> for Polygon<T> where
T: GeoFloat,
impl<T> Contains<LineString<T>> for Polygon<T> where
T: GeoFloat,
fn contains(&self, linestring: &LineString<T>) -> bool
sourceimpl<F> Contains<Polygon<F>> for MultiPolygon<F> where
F: GeoFloat,
impl<F> Contains<Polygon<F>> for MultiPolygon<F> where
F: GeoFloat,
sourceimpl<T> ConvexHull for Polygon<T> where
T: GeoNum,
impl<T> ConvexHull for Polygon<T> where
T: GeoNum,
type Scalar = T
fn convex_hull(&self) -> Polygon<T>
sourceimpl<T> CoordinatePosition for Polygon<T> where
T: GeoNum,
impl<T> CoordinatePosition for Polygon<T> where
T: GeoNum,
type Scalar = T
fn calculate_coordinate_position(
&self,
coord: &Coordinate<T>,
is_inside: &mut bool,
boundary_count: &mut usize
)
fn coordinate_position(&self, coord: &Coordinate<Self::Scalar>) -> CoordPos
sourceimpl<'a, T: CoordNum + 'a> CoordsIter<'a> for Polygon<T>
impl<'a, T: CoordNum + 'a> CoordsIter<'a> for Polygon<T>
sourcefn coords_count(&'a self) -> usize
fn coords_count(&'a self) -> usize
Return the number of coordinates in the Polygon
.
type Iter = Chain<Copied<Iter<'a, Coordinate<T>>>, Flatten<MapCoordsIter<'a, T, Iter<'a, LineString<T>>, LineString<T>>>>
type ExteriorIter = Copied<Iter<'a, Coordinate<T>>>
type Scalar = T
sourcefn coords_iter(&'a self) -> Self::Iter
fn coords_iter(&'a self) -> Self::Iter
Iterate over all exterior and (if any) interior coordinates of a geometry. Read more
sourcefn exterior_coords_iter(&'a self) -> Self::ExteriorIter
fn exterior_coords_iter(&'a self) -> Self::ExteriorIter
Iterate over all exterior coordinates of a geometry. Read more
sourceimpl<T> EuclideanDistance<T, Line<T>> for Polygon<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
impl<T> EuclideanDistance<T, Line<T>> for Polygon<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
sourcefn euclidean_distance(&self, other: &Line<T>) -> T
fn euclidean_distance(&self, other: &Line<T>) -> T
Returns the distance between two geometries Read more
sourceimpl<T> EuclideanDistance<T, LineString<T>> for Polygon<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
impl<T> EuclideanDistance<T, LineString<T>> for Polygon<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
Polygon to LineString distance
sourcefn euclidean_distance(&self, other: &LineString<T>) -> T
fn euclidean_distance(&self, other: &LineString<T>) -> T
Returns the distance between two geometries Read more
sourceimpl<T> EuclideanDistance<T, Point<T>> for Polygon<T> where
T: GeoFloat,
impl<T> EuclideanDistance<T, Point<T>> for Polygon<T> where
T: GeoFloat,
sourcefn euclidean_distance(&self, point: &Point<T>) -> T
fn euclidean_distance(&self, point: &Point<T>) -> T
Minimum distance from a Polygon to a Point
sourceimpl<T> EuclideanDistance<T, Polygon<T>> for Point<T> where
T: GeoFloat,
impl<T> EuclideanDistance<T, Polygon<T>> for Point<T> where
T: GeoFloat,
sourcefn euclidean_distance(&self, polygon: &Polygon<T>) -> T
fn euclidean_distance(&self, polygon: &Polygon<T>) -> T
Minimum distance from a Point to a Polygon
sourceimpl<T> EuclideanDistance<T, Polygon<T>> for Line<T> where
T: GeoFloat + Signed + RTreeNum + FloatConst,
impl<T> EuclideanDistance<T, Polygon<T>> for Line<T> where
T: GeoFloat + Signed + RTreeNum + FloatConst,
sourcefn euclidean_distance(&self, other: &Polygon<T>) -> T
fn euclidean_distance(&self, other: &Polygon<T>) -> T
Returns the distance between two geometries Read more
sourceimpl<T> EuclideanDistance<T, Polygon<T>> for LineString<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
impl<T> EuclideanDistance<T, Polygon<T>> for LineString<T> where
T: GeoFloat + FloatConst + Signed + RTreeNum,
LineString to Polygon
sourcefn euclidean_distance(&self, other: &Polygon<T>) -> T
fn euclidean_distance(&self, other: &Polygon<T>) -> T
Returns the distance between two geometries Read more
sourceimpl<T> EuclideanDistance<T, Polygon<T>> for Polygon<T> where
T: GeoFloat + FloatConst + RTreeNum,
impl<T> EuclideanDistance<T, Polygon<T>> for Polygon<T> where
T: GeoFloat + FloatConst + RTreeNum,
sourcefn euclidean_distance(&self, poly2: &Polygon<T>) -> T
fn euclidean_distance(&self, poly2: &Polygon<T>) -> T
This implementation has a “fast path” in cases where both input polygons are convex: it switches to an implementation of the “rotating calipers” method described in Pirzadeh (1999), pp24—30, which is approximately an order of magnitude faster than the standard method.
sourceimpl<C: CoordNum> HasDimensions for Polygon<C>
impl<C: CoordNum> HasDimensions for Polygon<C>
sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Some geometries, like a MultiPoint
, can have zero coordinates - we call these empty
. Read more
sourcefn dimensions(&self) -> Dimensions
fn dimensions(&self) -> Dimensions
The dimensions of some geometries are fixed, e.g. a Point always has 0 dimensions. However
for others, the dimensionality depends on the specific geometry instance - for example
typical Rect
s are 2-dimensional, but it’s possible to create degenerate Rect
s which
have either 1 or 0 dimensions. Read more
sourcefn boundary_dimensions(&self) -> Dimensions
fn boundary_dimensions(&self) -> Dimensions
The dimensions of the Geometry
’s boundary, as used by OGC-SFA. Read more
sourceimpl<T> Intersects<Coordinate<T>> for Polygon<T> where
T: GeoNum,
impl<T> Intersects<Coordinate<T>> for Polygon<T> where
T: GeoNum,
fn intersects(&self, p: &Coordinate<T>) -> bool
sourceimpl<T> Intersects<Geometry<T>> for Polygon<T> where
Geometry<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<Geometry<T>> for Polygon<T> where
Geometry<T>: Intersects<Polygon<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Geometry<T>) -> bool
sourceimpl<T> Intersects<GeometryCollection<T>> for Polygon<T> where
GeometryCollection<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<GeometryCollection<T>> for Polygon<T> where
GeometryCollection<T>: Intersects<Polygon<T>>,
T: CoordNum,
fn intersects(&self, rhs: &GeometryCollection<T>) -> bool
sourceimpl<T> Intersects<Line<T>> for Polygon<T> where
T: GeoNum,
impl<T> Intersects<Line<T>> for Polygon<T> where
T: GeoNum,
fn intersects(&self, line: &Line<T>) -> bool
sourceimpl<T> Intersects<LineString<T>> for Polygon<T> where
LineString<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<LineString<T>> for Polygon<T> where
LineString<T>: Intersects<Polygon<T>>,
T: CoordNum,
fn intersects(&self, rhs: &LineString<T>) -> bool
sourceimpl<T> Intersects<MultiLineString<T>> for Polygon<T> where
MultiLineString<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<MultiLineString<T>> for Polygon<T> where
MultiLineString<T>: Intersects<Polygon<T>>,
T: CoordNum,
fn intersects(&self, rhs: &MultiLineString<T>) -> bool
sourceimpl<T> Intersects<MultiPoint<T>> for Polygon<T> where
MultiPoint<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<MultiPoint<T>> for Polygon<T> where
MultiPoint<T>: Intersects<Polygon<T>>,
T: CoordNum,
fn intersects(&self, rhs: &MultiPoint<T>) -> bool
sourceimpl<T> Intersects<MultiPolygon<T>> for Polygon<T> where
MultiPolygon<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<MultiPolygon<T>> for Polygon<T> where
MultiPolygon<T>: Intersects<Polygon<T>>,
T: CoordNum,
fn intersects(&self, rhs: &MultiPolygon<T>) -> bool
sourceimpl<T> Intersects<Point<T>> for Polygon<T> where
Point<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<Point<T>> for Polygon<T> where
Point<T>: Intersects<Polygon<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Point<T>) -> bool
sourceimpl<T> Intersects<Polygon<T>> for Coordinate<T> where
Polygon<T>: Intersects<Coordinate<T>>,
T: CoordNum,
impl<T> Intersects<Polygon<T>> for Coordinate<T> where
Polygon<T>: Intersects<Coordinate<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Polygon<T>) -> bool
sourceimpl<T> Intersects<Polygon<T>> for Line<T> where
Polygon<T>: Intersects<Line<T>>,
T: CoordNum,
impl<T> Intersects<Polygon<T>> for Line<T> where
Polygon<T>: Intersects<Line<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Polygon<T>) -> bool
sourceimpl<T> Intersects<Polygon<T>> for Rect<T> where
Polygon<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<Polygon<T>> for Rect<T> where
Polygon<T>: Intersects<Rect<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Polygon<T>) -> bool
sourceimpl<T> Intersects<Polygon<T>> for Polygon<T> where
T: GeoNum,
impl<T> Intersects<Polygon<T>> for Polygon<T> where
T: GeoNum,
fn intersects(&self, polygon: &Polygon<T>) -> bool
sourceimpl<T> Intersects<Rect<T>> for Polygon<T> where
T: GeoNum,
impl<T> Intersects<Rect<T>> for Polygon<T> where
T: GeoNum,
fn intersects(&self, rect: &Rect<T>) -> bool
sourceimpl<T> Intersects<Triangle<T>> for Polygon<T> where
Triangle<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<Triangle<T>> for Polygon<T> where
Triangle<T>: Intersects<Polygon<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Triangle<T>) -> bool
sourceimpl<'a, T: CoordNum + 'a> LinesIter<'a> for Polygon<T>
impl<'a, T: CoordNum + 'a> LinesIter<'a> for Polygon<T>
type Scalar = T
type Iter = Chain<LineStringIter<'a, <Polygon<T> as LinesIter<'a>>::Scalar>, Flatten<MapLinesIter<'a, Iter<'a, LineString<<Polygon<T> as LinesIter<'a>>::Scalar>>, LineString<<Polygon<T> as LinesIter<'a>>::Scalar>>>>
sourcefn lines_iter(&'a self) -> Self::Iter
fn lines_iter(&'a self) -> Self::Iter
Iterate over all exterior and (if any) interior lines of a geometry. Read more
sourceimpl<T: CoordNum> MapCoordsInplace<T> for Polygon<T>
impl<T: CoordNum> MapCoordsInplace<T> for Polygon<T>
sourceimpl<F: GeoFloat> Relate<F, GeometryCollection<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, GeometryCollection<F>> for Polygon<F>
fn relate(&self, other: &GeometryCollection<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Line<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, Line<F>> for Polygon<F>
fn relate(&self, other: &Line<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, LineString<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, LineString<F>> for Polygon<F>
fn relate(&self, other: &LineString<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, MultiLineString<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, MultiLineString<F>> for Polygon<F>
fn relate(&self, other: &MultiLineString<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, MultiPoint<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, MultiPoint<F>> for Polygon<F>
fn relate(&self, other: &MultiPoint<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, MultiPolygon<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, MultiPolygon<F>> for Polygon<F>
fn relate(&self, other: &MultiPolygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Point<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, Point<F>> for Polygon<F>
fn relate(&self, other: &Point<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for Point<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for Point<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for Line<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for Line<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for LineString<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for LineString<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for Polygon<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for MultiPoint<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for MultiPoint<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for MultiLineString<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for MultiLineString<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for MultiPolygon<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for MultiPolygon<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for Rect<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for Rect<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for Triangle<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for Triangle<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Polygon<F>> for GeometryCollection<F>
impl<F: GeoFloat> Relate<F, Polygon<F>> for GeometryCollection<F>
fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Rect<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, Rect<F>> for Polygon<F>
fn relate(&self, other: &Rect<F>) -> IntersectionMatrix
sourceimpl<F: GeoFloat> Relate<F, Triangle<F>> for Polygon<F>
impl<F: GeoFloat> Relate<F, Triangle<F>> for Polygon<F>
fn relate(&self, other: &Triangle<F>) -> IntersectionMatrix
sourceimpl<T> RelativeEq<Polygon<T>> for Polygon<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
impl<T> RelativeEq<Polygon<T>> for Polygon<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
sourcefn relative_eq(
&self,
other: &Polygon<T>,
epsilon: <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon,
max_relative: <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon
) -> bool
fn relative_eq(
&self,
other: &Polygon<T>,
epsilon: <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon,
max_relative: <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon
) -> bool
Equality assertion within a relative limit.
Examples
use geo_types::{Polygon, polygon};
let a: Polygon<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7., y: 9.), (x: 0., y: 0.)];
let b: Polygon<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7.01, y: 9.), (x: 0., y: 0.)];
approx::assert_relative_eq!(a, b, max_relative=0.1);
approx::assert_relative_ne!(a, b, max_relative=0.001);
sourcefn default_max_relative() -> <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon
fn default_max_relative() -> <Polygon<T> as AbsDiffEq<Polygon<T>>>::Epsilon
The default relative tolerance for testing values that are far-apart. Read more
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
The inverse of [RelativeEq::relative_eq
].
sourceimpl<T> Rotate<T> for Polygon<T> where
T: GeoFloat,
impl<T> Rotate<T> for Polygon<T> where
T: GeoFloat,
sourcefn rotate_around_centroid(&self, angle: T) -> Self
fn rotate_around_centroid(&self, angle: T) -> Self
Rotate the Polygon about its centroid by the given number of degrees
sourcefn rotate_around_center(&self, angle: T) -> Self
fn rotate_around_center(&self, angle: T) -> Self
Rotate the Polygon about the center of its bounding rectangle by the given number of degrees
sourcefn rotate(&self, angle: T) -> Self
👎 Deprecated: Equivalent to rotate_around_centroid
except for Polygon<T>
,
where it is equivalent to rotating around the polygon’s outer ring.
Call that instead, or rotate_around_center
if you’d like to rotate
around the geometry’s bounding box center.
fn rotate(&self, angle: T) -> Self
Equivalent to rotate_around_centroid
except for Polygon<T>
,
where it is equivalent to rotating around the polygon’s outer ring.
Call that instead, or rotate_around_center
if you’d like to rotate
around the geometry’s bounding box center.
Rotate the Polygon about its centroid by the given number of degrees
sourceimpl<T> Simplify<T, T> for Polygon<T> where
T: GeoFloat,
impl<T> Simplify<T, T> for Polygon<T> where
T: GeoFloat,
sourcefn simplify(&self, epsilon: &T) -> Self
fn simplify(&self, epsilon: &T) -> Self
Returns the simplified representation of a geometry, using the Ramer–Douglas–Peucker algorithm Read more
sourceimpl<T> SimplifyVW<T, T> for Polygon<T> where
T: CoordFloat,
impl<T> SimplifyVW<T, T> for Polygon<T> where
T: CoordFloat,
sourcefn simplifyvw(&self, epsilon: &T) -> Polygon<T>
fn simplifyvw(&self, epsilon: &T) -> Polygon<T>
Returns the simplified representation of a geometry, using the Visvalingam-Whyatt algorithm Read more
sourceimpl<T> SimplifyVWPreserve<T, T> for Polygon<T> where
T: CoordFloat + RTreeNum,
impl<T> SimplifyVWPreserve<T, T> for Polygon<T> where
T: CoordFloat + RTreeNum,
sourcefn simplifyvw_preserve(&self, epsilon: &T) -> Polygon<T>
fn simplifyvw_preserve(&self, epsilon: &T) -> Polygon<T>
Returns the simplified representation of a geometry, using a topology-preserving variant of the Visvalingam-Whyatt algorithm. Read more
sourceimpl<T> TryFrom<Geometry<T>> for Polygon<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for Polygon<T> where
T: CoordNum,
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.
sourceimpl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Polygon<T>
impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Polygon<T>
sourceimpl<T: CoordNum, E> TryMapCoordsInplace<T, E> for Polygon<T>
impl<T: CoordNum, E> TryMapCoordsInplace<T, E> for Polygon<T>
impl<T> Eq for Polygon<T> where
T: Eq + CoordNum,
impl<T> StructuralEq for Polygon<T> where
T: CoordNum,
impl<T> StructuralPartialEq for Polygon<T> where
T: CoordNum,
Auto Trait Implementations
impl<T> RefUnwindSafe for Polygon<T> where
T: RefUnwindSafe,
impl<T> Send for Polygon<T> where
T: Send,
impl<T> Sync for Polygon<T> where
T: Sync,
impl<T> Unpin for Polygon<T> where
T: Unpin,
impl<T> UnwindSafe for Polygon<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<'a, T, G> Extremes<'a, T> for G where
G: CoordsIter<'a, Scalar = T>,
T: CoordNum,
impl<'a, T, G> Extremes<'a, T> for G where
G: CoordsIter<'a, Scalar = T>,
T: CoordNum,
sourceimpl<T, G> RotatePoint<T> for G where
T: CoordFloat,
G: MapCoords<T, T, Output = G>,
impl<T, G> RotatePoint<T> for G where
T: CoordFloat,
G: MapCoords<T, T, Output = G>,
sourcefn rotate_around_point(&self, angle: T, point: Point<T>) -> G
fn rotate_around_point(&self, angle: T, point: Point<T>) -> G
Rotate a Geometry around an arbitrary point by an angle, given in degrees Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T, G> Translate<T> for G where
T: CoordNum,
G: MapCoords<T, T, Output = G> + MapCoordsInplace<T>,
impl<T, G> Translate<T> for G where
T: CoordNum,
G: MapCoords<T, T, Output = G> + MapCoordsInplace<T>,
sourcefn translate(&self, xoff: T, yoff: T) -> G
fn translate(&self, xoff: T, yoff: T) -> G
Translate a Geometry along its axes by the given offsets Read more
sourcefn translate_inplace(&mut self, xoff: T, yoff: T)
fn translate_inplace(&mut self, xoff: T, yoff: T)
Translate a Geometry along its axes, but in place.