Struct rgeometry::data::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)$

Locate a point relative to a convex polygon.

Time complexity

$O(\log n)$

Examples

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

$O(1)$

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

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

Access point of a given vertex.

Time complexity

$O(1)$

Access cursor of a given vertex.

Time complexity

$O(1)$

Panics if the edge isn’t part of the polygon.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

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

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more

Performs the conversion.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.