pub fn intersection<G1, G2, P>(
g1: &G1,
g2: &G2,
) -> Result<MultiPolygon<Polygon<P>>, OverlayError>where
G1: PolygonTrait<Point = P>,
G2: PolygonTrait<Point = P>,
P: PointMut + Default + Copy,
P::Scalar: CoordinateScalar + Into<f64>,
<P::Cs as CoordinateSystem>::Family: SameAs<CartesianFamily>,Expand description
Intersection of two polygons — the region inside both.
Mirrors boost::geometry::intersection from
algorithms/detail/intersection/interface.hpp:342-372. Returns an empty
MultiPolygon when the polygons do not overlap.
§Errors
OverlayError::Unsupported when coordinates exceed the predicate range.
§Examples
use geometry_cs::Cartesian;
use geometry_model::{polygon, Point2D, Polygon};
use geometry_overlay::operation::intersection;
use geometry_trait::MultiPolygon as _;
type P = Point2D<f64, Cartesian>;
let a: Polygon<P> = polygon![[(0.0, 0.0), (2.0, 0.0), (2.0, 2.0), (0.0, 2.0), (0.0, 0.0)]];
let b: Polygon<P> = polygon![[(1.0, 1.0), (3.0, 1.0), (3.0, 3.0), (1.0, 3.0), (1.0, 1.0)]];
let out = intersection(&a, &b).unwrap();
assert_eq!(out.polygons().count(), 1);