Struct Region

Source
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

Source

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).

Source

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

As Self::minkowski_sum.

Source

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.

Source

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

As Self::dilate_inner.

Source

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

As Self::dilate_inner.

Source

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

As Self::dilate_inner.

Source§

impl Region

Source

pub fn empty() -> Self

The empty region. Not a failure: the identity for union.

Source

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.

Source

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.

Source

pub fn polygons(&self) -> &[Polygon]

The region’s polygons, in canonical order.

Source

pub const fn evidence(&self) -> RegionEvidence

What the producing operation did.

Source

pub fn is_empty(&self) -> bool

True when the region covers no area.

Source

pub fn area(&self) -> f64

Total covered area. Holes subtract.

Source

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.

Source

pub fn boundary_rings(&self) -> Vec<Ring>

Every boundary ring, outer boundaries first then holes.

Source

pub fn union( &self, other: &Self, tolerance: Tolerance, ) -> Result<Self, OverlayError>

Set union.

Source

pub fn intersection( &self, other: &Self, tolerance: Tolerance, ) -> Result<Self, OverlayError>

Set intersection.

Source

pub fn difference( &self, other: &Self, tolerance: Tolerance, ) -> Result<Self, OverlayError>

Set difference: this region minus other.

Source

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.

Source

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.

Source

pub fn translate(&self, offset: Vec2) -> Result<Self, OverlayError>

Translate by offset. Rigid: area and component count are preserved.

Source

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

Source

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.

Trait Implementations§

Source§

impl Clone for Region

Source§

fn clone(&self) -> Region

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Region

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Region

Source§

fn default() -> Region

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Region

Source§

fn eq(&self, other: &Region) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Region

Auto Trait Implementations§

§

impl Freeze for Region

§

impl RefUnwindSafe for Region

§

impl Send for Region

§

impl Sync for Region

§

impl Unpin for Region

§

impl UnwindSafe for Region

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.