pub struct Region { /* private fields */ }Expand description
A validated planar region: a normalised set of polygons with holes.
Construction validates; operations preserve validity. Ring ordering is canonical (outer counter-clockwise, holes clockwise, each rotated to its lexicographically smallest vertex) and polygons are sorted, so equal regions compare equal regardless of how they were built.
Implementations§
Source§impl Region
impl Region
Sourcepub fn minkowski_sum(
&self,
convex_ring: &Ring,
tolerance: Tolerance,
) -> Result<Self, MinkowskiError>
pub fn minkowski_sum( &self, convex_ring: &Ring, tolerance: Tolerance, ) -> Result<Self, MinkowskiError>
The Minkowski sum with a convex polygon convex: every point of the
region moved by every point of the polygon.
Decided exactly (ADR 0070), with each vertex sum a + k rounded
once to f64 and output vertices rounded once.
§Errors
MinkowskiError::NotConvex for a polygon that is not convex; the
sum with a non-convex one is not built yet (#145).
Sourcepub fn minkowski_erosion(
&self,
convex_ring: &Ring,
tolerance: Tolerance,
) -> Result<Self, MinkowskiError>
pub fn minkowski_erosion( &self, convex_ring: &Ring, tolerance: Tolerance, ) -> Result<Self, MinkowskiError>
The Minkowski erosion by a convex polygon: the points x for which
the polygon moved by x lies within the region.
§Errors
Sourcepub fn dilate_inner(
&self,
radius: f64,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn dilate_inner( &self, radius: f64, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Dilation by a disc of radius, contained in the exact one: the sum
with an inscribed polygon, drawn in by a margin.
§Errors
OverlayError::InvalidOffsetDistance for a radius that is not
finite and nonnegative, and overlay refusals.
Sourcepub fn dilate_outer(
&self,
radius: f64,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn dilate_outer( &self, radius: f64, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Dilation by a disc of radius, containing the exact one: the sum
with a circumscribed polygon, pushed out by a margin.
§Errors
Sourcepub fn erode_inner(
&self,
radius: f64,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn erode_inner( &self, radius: f64, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Erosion by a disc of radius, contained in the exact one: eroded by
a circumscribed polygon, pushed out by a margin. A route found in it
proves reachability.
§Errors
Sourcepub fn erode_outer(
&self,
radius: f64,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn erode_outer( &self, radius: f64, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Erosion by a disc of radius, containing the exact one: eroded by
an inscribed polygon, drawn in by a margin. No route in it proves
unreachability.
§Errors
Source§impl Region
impl Region
Sourcepub fn new(
polygons: Vec<Polygon>,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn new( polygons: Vec<Polygon>, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Build a region from polygons, validating every ring.
Validation is the same used by crate::overlay, so the two cannot
disagree about what a well-formed polygon is.
Sourcepub const fn bound(&self) -> Option<MorphologyBound>
pub const fn bound(&self) -> Option<MorphologyBound>
For a result of Self::dilate_inner, Self::dilate_outer,
Self::erode_inner or Self::erode_outer: which side of the
exact disc morphology it lies on and how far from it it can be.
None for every other region, including Self::dilate and
Self::erode, whose side is not stated.
Sourcepub const fn evidence(&self) -> RegionEvidence
pub const fn evidence(&self) -> RegionEvidence
What the producing operation did.
Sourcepub fn component_count(&self) -> usize
pub fn component_count(&self) -> usize
Number of disjoint connected components.
One polygon is one component: the overlay backend already resolves touching and overlapping input into disjoint output polygons, so counting them is the component count rather than an approximation of it.
Sourcepub fn boundary_rings(&self) -> Vec<Ring>
pub fn boundary_rings(&self) -> Vec<Ring>
Every boundary ring, outer boundaries first then holes.
Sourcepub fn union(
&self,
other: &Self,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn union( &self, other: &Self, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Set union.
Sourcepub fn intersection(
&self,
other: &Self,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn intersection( &self, other: &Self, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Set intersection.
Sourcepub fn difference(
&self,
other: &Self,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn difference( &self, other: &Self, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Set difference: this region minus other.
Sourcepub fn dilate(
&self,
radius: f64,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn dilate( &self, radius: f64, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Dilate by radius: the Minkowski sum with a disc, approximated by
round joins on an unstated side of the exact result. Where a verdict
must be proven, use Self::dilate_inner or Self::dilate_outer.
This is the disc-expansion form used for clearance envelopes. A zero radius is the identity.
Sourcepub fn erode(
&self,
radius: f64,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn erode( &self, radius: f64, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Erode by radius: the Minkowski erosion by a disc, approximated on
an unstated side of the exact result. Where a verdict must be
proven, use Self::erode_inner (a route found proves
reachability) or Self::erode_outer (no route proves
unreachability).
A region thinner than 2 * radius anywhere is cut there, which is
how a corridor narrower than a body radius becomes impassable. If
that removes everything the result is empty and
RegionEvidence::emptied is set.
Sourcepub fn translate(&self, offset: Vec2) -> Result<Self, OverlayError>
pub fn translate(&self, offset: Vec2) -> Result<Self, OverlayError>
Translate by offset. Rigid: area and component count are preserved.
Sourcepub fn sweep(
&self,
direction: Vec2,
tolerance: Tolerance,
) -> Result<Self, OverlayError>
pub fn sweep( &self, direction: Vec2, tolerance: Tolerance, ) -> Result<Self, OverlayError>
Sweep along direction: the union of the region with every
translate of itself along the vector.
Equivalent to the Minkowski sum with the segment [0, direction].
Built as the union of the region and its translate plus the hull
swept between them, which for a polygon set is exactly the union of
the two end positions with the stroke of each boundary edge; using
the union of endpoints alone would miss the swept middle whenever
the translation exceeds the region’s own extent.
Source§impl Region
impl Region
Sourcepub fn visibility_polygon(
&self,
viewpoint: Point2,
tolerance: Tolerance,
) -> Result<Self, VisibilityError>
pub fn visibility_polygon( &self, viewpoint: Point2, tolerance: Tolerance, ) -> Result<Self, VisibilityError>
The part of the region in sight of viewpoint: every point the
straight segment from the viewpoint reaches without leaving the
region. Walls and holes cast shadows.
§Errors
VisibilityError::NotInside for a viewpoint on the boundary or
outside.