Struct libreda_pnr::db::Polygon[]

pub struct Polygon<T> where
    T: CoordinateType
{ pub exterior: SimplePolygon<T>, pub interiors: Vec<SimplePolygon<T>, Global>, }

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

Fields

exterior: SimplePolygon<T>

The outer hull of the polygon.

interiors: Vec<SimplePolygon<T>, Global>

A list of holes in the polygon.

Implementations

impl<T> Polygon<T> where
    T: CoordinateType

pub fn new<I>(i: I) -> Polygon<T> where
    I: Into<Polygon<T>>, 

Create a new polygon from a sequence of points.

pub fn empty() -> Polygon<T>

Create empty polygon without any vertices.

pub fn new_with_holes<E, I>(exterior: E, holes: Vec<I, Global>) -> Polygon<T> where
    I: Into<SimplePolygon<T>>,
    E: Into<SimplePolygon<T>>, 

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

pub fn len(&self) -> usize

Get the number of vertices.

pub fn edges(&self) -> Vec<Edge<T>, Global>

Get all exterior edges of the polygon.

pub fn convex_hull(&self) -> Polygon<T> where
    T: Ord

Get the convex hull of the polygon.

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

pub fn lower_left_vertex(&self) -> Point<T>

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

pub fn orientation(&self) -> Orientation

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(), Orientation::CounterClockWise);

Trait Implementations

impl<T> Clone for Polygon<T> where
    T: Clone + CoordinateType

impl<T> Debug for Polygon<T> where
    T: Debug + CoordinateType

impl<T> DoubledOrientedArea<T> for Polygon<T> where
    T: CoordinateType

pub fn area_doubled_oriented(&self) -> T

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

assert_eq!(poly.area_doubled_oriented(), 3);

impl<T> Eq for Polygon<T> where
    T: Eq + CoordinateType

impl<'_, T> From<&'_ Rect<T>> for Polygon<T> where
    T: CoordinateType

Create a polygon from a rectangle.

impl<'_, T> From<&'_ SimplePolygon<T>> for Polygon<T> where
    T: CoordinateType

Create a polygon from a simple polygon.

impl<'a, T, P> From<&'a Vec<P, Global>> for Polygon<T> where
    T: CoordinateType,
    Point<T>: From<&'a P>, 

Create a polygon from a Vec of values convertible to Points.

impl<T> From<Polygon<T>> for Geometry<T> where
    T: CoordinateType

impl<T> From<Rect<T>> for Polygon<T> where
    T: CoordinateType

Create a polygon from a rectangle.

impl<T> From<SimplePolygon<T>> for Polygon<T> where
    T: CoordinateType

Create a polygon from a simple polygon.

impl<T, P> From<Vec<P, Global>> for Polygon<T> where
    T: CoordinateType,
    Point<T>: From<P>, 

Create a polygon from a Vec of values convertible to Points.

impl<T, P> FromIterator<P> for Polygon<T> where
    T: CoordinateType,
    P: Into<Point<T>>, 

Create a polygon from a iterator of values convertible to Points.

impl<T> Hash for Polygon<T> where
    T: Hash + CoordinateType

impl<T> Into<Polygon<T>> for Geometry<T> where
    T: CoordinateType + NumCast

pub fn into(self) -> Polygon<T>

Convert a geometry into a polygon.

impl<T> MapPointwise<T> for Polygon<T> where
    T: CoordinateType

impl<T> PartialEq<Polygon<T>> for Polygon<T> where
    T: CoordinateType

pub fn eq(&self, rhs: &Polygon<T>) -> bool

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.

impl<T> StructuralEq for Polygon<T> where
    T: CoordinateType

impl<T> TryBoundingBox<T> for Polygon<T> where
    T: CoordinateType

impl<T, Dst> TryCastCoord<T, Dst> for Polygon<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast

type Output = Polygon<Dst>

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

impl<T> WindingNumber<T> for Polygon<T> where
    T: CoordinateType

pub fn winding_number(&self, point: Point<T>) -> isize

Calculate the winding number of the polygon around this point.

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

See: http://geomalgorithms.com/a03-_inclusion.html

Auto Trait Implementations

impl<T> RefUnwindSafe for Polygon<T> where
    T: RefUnwindSafe

impl<T> Send for Polygon<T> where
    T: Send

impl<T> Sync for Polygon<T> where
    T: Sync

impl<T> Unpin for Polygon<T> where
    T: Unpin

impl<T> UnwindSafe for Polygon<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<S, T> Mirror<T> for S where
    S: MapPointwise<T>,
    T: CoordinateType

pub fn mirror_x(&self) -> S

Return the geometrical object mirrored at the x axis.

pub fn mirror_y(&self) -> S

Return the geometrical object mirrored at the y axis.

impl<S, T> RotateOrtho<T> for S where
    S: MapPointwise<T>,
    T: CoordinateType

impl<S, T> Scale<T> for S where
    S: MapPointwise<T>,
    T: CoordinateType

impl<T> TextType for T where
    T: Clone + Eq + Debug + Hash

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<S, T> Translate<T> for S where
    S: MapPointwise<T>,
    T: CoordinateType

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.