pub struct PolygonConvex<T>(_);
Implementations
sourceimpl<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>
Assume that a polygon is convex.
Safety
The input polygon has to be strictly convex, ie. no vertices are allowed to be concave or colinear.
Time complexity
$O(1)$
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>> where
T: Clone + Into<f64>,
sourcepub fn random<R>(n: usize, rng: &mut R) -> PolygonConvex<T> where
T: Bounded + PolygonScalar + SampleUniform + Copy,
R: Rng + ?Sized,
pub fn random<R>(n: usize, rng: &mut R) -> PolygonConvex<T> where
T: Bounded + PolygonScalar + SampleUniform + Copy,
R: Rng + ?Sized,
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)$
Examples
PolygonConvex::random(3, &mut rand::thread_rng())
Runsourceimpl 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>) -> PointLocation where
T: PolygonScalar,
pub fn triangulate(
&self
) -> impl Iterator<Item = (Cursor<'_, T>, Cursor<'_, T>, Cursor<'_, T>)> + '_ where
T: PolygonScalar,
pub fn centroid(&self) -> Point<T, 2> where
T: PolygonScalar,
pub fn bounding_box(&self) -> (Point<T, 2>, Point<T, 2>) where
T: PolygonScalar,
sourcepub fn signed_area<F>(&self) -> F where
T: PolygonScalar + Into<F>,
F: NumOps<F, F> + Sum + FromPrimitive,
pub fn signed_area<F>(&self) -> F where
T: PolygonScalar + Into<F>,
F: NumOps<F, F> + Sum + FromPrimitive,
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
// The area of this polygon is 1/2 and won't fit in an `i32`
let p = Polygon::new(vec![
Point::new([0, 0]),
Point::new([1, 0]),
Point::new([0, 1]),
])?;
assert_eq!(p.signed_area::<i32>(), 0);
Run// The area of this polygon is 1/2 and will fit in a `Ratio<i32>`.
let p = Polygon::new(vec![
Point::new([0, 0]),
Point::new([1, 0]),
Point::new([0, 1]),
])?;
assert_eq!(p.signed_area::<Ratio<i32>>(), Ratio::from((1,2)));
Runsourcepub fn signed_area_2x<F>(&self) -> F where
T: PolygonScalar + Into<F>,
F: NumOps<F, F> + Sum,
pub fn signed_area_2x<F>(&self) -> F where
T: PolygonScalar + Into<F>,
F: NumOps<F, F> + Sum,
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:
// The area of this polygon is 1/2 and cannot fit in an `i32` variable
// so lets compute twice the area.
let p = Polygon::new(vec![
Point::new([0, 0]),
Point::new([1, 0]),
Point::new([0, 1]),
])?;
assert_eq!(p.signed_area_2x::<i32>(), 1);
Run// The area of a polygon may require more bits of precision than are
// used for the coordinates.
let p = Polygon::new(vec![
Point::new([0, 0]),
Point::new([i32::MAX, 0]),
Point::new([0, i32::MAX]),
])?;
assert_eq!(p.signed_area_2x::<i64>(), 4611686014132420609_i64);
Runpub fn orientation(&self) -> Orientation where
T: PolygonScalar,
pub fn boundary_slice(&self) -> &[PointId]
pub fn iter_boundary(&self) -> CursorIter<'_, T>ⓘNotable traits for CursorIter<'a, T>impl<'a, T> Iterator for CursorIter<'a, T> type Item = Cursor<'a, T>;
pub fn iter_boundary_edges(&self) -> EdgeIter<'_, T>ⓘNotable traits for EdgeIter<'a, T>impl<'a, T: Clone> Iterator for EdgeIter<'a, T> type Item = DirectedEdge<'a, T, 2>;
pub fn iter(&self) -> Iter<'_, T>ⓘNotable traits for Iter<'a, T>impl<'a, T> Iterator for Iter<'a, T> type Item = &'a Point<T, 2>;
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 normalize(&self) -> Polygon<OrderedFloat<f64>>
Trait Implementations
sourceimpl<T: Clone> Clone for PolygonConvex<T>
impl<T: Clone> Clone for PolygonConvex<T>
sourcefn clone(&self) -> PolygonConvex<T>
fn clone(&self) -> PolygonConvex<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T: Debug> Debug for PolygonConvex<T>
impl<T: Debug> Debug for PolygonConvex<T>
sourceimpl<T> Deref for PolygonConvex<T>
impl<T> Deref for PolygonConvex<T>
sourceimpl Distribution<PolygonConvex<isize>> for Standard
impl Distribution<PolygonConvex<isize>> for Standard
sourcefn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> PolygonConvex<isize>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> PolygonConvex<isize>
Generate a random value of T
, using rng
as the source of randomness.
sourcefn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T> where
R: Rng,
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T> where
R: Rng,
Create an iterator that generates random values of T
, using rng
as
the source of randomness. Read more
sourceimpl<'a, T> From<&'a PolygonConvex<T>> for &'a Polygon<T>
impl<'a, T> From<&'a PolygonConvex<T>> for &'a Polygon<T>
sourcefn from(convex: &'a PolygonConvex<T>) -> &'a Polygon<T>
fn from(convex: &'a PolygonConvex<T>) -> &'a Polygon<T>
Converts to this type from the input type.
sourceimpl<T> From<PolygonConvex<T>> for Polygon<T>
impl<T> From<PolygonConvex<T>> for Polygon<T>
sourcefn from(convex: PolygonConvex<T>) -> Polygon<T>
fn from(convex: PolygonConvex<T>) -> Polygon<T>
Converts to this type from the input type.
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more