Struct geo::geometry::Polygon

source ·
pub struct Polygon<T = f64>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 LineStrings.

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 Coord of each ring has the same value.

Validity

  • The exterior and interior rings must be valid LinearRings (see LineString).

  • 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 the Polygon 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 Coord have different values, a new Coord will be appended to the LineString with a value equal to the first Coord.

Implementations§

source§

impl<T> Polygon<T>where T: CoordNum,

source

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 Coords of the exterior or interior LineStrings no longer match, those LineStrings 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.),])
);
source

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),
    ])]
);
source

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);
source

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 Coords 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.),])
);
source

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());
source

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 LineStrings 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 Coords of any interior LineString no longer match, those LineStrings 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),
    ])]
);
source

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),
    ])]
);
source§

impl<T> Polygon<T>where T: CoordFloat + Signed,

source

pub fn is_convex(&self) -> bool

👎Deprecated since 0.6.1: Please use geo::is_convex on poly.exterior() instead

Determine whether a Polygon is convex

Trait Implementations§

source§

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

source§

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

Used for specifying relative comparisons.
source§

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

The inverse of [AbsDiffEq::abs_diff_eq].
source§

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.

source§

fn signed_area(&self) -> T

source§

fn unsigned_area(&self) -> T

source§

impl<T: GeoFloat> BooleanOps for Polygon<T>

§

type Scalar = T

source§

fn boolean_op(&self, other: &Self, op: OpType) -> MultiPolygon<Self::Scalar>

source§

fn clip( &self, ls: &MultiLineString<Self::Scalar>, invert: bool ) -> MultiLineString<Self::Scalar>

Clip a 1-D geometry with self. Read more
source§

fn intersection(&self, other: &Self) -> MultiPolygon<Self::Scalar>

source§

fn union(&self, other: &Self) -> MultiPolygon<Self::Scalar>

source§

fn xor(&self, other: &Self) -> MultiPolygon<Self::Scalar>

source§

fn difference(&self, other: &Self) -> MultiPolygon<Self::Scalar>

source§

impl<T> BoundingRect<T> for Polygon<T>where T: CoordNum,

source§

fn bounding_rect(&self) -> Self::Output

Return the BoundingRect for a Polygon

§

type Output = Option<Rect<T>>

source§

impl<T> Centroid for Polygon<T>where T: GeoFloat,

source§

fn centroid(&self) -> Self::Output

The Centroid of a Polygon is the mean of its points

Examples
use geo::Centroid;
use geo::{polygon, point};

let polygon = polygon![
    (x: 0.0f32, y: 0.0),
    (x: 2.0, y: 0.0),
    (x: 2.0, y: 1.0),
    (x: 0.0, y: 1.0),
];

assert_eq!(
    Some(point!(x: 1.0, y: 0.5)),
    polygon.centroid(),
);
§

type Output = Option<Point<T>>

source§

impl<T> ChaikinSmoothing<T> for Polygon<T>where T: CoordFloat + FromPrimitive,

source§

fn chaikin_smoothing(&self, n_iterations: usize) -> Self

create a new geometry with the Chaikin smoothing being applied n_iterations times.
source§

impl<T> ChamberlainDuquetteArea<T> for Polygon<T>where T: CoordFloat,

source§

impl<T> Clone for Polygon<T>where T: Clone + CoordNum,

source§

fn clone(&self) -> Polygon<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<F: GeoFloat> ClosestPoint<F, Point<F>> for Polygon<F>

source§

fn closest_point(&self, p: &Point<F>) -> Closest<F>

Find the closest point between self and p.
source§

impl<T> ConcaveHull for Polygon<T>where T: GeoFloat + RTreeNum,

§

type Scalar = T

source§

fn concave_hull(&self, concavity: Self::Scalar) -> Polygon<Self::Scalar>

source§

impl<T> Contains<Coord<T>> for Polygon<T>where T: GeoNum,

