# Struct libreda_pnr::db::Polygon

``````pub struct Polygon<T> {
pub exterior: SimplePolygon<T>,
pub interiors: Vec<SimplePolygon<T>, Global>,
}``````
Expand description

A polygon possibly with holes. The polygon is defined by a hull and a list of holes which are both `SimplePolygon`s.

## Fields

`exterior: SimplePolygon<T>`

The outer hull of the polygon.

`interiors: Vec<SimplePolygon<T>, Global>`

A list of holes in the polygon.

## Implementations

Create empty polygon without any vertices.

Get the number of vertices.

Get all exterior edges of the polygon.

Iterate over all edges of the polygon, including interior edges.

Create a new polygon from a sequence of points.

Create a new polygon from a hull and a list of holes.

Get the convex hull of the polygon.

Implements Andrew’s Monotone Chain algorithm. See: http://geomalgorithms.com/a10-_hull-1.html

Get the vertex with lowest x-coordinate of the exterior polygon. Prefer lower y-coordinates to break ties.

##### Examples
``````use iron_shapes::polygon::Polygon;
use iron_shapes::point::Point;
let coords = vec![(0, 0), (1, 0), (-1, 2), (-1, 1)];

let poly = Polygon::new(coords);

assert_eq!(poly.lower_left_vertex(), Point::new(-1, 1));
``````

Get the orientation of the exterior polygon.

##### Examples
``````use iron_shapes::polygon::Polygon;
use iron_shapes::point::Point;
use iron_shapes::types::Orientation;
let coords = vec![(0, 0), (3, 0), (3, 1)];

let poly = Polygon::new(coords);

assert_eq!(poly.orientation::<i64>(), Orientation::CounterClockWise);
``````

## Trait Implementations

Compute the boolean operation of `self` and `other`. Read more

Compute the boolean intersection `self & other`. Read more

Compute the boolean difference `self - other`. Read more

Compute the boolean union `self | other`. Read more

Compute the boolean exclusive OR `self ^ other`. Read more

Compute the boolean operation of `self` and `other`. Read more

Compute the boolean intersection `self & other`. Read more

Compute the boolean difference `self - other`. Read more

Compute the boolean union `self | other`. Read more

Compute the boolean exclusive OR `self ^ other`. Read more

Compute the boolean operation of `self` and `other`. Read more

Compute the boolean intersection `self & other`. Read more

Compute the boolean difference `self - other`. Read more

Compute the boolean union `self | other`. Read more

Compute the boolean exclusive OR `self ^ other`. Read more

Compute the boolean operation of `self` and `other`. Read more

Compute the boolean intersection `self & other`. Read more

Compute the boolean difference `self - other`. Read more

Compute the boolean union `self | other`. Read more

Compute the boolean exclusive OR `self ^ other`. Read more

Compute the boolean operation of `self` and `other`. Read more

Compute the boolean intersection `self & other`. Read more

Compute the boolean difference `self - other`. Read more

Compute the boolean union `self | other`. Read more

Compute the boolean exclusive OR `self ^ other`. Read more

Compute the boolean operation of `self` and `other`. Read more

Compute the boolean intersection `self & other`. Read more

Compute the boolean difference `self - other`. Read more

Compute the boolean union `self | other`. Read more

Compute the boolean exclusive OR `self ^ other`. Read more

Returns a copy of the value. Read more

Performs copy-assignment from `source`. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Calculates the doubled oriented area.

Using doubled area allows to compute in the integers because the area of a polygon with integer coordinates is either integer or half-integer.

The area will be positive if the vertices are listed counter-clockwise, negative otherwise.

Complexity: O(n)

##### Examples
``````use iron_shapes::polygon::{Polygon, DoubledOrientedArea};
let coords = vec![(0, 0), (3, 0), (3, 1)];

let poly = Polygon::new(coords);

let area: i64 = poly.area_doubled_oriented();
assert_eq!(area, 3);
``````

Create a polygon from a rectangle.

Performs the conversion.

Create a polygon from a simple polygon.

Performs the conversion.

Create a polygon from a `Vec` of values convertible to `Point`s.

Performs the conversion.

Performs the conversion.

Create a polygon from a rectangle.

Performs the conversion.

Create a polygon from a simple polygon.

Performs the conversion.

Create a polygon from a `Vec` of values convertible to `Point`s.

Performs the conversion.

Create a polygon from a iterator of values convertible to `Point`s.

Creates a value from an iterator. Read more

Feeds this value into the given `Hasher`. Read more

Feeds a slice of this type into the given `Hasher`. Read more

Convert a geometry into a polygon.

Point wise transformation.

Equality test for polygons.

Two polygons are equal iff a cyclic shift on their vertices can be applied such that the both lists of vertices match exactly.

This method tests for `!=`.

Serialize this value into the given Serde serializer. Read more

Return the bounding box of this geometry if a bounding box is defined.

Output type of the cast. This is likely the same geometrical type just with other coordinate types. Read more

Try to cast to target data type. Read more

Cast to target data type. Read more

Calculate the winding number of the polygon around this point.

TODO: Define how point on edges and vertices is handled.

Check if `point` is inside the polygon, i.e. the polygons winds around the point a non-zero number of times. Read more

Check if `point` is inside the polygon, i.e. the polygon winds around the point an odd number of times. 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.

Return the geometrical object mirrored at the `x` axis.

Return the geometrical object mirrored at the `y` axis.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Rotate the geometrical shape by a multiple of 90 degrees.

Scale the geometrical shape. Scaling center is the origin `(0, 0)`.

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

Translate the geometrical object by a vector `v`.

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.