# Struct rgeometry::data::Polygon

pub struct Polygon<T> { /* private fields */ }

## Implementations

$O(1)$

$O(n^2)$

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

Converts to this type from the input type.

Converts to this type from the input type.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

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

Returns the argument unchanged.

Calls U::from(self).

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

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)

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.