pub struct PolygonConvex<T>(/* private fields */);
Implementations§
source§impl<T> PolygonConvex<T>where
T: PolygonScalar,
impl<T> PolygonConvex<T>where
T: PolygonScalar,
sourcepub fn new_unchecked(poly: Polygon<T>) -> PolygonConvex<T>
pub fn new_unchecked(poly: Polygon<T>) -> PolygonConvex<T>
sourcepub fn locate(&self, pt: &Point<T, 2>) -> PointLocation
pub fn locate(&self, pt: &Point<T, 2>) -> PointLocation
sourcepub fn validate(&self) -> Result<(), Error>
pub fn validate(&self) -> Result<(), Error>
Validates the following properties:
- Each vertex is convex, ie. not concave or colinear.
- All generate polygon properties hold true (eg. no duplicate points, no self-intersections).
§Time complexity
$O(n \log n)$
pub fn float(self) -> PolygonConvex<OrderedFloat<f64>>
sourcepub fn random<R>(n: usize, rng: &mut R) -> PolygonConvex<T>
pub fn random<R>(n: usize, rng: &mut R) -> PolygonConvex<T>
Uniformly sample a random convex polygon.
The output polygon is rooted in (0,0)
, grows upwards, and has a height and width of T::max_value()
.
§Time complexity
$O(n \log n)$
source§impl PolygonConvex<OrderedFloat<f64>>
impl PolygonConvex<OrderedFloat<f64>>
pub fn normalize(&self) -> PolygonConvex<OrderedFloat<f64>>
Methods from Deref<Target = Polygon<T>>§
pub fn validate(&self) -> Result<(), Error>where
T: PolygonScalar,
pub fn validate_weakly(&self) -> Result<(), Error>where
T: PolygonScalar,
pub fn locate(&self, origin: &Point<T, 2>) -> PointLocationwhere
T: PolygonScalar,
pub fn triangulate(
&self,
) -> impl Iterator<Item = (Cursor<'_, T>, Cursor<'_, T>, Cursor<'_, T>)> + '_where
T: PolygonScalar,
pub fn centroid(&self) -> Point<T>where
T: PolygonScalar,
pub fn bounding_box(&self) -> (Point<T>, Point<T>)where
T: PolygonScalar,
sourcepub fn signed_area<F>(&self) -> F
pub fn signed_area<F>(&self) -> F
Computes the area of a polygon. If the polygon winds counter-clockwise, the area will be a positive number. If the polygon winds clockwise, the area will be negative.
§Return type
This function is polymorphic for the same reason as signed_area_2x
.
§Time complexity
$O(n)$
§Examples
sourcepub fn signed_area_2x<F>(&self) -> F
pub fn signed_area_2x<F>(&self) -> F
Compute double the area of a polygon. If the polygon winds counter-clockwise, the area will be a positive number. If the polygon winds clockwise, the area will be negative.
Why compute double the area? If you are using integer coordinates then the doubled area will also be an integer value. Computing the exact requires a division which may leave you with a non-integer result.
§Return type
Storing the area of a polygon may require more bits of precision than are used
for the coordinates. For example, if 32bit integers are used for point coordinates
then you might need 65 bits to store the area doubled. For this reason, the return
type is polymorphic and should be selected with care. If you are unsure which type
is appropriate, use BigInt
or BigRational
.
§Time complexity
$O(n)$
§Examples:
pub fn orientation(&self) -> Orientationwhere
T: PolygonScalar,
pub fn boundary_slice(&self) -> &[PointId]
pub fn equals(&self, other: &Self) -> boolwhere
T: PolygonScalar,
pub fn iter_boundary(&self) -> CursorIter<'_, T> ⓘ
pub fn iter_boundary_edges(&self) -> EdgeIter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
sourcepub fn direct(&self, edge: IndexEdge) -> DirectedIndexEdge
pub fn direct(&self, edge: IndexEdge) -> DirectedIndexEdge
Panics if the edge isn’t part of the polygon.
pub fn is_monotone(&self, direction: &Vector<T, 2>) -> boolwhere
T: PolygonScalar,
pub fn normalize(&self) -> Polygon<OrderedFloat<f64>>
Trait Implementations§
source§impl<T: Clone> Clone for PolygonConvex<T>
impl<T: Clone> Clone for PolygonConvex<T>
source§fn clone(&self) -> PolygonConvex<T>
fn clone(&self) -> PolygonConvex<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for PolygonConvex<T>
impl<T: Debug> Debug for PolygonConvex<T>
source§impl<T> Deref for PolygonConvex<T>
impl<T> Deref for PolygonConvex<T>
source§impl Distribution<PolygonConvex<isize>> for Standard
impl Distribution<PolygonConvex<isize>> for Standard
source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> PolygonConvex<isize>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> PolygonConvex<isize>
T
, using rng
as the source of randomness.source§fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
T
, using rng
as
the source of randomness. Read moresource§impl<'a, T> From<&'a PolygonConvex<T>> for &'a Polygon<T>
impl<'a, T> From<&'a PolygonConvex<T>> for &'a Polygon<T>
source§fn from(convex: &'a PolygonConvex<T>) -> &'a Polygon<T>
fn from(convex: &'a PolygonConvex<T>) -> &'a Polygon<T>
source§impl<T> From<PolygonConvex<T>> for Polygon<T>
impl<T> From<PolygonConvex<T>> for Polygon<T>
source§fn from(convex: PolygonConvex<T>) -> Polygon<T>
fn from(convex: PolygonConvex<T>) -> Polygon<T>
Auto Trait Implementations§
impl<T> Freeze for PolygonConvex<T>
impl<T> RefUnwindSafe for PolygonConvex<T>where
T: RefUnwindSafe,
impl<T> Send for PolygonConvex<T>where
T: Send,
impl<T> Sync for PolygonConvex<T>where
T: Sync,
impl<T> Unpin for PolygonConvex<T>where
T: Unpin,
impl<T> UnwindSafe for PolygonConvex<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)