pub trait BooleanOps {
type Scalar: BoolOpsNum;
Show 13 methods
// Required method
fn rings(&self) -> impl Iterator<Item = &LineString<Self::Scalar>>;
// Provided methods
fn boolean_op(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
op: OpType,
) -> MultiPolygon<Self::Scalar> { ... }
fn boolean_op_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
op: OpType,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar> { ... }
fn intersection(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
) -> MultiPolygon<Self::Scalar> { ... }
fn intersection_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar> { ... }
fn union(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
) -> MultiPolygon<Self::Scalar> { ... }
fn union_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar> { ... }
fn xor(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
) -> MultiPolygon<Self::Scalar> { ... }
fn xor_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar> { ... }
fn difference(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
) -> MultiPolygon<Self::Scalar> { ... }
fn difference_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar> { ... }
fn clip(
&self,
multi_line_string: &MultiLineString<Self::Scalar>,
invert: bool,
) -> MultiLineString<Self::Scalar> { ... }
fn clip_with_fill_rule(
&self,
multi_line_string: &MultiLineString<Self::Scalar>,
invert: bool,
fill_rule: FillRule,
) -> MultiLineString<Self::Scalar> { ... }
}Expand description
Boolean Operations on geometry.
Boolean operations are set operations on geometries considered as a subset of the 2-D plane. The operations supported are: intersection, union, symmetric difference (xor), and set-difference on pairs of 2-D geometries and clipping a 1-D geometry with self.
These operations are implemented on Polygon and the MultiPolygon
geometries.
§Validity
Note that the operations are strictly well-defined only on valid geometries. However, the implementation generally works well as long as the interiors of polygons are contained within their corresponding exteriors.
Degenerate 2-d geoms with 0 area are handled, and ignored by the algorithm.
In particular, taking union with an empty geom should remove degeneracies
and fix invalid polygons as long the interior-exterior requirement above is
satisfied.
§Performance
For union operations on a large number of Polygons or MultiPolygons,
using unary_union will yield far better performance.
Required Associated Types§
type Scalar: BoolOpsNum
Required Methods§
Sourcefn rings(&self) -> impl Iterator<Item = &LineString<Self::Scalar>>
fn rings(&self) -> impl Iterator<Item = &LineString<Self::Scalar>>
The exterior and interior rings of the geometry.
It doesn’t particularly matter which order they are in, as the topology algorithm counts crossings to determine the interior and exterior of the polygon.
It is required that the rings are from valid geometries, that the rings not overlap. In the case of a MultiPolygon, this requires that none of its polygon’s interiors may overlap.
Provided Methods§
Sourcefn boolean_op(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
op: OpType,
) -> MultiPolygon<Self::Scalar>
fn boolean_op( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, op: OpType, ) -> MultiPolygon<Self::Scalar>
Performs a boolean operation between shapes using the default FillRule::EvenOdd fill rule.
The EvenOdd rule determines filled regions based on the parity of path crossings.
It correctly handles “holes” in polygons by accounting for path direction and overlapping regions.
This behavior models that of a real-world laser cutter: each shape is treated as a continuous cut from solid material. When a new shape overlaps an existing cut, the overlapping area is removed, potentially splitting the geometry into multiple disjoint parts.
This fill rule is intuitive for applications like CAD tooling, CNC routing, and other manufacturing processes where overlapping shapes subtract from the material rather than accumulate.
To use a different fill rule, such as FillRule::NonZero, use Self::boolean_op_with_fill_rule instead.
Sourcefn boolean_op_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
op: OpType,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar>
fn boolean_op_with_fill_rule( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, op: OpType, fill_rule: FillRule, ) -> MultiPolygon<Self::Scalar>
Performs a boolean operation with the specified fill rule.
§Examples
use geo::algorithm::bool_ops::{BooleanOps, OpType, FillRule};
use geo::wkt;
let polygon1 = wkt!(POLYGON((0.0 0.0, 10.0 0.0, 10.0 10.0, 0.0 10.0, 0.0 0.0)));
let polygon2 = wkt!(POLYGON((5.0 5.0, 15.0 5.0, 15.0 15.0, 5.0 15.0, 5.0 5.0)));
let result = polygon1.boolean_op_with_fill_rule(&polygon2, OpType::Union, FillRule::NonZero);
assert_eq!(result.0.len(), 1);Sourcefn intersection(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
) -> MultiPolygon<Self::Scalar>
fn intersection( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, ) -> MultiPolygon<Self::Scalar>
Returns the overlapping regions shared by both self and other.
Sourcefn intersection_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar>
fn intersection_with_fill_rule( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, fill_rule: FillRule, ) -> MultiPolygon<Self::Scalar>
Returns the overlapping regions shared by both self and other, using the specified fill rule.
Sourcefn union(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
) -> MultiPolygon<Self::Scalar>
fn union( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, ) -> MultiPolygon<Self::Scalar>
Combines the regions of both self and other into a single geometry, removing
overlaps and merging boundaries. Consider using unary_union for efficiently combining several adjacent / overlapping geometries.
Sourcefn union_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar>
fn union_with_fill_rule( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, fill_rule: FillRule, ) -> MultiPolygon<Self::Scalar>
Combines the regions of both self and other into a single geometry, removing
overlaps and merging boundaries, using the specified fill rule.
Sourcefn xor(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
) -> MultiPolygon<Self::Scalar>
fn xor( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, ) -> MultiPolygon<Self::Scalar>
The regions that are in either self or other, but not in both.
Sourcefn xor_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar>
fn xor_with_fill_rule( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, fill_rule: FillRule, ) -> MultiPolygon<Self::Scalar>
The regions that are in either self or other, but not in both.
Sourcefn difference(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
) -> MultiPolygon<Self::Scalar>
fn difference( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, ) -> MultiPolygon<Self::Scalar>
The regions of self which are not in other.
Sourcefn difference_with_fill_rule(
&self,
other: &impl BooleanOps<Scalar = Self::Scalar>,
fill_rule: FillRule,
) -> MultiPolygon<Self::Scalar>
fn difference_with_fill_rule( &self, other: &impl BooleanOps<Scalar = Self::Scalar>, fill_rule: FillRule, ) -> MultiPolygon<Self::Scalar>
The regions of self which are not in other, using the specified fill rule.
Sourcefn clip(
&self,
multi_line_string: &MultiLineString<Self::Scalar>,
invert: bool,
) -> MultiLineString<Self::Scalar>
fn clip( &self, multi_line_string: &MultiLineString<Self::Scalar>, invert: bool, ) -> MultiLineString<Self::Scalar>
Clip a 1-D geometry with self.
Returns the portion of ls that lies within self (known as the set-theoeretic
intersection) if invert is false, and the difference (ls - self) otherwise.
Sourcefn clip_with_fill_rule(
&self,
multi_line_string: &MultiLineString<Self::Scalar>,
invert: bool,
fill_rule: FillRule,
) -> MultiLineString<Self::Scalar>
fn clip_with_fill_rule( &self, multi_line_string: &MultiLineString<Self::Scalar>, invert: bool, fill_rule: FillRule, ) -> MultiLineString<Self::Scalar>
Clip a 1-D geometry with self.
Returns the portion of ls that lies within self (known as the set-theoeretic
intersection) if invert is false, and the difference (ls - self) otherwise.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.