source§

fn contains(&self, coord: &Coord<T>) -> bool

source§

impl<T> Contains<Geometry<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, geometry: &Geometry<T>) -> bool

source§

impl<T> Contains<GeometryCollection<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, target: &GeometryCollection<T>) -> bool

source§

impl<T> Contains<Line<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, target: &Line<T>) -> bool

source§

impl<T> Contains<LineString<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, target: &LineString<T>) -> bool

source§

impl<T> Contains<MultiLineString<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, target: &MultiLineString<T>) -> bool

source§

impl<T> Contains<MultiPoint<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, target: &MultiPoint<T>) -> bool

source§

impl<T> Contains<MultiPolygon<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, target: &MultiPolygon<T>) -> bool

source§

impl<T> Contains<Point<T>> for Polygon<T>where T: GeoNum,

source§

fn contains(&self, p: &Point<T>) -> bool

source§

impl<F> Contains<Polygon<F>> for MultiPolygon<F>where F: GeoFloat,

source§

fn contains(&self, rhs: &Polygon<F>) -> bool

source§

impl<T> Contains<Polygon<T>> for Geometry<T>where T: GeoFloat,

source§

fn contains(&self, polygon: &Polygon<T>) -> bool

source§

impl<T> Contains<Polygon<T>> for GeometryCollection<T>where T: GeoFloat,

source§

fn contains(&self, target: &Polygon<T>) -> bool

source§

impl<T> Contains<Polygon<T>> for Line<T>where T: GeoFloat,

source§

fn contains(&self, target: &Polygon<T>) -> bool

source§

impl<T> Contains<Polygon<T>> for LineString<T>where T: GeoFloat,

source§

fn contains(&self, target: &Polygon<T>) -> bool

source§

impl<T> Contains<Polygon<T>> for MultiLineString<T>where T: GeoFloat,

source§

fn contains(&self, target: &Polygon<T>) -> bool

source§

impl<T> Contains<Polygon<T>> for MultiPoint<T>where T: GeoFloat,

source§

fn contains(&self, target: &Polygon<T>) -> bool

source§

impl<T> Contains<Polygon<T>> for Point<T>where T: CoordNum,

source§

fn contains(&self, polygon: &Polygon<T>) -> bool

source§

impl<T> Contains<Polygon<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, target: &Polygon<T>) -> bool

source§

impl<T> Contains<Polygon<T>> for Rect<T>where T: GeoFloat,

source§

fn contains(&self, target: &Polygon<T>) -> bool

source§

impl<T> Contains<Polygon<T>> for Triangle<T>where T: GeoFloat,

source§

fn contains(&self, target: &Polygon<T>) -> bool

source§

impl<T> Contains<Rect<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, target: &Rect<T>) -> bool

source§

impl<T> Contains<Triangle<T>> for Polygon<T>where T: GeoFloat,

source§

fn contains(&self, target: &Triangle<T>) -> bool

source§

impl<T> CoordinatePosition for Polygon<T>where T: GeoNum,

§

type Scalar = T

source§

fn calculate_coordinate_position( &self, coord: &Coord<T>, is_inside: &mut bool, boundary_count: &mut usize )

source§

fn coordinate_position(&self, coord: &Coord<Self::Scalar>) -> CoordPos

source§

impl<'a, T: CoordNum + 'a> CoordsIter<'a> for Polygon<T>

source§

