Struct libreda_db::layout::prelude::SimplePolygon [−][src]
pub struct SimplePolygon<T> where
T: CoordinateType, {
pub points: Vec<Point<T>, Global>,
}Expand description
A SimplePolygon is a polygon defined by vertices. It does not contain holes but can be
self-intersecting.
TODO: Implement Deref for accessing the vertices.
Fields
points: Vec<Point<T>, Global>Vertices of the polygon.
Implementations
Create a new polygon from a list of points.
The orientation of the points is normalized to counter-clock-wise.
Create a new polygon from a list of points. The points are taken as they are, without reordering or simplification.
Create a new simple polygon from a rectangle.
Create empty polygon without any vertices.
Get the convex hull of the polygon.
Implements Andrew’s Monotone Chain algorithm. See: http://geomalgorithms.com/a10-_hull-1.html
Get all exterior edges of the polygon.
Examples
use iron_shapes::simple_polygon::SimplePolygon;
use iron_shapes::edge::Edge;
let coords = vec![(0, 0), (1, 0)];
let poly = SimplePolygon::from(coords);
assert_eq!(poly.edges(), vec![Edge::new((0, 0), (1, 0)), Edge::new((1, 0), (0, 0))]);
Test if all edges are parallel to the x or y axis.
Get the vertex with lowest x-coordinate. Prefer lower y-coordinates to break ties.
Examples
use iron_shapes::simple_polygon::SimplePolygon;
use iron_shapes::point::Point;
let coords = vec![(0, 0), (1, 0), (-1, 2), (-1, 1)];
let poly = SimplePolygon::from(coords);
assert_eq!(poly.lower_left_vertex(), Point::new(-1, 1));
Get the orientation of the polygon, i.e. check if it is wound clock-wise or counter-clock-wise.
Examples
use iron_shapes::simple_polygon::SimplePolygon;
use iron_shapes::point::Point;
use iron_shapes::types::Orientation;
let coords = vec![(0, 0), (3, 0), (3, 1)];
let poly = SimplePolygon::from(coords);
assert_eq!(poly.orientation(), Orientation::CounterClockWise);
Trait Implementations
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<SimplePolygon<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<SimplePolygon<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
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::traits::DoubledOrientedArea;
use iron_shapes::simple_polygon::SimplePolygon;
let coords = vec![(0, 0), (3, 0), (3, 1)];
let poly = SimplePolygon::from(coords);
assert_eq!(poly.area_doubled_oriented(), 3);
Create a polygon from a simple polygon.
Performs the conversion.
impl<I, T, P> From<I> for SimplePolygon<T> where
T: CoordinateType,
I: IntoIterator<Item = P>,
Point<T>: From<P>,
impl<I, T, P> From<I> for SimplePolygon<T> where
T: CoordinateType,
I: IntoIterator<Item = P>,
Point<T>: From<P>,
Create a polygon from a type that is convertible into an iterator of values convertible to Points.
Performs the conversion.
Performs the conversion.
Create a polygon from a simple polygon.
Performs the conversion.
Create a polygon from a iterator of values convertible to Points.
Creates a value from an iterator. Read more
Equality test for simple polygons.
Two polygons are equal iff a cyclic shift on their vertices can be applied such that the both lists of vertices match exactly.
Complexity: O(n^2)
TODO: Normalized ordering of vertices for faster comparison.
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Return the bounding box of this geometry if a bounding box is defined.
impl<T, Dst> TryCastCoord<T, Dst> for SimplePolygon<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for SimplePolygon<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = SimplePolygon<Dst>
type Output = SimplePolygon<Dst>
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
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
Auto Trait Implementations
impl<T> RefUnwindSafe for SimplePolygon<T> where
T: RefUnwindSafe,
impl<T> Send for SimplePolygon<T> where
T: Send,
impl<T> Sync for SimplePolygon<T> where
T: Sync,
impl<T> Unpin for SimplePolygon<T> where
T: Unpin,
impl<T> UnwindSafe for SimplePolygon<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Rotate the geometrical shape by a multiple of 90 degrees.