Skip to main content

sym_difference

Function sym_difference 

Source
pub fn sym_difference<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

Symmetric difference of two polygons — the region inside exactly one of them ((A − B) ∪ (B − A)).

Mirrors boost::geometry::sym_difference from algorithms/sym_difference.hpp:795-824.

§Errors

OverlayError::Unsupported when coordinates exceed the predicate range.

§Examples

use geometry_cs::Cartesian;
use geometry_model::{polygon, Point2D, Polygon};
use geometry_overlay::operation::sym_difference;
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 = sym_difference(&a, &b).unwrap();
assert!(out.polygons().count() >= 1);