fn coords_count(&'a self) -> usize

Return the number of coordinates in the Polygon.

§

type Iter = Chain<Copied<Iter<'a, Coord<T>>>, Flatten<MapCoordsIter<'a, T, Iter<'a, LineString<T>>, LineString<T>>>>

§

type ExteriorIter = Copied<Iter<'a, Coord<T>>>

§

type Scalar = T

source§

fn coords_iter(&'a self) -> Self::Iter

Iterate over all exterior and (if any) interior coordinates of a geometry. Read more
source§

fn exterior_coords_iter(&'a self) -> Self::ExteriorIter

Iterate over all exterior coordinates of a geometry. Read more
source§

impl<T> Debug for Polygon<T>where T: Debug + CoordNum,

source§

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

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

impl<T> Densify<T> for Polygon<T>where T: CoordFloat, Line<T>: EuclideanLength<T>, LineString<T>: EuclideanLength<T>,

§

type Output = Polygon<T>

source§

fn densify(&self, max_distance: T) -> Self::Output

source§

impl<'de, T> Deserialize<'de> for Polygon<T>where T: CoordNum + Deserialize<'de>,

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<Polygon<T>, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> EuclideanDistance<T, Line<T>> for Polygon<T>where T: GeoFloat + FloatConst + Signed + RTreeNum,

source§

fn euclidean_distance(&self, other: &Line<T>) -> T

Returns the distance between two geometries Read more
source§

impl<T> EuclideanDistance<T, LineString<T>> for Polygon<T>where T: GeoFloat + FloatConst + Signed + RTreeNum,

Polygon to LineString distance

source§

fn euclidean_distance(&self, other: &LineString<T>) -> T

Returns the distance between two geometries Read more
source§

impl<T> EuclideanDistance<T, Point<T>> for Polygon<T>where T: GeoFloat,

source§

fn euclidean_distance(&self, point: &Point<T>) -> T

Minimum distance from a Polygon to a Point

source§

impl<T> EuclideanDistance<T, Polygon<T>> for Line<T>where T: GeoFloat + Signed + RTreeNum + FloatConst,

source§

fn euclidean_distance(&self, other: &Polygon<T>) -> T

Returns the distance between two geometries Read more
source§

impl<T> EuclideanDistance<T, Polygon<T>> for LineString<T>where T: GeoFloat + FloatConst + Signed + RTreeNum,

LineString to Polygon

source§

fn euclidean_distance(&self, other: &Polygon<T>) -> T

Returns the distance between two geometries Read more
source§

impl<T> EuclideanDistance<T, Polygon<T>> for Point<T>where T: GeoFloat,

source§

fn euclidean_distance(&self, polygon: &Polygon<T>) -> T

Minimum distance from a Point to a Polygon

source§

impl<T> EuclideanDistance<T, Polygon<T>> for Polygon<T>where T: GeoFloat + FloatConst + RTreeNum,

source§

fn euclidean_distance(&self, poly2: &Polygon<T>) -> T

Returns the distance between two geometries Read more
source§

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

source§

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

Converts to this type from the input type.
source§

impl<T> From<Rect<T>> for Polygon<T>where T: CoordNum,

source§

fn from(r: Rect<T>) -> Polygon<T>

Converts to this type from the input type.
source§

impl<T> From<Triangle<T>> for Polygon<T>where T: CoordNum,

source§

fn from(t: Triangle<T>) -> Polygon<T>

Converts to this type from the input type.
source§

impl GeodesicArea<f64> for Polygon

source§

fn geodesic_perimeter(&self) -> f64

Determine the perimeter of a geometry on an ellipsoidal model of the earth. Read more
source§

fn geodesic_area_signed(&self) -> f64

Determine the area of a geometry on an ellipsoidal model of the earth. Read more
source§

fn geodesic_area_unsigned(&self) -> f64

Determine the area of a geometry on an ellipsoidal model of the earth. Supports very large geometries that cover a significant portion of the earth. Read more
source§

fn geodesic_perimeter_area_signed(&self) -> (f64, f64)

Determine the perimeter and area of a geometry on an ellipsoidal model of the earth, all in one operation. Read more
source§

fn geodesic_perimeter_area_unsigned(&self) -> (f64, f64)

Determine the perimeter and area of a geometry on an ellipsoidal model of the earth, all in one operation. Supports very large geometries that cover a significant portion of the earth. Read more
source§

impl<C: CoordNum> HasDimensions for Polygon<C>

source§

fn is_empty(&self) -> bool

Some geometries, like a MultiPoint, can have zero coordinates - we call these empty. Read more
source§

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 Rects are 2-dimensional, but it’s possible to create degenerate Rects which have either 1 or 0 dimensions. Read more
source§

fn boundary_dimensions(&self) -> Dimensions

The dimensions of the Geometry’s boundary, as used by OGC-SFA. Read more
source§

impl<T> Hash for Polygon<T>where T: Hash + CoordNum,

source§

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

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> InteriorPoint for Polygon<T>where T: GeoFloat,

§

type Output = Option<Point<T>>

source§

fn interior_point(&self) -> Self::Output

Calculates a representative point inside the Geometry Read more
source§

impl<T> Intersects<Coord<T>> for Polygon<T>where T: GeoNum,

source§

fn intersects(&self, p: &Coord<T>) -> bool

source§

impl<T> Intersects<Geometry<T>> for Polygon<T>where Geometry<T>: Intersects<Polygon<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &Geometry<T>) -> bool

source§

impl<T> Intersects<GeometryCollection<T>> for Polygon<T>where GeometryCollection<T>: Intersects<Polygon<T>>, T: CoordNum,

source§

impl<T> Intersects<Line<T>> for Polygon<T>where T: GeoNum,

source§

fn intersects(&self, line: &Line<T>) -> bool

source§

impl<T> Intersects<LineString<T>> for Polygon<T>where LineString<T>: Intersects<Polygon<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &LineString<T>) -> bool

source§

impl<T> Intersects<MultiLineString<T>> for Polygon<T>where MultiLineString<T>: Intersects<Polygon<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &MultiLineString<T>) -> bool

