Struct rgeometry::data::polygon::PolygonConvex [−][src]
pub struct PolygonConvex<T>(_);
Implementations
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)$
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 random<R: ?Sized>(n: usize, rng: &mut R) -> PolygonConvex<T> where
T: Bounded + PolygonScalar + SampleUniform + Copy,
R: Rng,
pub fn random<R: ?Sized>(n: usize, rng: &mut R) -> PolygonConvex<T> where
T: Bounded + PolygonScalar + SampleUniform + Copy,
R: Rng,
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())Run
Methods from Deref<Target = Polygon<T>>
pub fn triangulate(
&self
) -> impl Iterator<Item = (Cursor<'_, T>, Cursor<'_, T>, Cursor<'_, T>)> + '_ where
T: PolygonScalar,
pub 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)));Run
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);Run
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>ⓘ
Panics if the edge isn’t part of the polygon.
Trait Implementations
Generate a random value of T
, using rng
as the source of randomness.
Create an iterator that generates random values of T
, using rng
as
the source of randomness. Read more
Performs the conversion.
Performs the conversion.
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
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V