pub struct MonotonicPolygons<T: GeoNum>(/* private fields */);
Expand description
A multi-polygon represented as a collection of (disjoint) monotone polygons.
This structure is optimized for point-in-polygon queries, and is typically
much faster than the equivalent method on Polygon
. This is because a
single monotone polygon can be tested for intersection with a point in
O(log n)
time, where n
is the number of vertices in the polygon. In
contrast, the equivalent method on Polygon
is O(n)
. Typically, a
polygon can be sub-divided into a small number of monotone polygons, thus
providing a significant speed-up.
§Example
Construct a MonotonicPolygons
from a Polygon
, or a MultiPolygon
using
MontonicPolygons::from
, and query point intersection via the
Intersects<Coord>
trait.
use geo::prelude::*;
use geo::{polygon, coord};
let polygon = polygon![
(x: -2., y: 1.),
(x: 1., y: 3.),
(x: 4., y: 1.),
(x: 1., y: -1.),
(x: -2., y: 1.),
];
let mp = MonotonicPolygons::from(polygon);
assert!(mp.intersects(&coord!(x: -2., y: 1.)));
Implementations§
Source§impl<T: GeoNum> MonotonicPolygons<T>
impl<T: GeoNum> MonotonicPolygons<T>
Sourcepub fn subdivisions(&self) -> &Vec<MonoPoly<T>>
pub fn subdivisions(&self) -> &Vec<MonoPoly<T>>
Get a reference to the monotone polygons.
Sourcepub fn into_subdivisions(self) -> Vec<MonoPoly<T>>
pub fn into_subdivisions(self) -> Vec<MonoPoly<T>>
Reduce to inner Vec
of monotone polygons.
Trait Implementations§
Source§impl<T: Clone + GeoNum> Clone for MonotonicPolygons<T>
impl<T: Clone + GeoNum> Clone for MonotonicPolygons<T>
Source§fn clone(&self) -> MonotonicPolygons<T>
fn clone(&self) -> MonotonicPolygons<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: GeoNum> From<MultiPolygon<T>> for MonotonicPolygons<T>
impl<T: GeoNum> From<MultiPolygon<T>> for MonotonicPolygons<T>
Source§fn from(mp: MultiPolygon<T>) -> Self
fn from(mp: MultiPolygon<T>) -> Self
Source§impl<T: GeoNum> Intersects<Coord<T>> for MonotonicPolygons<T>
impl<T: GeoNum> Intersects<Coord<T>> for MonotonicPolygons<T>
fn intersects(&self, other: &Coord<T>) -> bool
Auto Trait Implementations§
impl<T> Freeze for MonotonicPolygons<T>
impl<T> RefUnwindSafe for MonotonicPolygons<T>where
T: RefUnwindSafe,
impl<T> Send for MonotonicPolygons<T>where
T: Send,
impl<T> Sync for MonotonicPolygons<T>where
T: Sync,
impl<T> Unpin for MonotonicPolygons<T>where
T: Unpin,
impl<T> UnwindSafe for MonotonicPolygons<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more