source§

impl<T> Intersects<MultiPoint<T>> for Polygon<T>where MultiPoint<T>: Intersects<Polygon<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &MultiPoint<T>) -> bool

source§

impl<T> Intersects<MultiPolygon<T>> for Polygon<T>where MultiPolygon<T>: Intersects<Polygon<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &MultiPolygon<T>) -> bool

source§

impl<T> Intersects<Point<T>> for Polygon<T>where Point<T>: Intersects<Polygon<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &Point<T>) -> bool

source§

impl<T> Intersects<Polygon<T>> for Coord<T>where Polygon<T>: Intersects<Coord<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &Polygon<T>) -> bool

source§

impl<T> Intersects<Polygon<T>> for Line<T>where Polygon<T>: Intersects<Line<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &Polygon<T>) -> bool

source§

impl<T> Intersects<Polygon<T>> for Polygon<T>where T: GeoNum,

source§

fn intersects(&self, polygon: &Polygon<T>) -> bool

source§

impl<T> Intersects<Polygon<T>> for Rect<T>where Polygon<T>: Intersects<Rect<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &Polygon<T>) -> bool

source§

impl<T> Intersects<Rect<T>> for Polygon<T>where T: GeoNum,

source§

fn intersects(&self, rect: &Rect<T>) -> bool

source§

impl<T> Intersects<Triangle<T>> for Polygon<T>where Triangle<T>: Intersects<Polygon<T>>, T: CoordNum,

source§

fn intersects(&self, rhs: &Triangle<T>) -> bool

source§

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>>>>

source§

