Struct geo::algorithm::monotone::MonotonicPolygons
source · 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 more