fn lines_iter(&'a self) -> Self::Iter

Iterate over all exterior and (if any) interior lines of a geometry. Read more
source§

impl<T: CoordNum, NT: CoordNum> MapCoords<T, NT> for Polygon<T>

§

type Output = Polygon<NT>

source§

fn map_coords( &self, func: impl Fn(Coord<T>) -> Coord<NT> + Copy ) -> Self::Output

Apply a function to all the coordinates in a geometric object, returning a new object. Read more
source§

fn try_map_coords<E>( &self, func: impl Fn(Coord<T>) -> Result<Coord<NT>, E> + Copy ) -> Result<Self::Output, E>

Map a fallible function over all the coordinates in a geometry, returning a Result Read more
source§

impl<T: CoordNum> MapCoordsInPlace<T> for Polygon<T>

source§

fn map_coords_in_place(&mut self, func: impl Fn(Coord<T>) -> Coord<T> + Copy)

Apply a function to all the coordinates in a geometric object, in place Read more
source§

fn try_map_coords_in_place<E>( &mut self, func: impl Fn(Coord<T>) -> Result<Coord<T>, E> ) -> Result<(), E>

Map a fallible function over all the coordinates in a geometry, in place, returning a Result. Read more
source§

impl<T: CoordNum> MapCoordsInplace<T> for Polygon<T>

source§

fn map_coords_inplace(&mut self, func: impl Fn((T, T)) -> (T, T) + Copy)where T: CoordNum,

👎Deprecated since 0.21.0: use MapCoordsInPlace::map_coords_in_place instead which takes a Coord instead of an (x,y) tuple

Apply a function to all the coordinates in a geometric object, in place

Examples
#[allow(deprecated)]
use geo::MapCoordsInplace;
use geo::Point;
use approx::assert_relative_eq;

let mut p = Point::new(10., 20.);
#[allow(deprecated)]
p.map_coords_inplace(|(x, y)| (x + 1000., y * 2.));

assert_relative_eq!(p, Point::new(1010., 40.), epsilon = 1e-6);
source§

impl<T> Orient for Polygon<T>where T: GeoNum,

source§

fn orient(&self, direction: Direction) -> Polygon<T>

Orients a Polygon’s exterior and interior rings according to convention Read more
source§

impl<T> PartialEq<Polygon<T>> for Polygon<T>where T: PartialEq<T> + CoordNum,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> RTreeObject for Polygon<T>where T: Float + RTreeNum,

§

type Envelope = AABB<Point<T>>

The object’s envelope type. Usually, AABB will be the right choice. This type also defines the object’s dimensionality.
source§

fn envelope(&self) -> <Polygon<T> as RTreeObject>::Envelope

Returns the object’s envelope. Read more
source§

impl<F: GeoFloat> Relate<F, GeometryCollection<F>> for Polygon<F>

source§

impl<F: GeoFloat> Relate<F, Line<F>> for Polygon<F>

source§

fn relate(&self, other: &Line<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, LineString<F>> for Polygon<F>

source§

impl<F: GeoFloat> Relate<F, MultiLineString<F>> for Polygon<F>

source§

impl<F: GeoFloat> Relate<F, MultiPoint<F>> for Polygon<F>

source§

impl<F: GeoFloat> Relate<F, MultiPolygon<F>> for Polygon<F>

source§

impl<F: GeoFloat> Relate<F, Point<F>> for Polygon<F>

source§

fn relate(&self, other: &Point<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for GeometryCollection<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for Line<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for LineString<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for MultiLineString<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for MultiPoint<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for MultiPolygon<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for Point<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for Polygon<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for Rect<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Polygon<F>> for Triangle<F>

source§

fn relate(&self, other: &Polygon<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Rect<F>> for Polygon<F>

source§

fn relate(&self, other: &Rect<F>) -> IntersectionMatrix

source§

impl<F: GeoFloat> Relate<F, Triangle<F>> for Polygon<F>

source§

fn relate(&self, other: &Triangle<F>) -> IntersectionMatrix

source§

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

source§

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);
source§

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

The inverse of [RelativeEq::relative_eq].
source§

impl<T> RemoveRepeatedPoints<T> for Polygon<T>where T: CoordNum + FromPrimitive,

source§

fn remove_repeated_points(&self) -> Self

Create a Polygon with consecutive repeated points removed.

source§

fn remove_repeated_points_mut(&mut self)

Remove consecutive repeated points from a Polygon inplace.

source§

impl<T> Serialize for Polygon<T>where T: CoordNum + Serialize,

source§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T> Simplify<T, T> for Polygon<T>where T: GeoFloat,

source§

fn simplify(&self, epsilon: &T) -> Self

Returns the simplified representation of a geometry, using the Ramer–Douglas–Peucker algorithm Read more
source§

impl<T> SimplifyVw<T, T> for Polygon<T>where T: CoordFloat,

source§

fn simplify_vw(&self, epsilon: &T) -> Polygon<T>

Returns the simplified representation of a geometry, using the Visvalingam-Whyatt algorithm Read more
source§

impl<T> SimplifyVwPreserve<T, T> for Polygon<T>where T: CoordFloat + RTreeNum + HasKernel,

source§

fn simplify_vw_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
source§

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.

§

type Error = Error

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

fn try_from( geom: Geometry<T> ) -> Result<Polygon<T>, <Polygon<T> as TryFrom<Geometry<T>>>::Error>

Performs the conversion.
source§

impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Polygon<T>

§

type Output = Polygon<NT>

👎Deprecated since 0.21.0: use MapCoords::try_map_coords which takes a Coord instead of an (x,y) tuple
source§

fn try_map_coords( &self, func: impl Fn((T, T)) -> Result<(NT, NT), E> + Copy ) -> Result<Self::Output, E>

👎Deprecated since 0.21.0: use MapCoords::try_map_coords which takes a Coord instead of an (x,y) tuple
Map a fallible function over all the coordinates in a geometry, returning a Result Read more
source§

impl<T: CoordNum, E> TryMapCoordsInplace<T, E> for Polygon<T>

source§

fn try_map_coords_inplace( &mut self, func: impl Fn((T, T)) -> Result<(T, T), E> ) -> Result<(), E>

👎Deprecated since 0.21.0: use MapCoordsInPlace::try_map_coords_in_place which takes a Coord instead of an (x,y) tuple
Map a fallible function over all the coordinates in a geometry, in place, returning a Result. Read more
source§

impl<T> Eq for Polygon<T>where T: Eq + CoordNum,

source§

impl<T> StructuralEq for Polygon<T>where T: CoordNum,

source§

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§

source§

impl<T, M> AffineOps<T> for Mwhere T: CoordNum, M: MapCoordsInPlace<T> + MapCoords<T, T, Output = M>,

source§

fn affine_transform(&self, transform: &AffineTransform<T>) -> M

Apply transform immutably, outputting a new geometry.
source§

fn affine_transform_mut(&mut self, transform: &AffineTransform<T>)

Apply transform to mutate self.
source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<G, T, U> Convert<T, U> for Gwhere T: CoordNum, U: CoordNum + From<T>, G: MapCoords<T, U>,

§

type Output = <G as MapCoords<T, U>>::Output

source§

fn convert(&self) -> <G as Convert<T, U>>::Output

source§

impl<'a, T, G> ConvexHull<'a, T> for Gwhere T: GeoNum, G: CoordsIter<'a, Scalar = T>,

§

type Scalar = T

source§

fn convex_hull(&'a self) -> Polygon<T>

source§

impl<'a, T, G> Extremes<'a, T> for Gwhere G: CoordsIter<'a, Scalar = T>, T: CoordNum,

source§

fn extremes(&'a self) -> Option<Outcome<T>>

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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<'a, T, G> MinimumRotatedRect<'a, T> for Gwhere T: CoordFloat + GeoFloat + GeoNum, G: CoordsIter<'a, Scalar = T>,

source§

impl<G, IP, IR, T> Rotate<T> for Gwhere T: CoordFloat, IP: Into<Option<Point<T>>>, IR: Into<Option<Rect<T>>>, G: Clone + Centroid<Output = IP> + BoundingRect<T, Output = IR> + AffineOps<T>,

source§

fn rotate_around_centroid(&self, degrees: T) -> G

Rotate a geometry around its centroid by an angle, in degrees Read more
source§

fn rotate_around_centroid_mut(&mut self, degrees: T)

Mutable version of Self::rotate_around_centroid
source§

fn rotate_around_center(&self, degrees: T) -> G

Rotate a geometry around the center of its bounding box by an angle, in degrees. Read more
source§

fn rotate_around_center_mut(&mut self, degrees: T)

Mutable version of Self::rotate_around_center
source§

fn rotate_around_point(&self, degrees: T, point: Point<T>) -> G

Rotate a Geometry around an arbitrary point by an angle, given in degrees Read more
source§

fn rotate_around_point_mut(&mut self, degrees: T, point: Point<T>)

Mutable version of Self::rotate_around_point
source§

impl<T, IR, G> Scale<T> for Gwhere T: CoordFloat, IR: Into<Option<Rect<T>>>, G: Clone + AffineOps<T> + BoundingRect<T, Output = IR>,

source§

fn scale(&self, scale_factor: T) -> G

Scale a geometry from it’s bounding box center. Read more
source§

fn scale_mut(&mut self, scale_factor: T)

Mutable version of scale
source§

fn scale_xy(&self, x_factor: T, y_factor: T) -> G

Scale a geometry from it’s bounding box center, using different values for x_factor and y_factor to distort the geometry’s aspect ratio. Read more
source§

fn scale_xy_mut(&mut self, x_factor: T, y_factor: T)

Mutable version of scale_xy.
source§

fn scale_around_point( &self, x_factor: T, y_factor: T, origin: impl Into<Coord<T>> ) -> G

Scale a geometry around a point of origin. Read more
source§

fn scale_around_point_mut( &mut self, x_factor: T, y_factor: T, origin: impl Into<Coord<T>> )

Mutable version of scale_around_point.
source§

impl<T, IR, G> Skew<T> for Gwhere T: CoordFloat, IR: Into<Option<Rect<T>>>, G: Clone + AffineOps<T> + BoundingRect<T, Output = IR>,

source§

fn skew(&self, degrees: T) -> G

An affine transformation which skews a geometry, sheared by a uniform angle along the x and y dimensions. Read more
source§

fn skew_mut(&mut self, degrees: T)

Mutable version of skew.
source§

fn skew_xy(&self, degrees_x: T, degrees_y: T) -> G

An affine transformation which skews a geometry, sheared by an angle along the x and y dimensions. Read more
source§

fn skew_xy_mut(&mut self, degrees_x: T, degrees_y: T)

Mutable version of skew_xy.
source§

fn skew_around_point(&self, xs: T, ys: T, origin: impl Into<Coord<T>>) -> G

An affine transformation which skews a geometry around a point of origin, sheared by an angle along the x and y dimensions. Read more
source§

fn skew_around_point_mut(&mut self, xs: T, ys: T, origin: impl Into<Coord<T>>)

Mutable version of skew_around_point.
source§

impl<T> ToOwned for Twhere T: Clone,

§

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, G> Translate<T> for Gwhere T: CoordNum, G: AffineOps<T>,

source§

fn translate(&self, x_offset: T, y_offset: T) -> G

Translate a Geometry along its axes by the given offsets Read more
source§

fn translate_mut(&mut self, x_offset: T, y_offset: T)

Translate a Geometry along its axes, but in place.
source§

fn translate_in_place(&mut self, x_offset: T, y_offset: T)

source§

fn translate_inplace(&mut self, x_offset: T, y_offset: T)

source§

impl<G, T, U> TryConvert<T, U> for Gwhere T: CoordNum, U: CoordNum + TryFrom<T>, G: MapCoords<T, U>,

§

type Output = Result<<G as MapCoords<T, U>>::Output, <U as TryFrom<T>>::Error>

source§

fn try_convert(&self) -> <G as TryConvert<T, U>>::Output

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

source§

fn is_within(&self, b: &G2) -> bool

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,