Struct libreda_db::layout::prelude::Polygon
source · pub struct Polygon<T> {
pub exterior: SimplePolygon<T>,
pub interiors: Vec<SimplePolygon<T>>,
}Expand description
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>>A list of holes in the polygon.
Implementations§
source§impl<T> Polygon<T>
impl<T> Polygon<T>
sourcepub fn new_raw(exterior: Vec<Point<T>>) -> Polygon<T>
pub fn new_raw(exterior: Vec<Point<T>>) -> Polygon<T>
Create a new polygon from a sequence of points. Ordering of points is not normalized. This impacts the equality check.
sourcepub fn new_raw_with_holes<E, I>(exterior: E, holes: Vec<I>) -> Polygon<T>
pub fn new_raw_with_holes<E, I>(exterior: E, holes: Vec<I>) -> Polygon<T>
Create a new polygon from a hull and a list of holes. Ordering of points is not normalized. This impacts the equality check.
source§impl<T> Polygon<T>where
T: PartialOrd,
impl<T> Polygon<T>where
T: PartialOrd,
sourcepub fn new_with_holes<E, I>(exterior: E, holes: Vec<I>) -> Polygon<T>
pub fn new_with_holes<E, I>(exterior: E, holes: Vec<I>) -> Polygon<T>
Create a new polygon from a hull and a list of holes.
sourcepub fn normalize(&mut self)
pub fn normalize(&mut self)
Reorder vertices and holes to get the lexicographically smallest representation of this polygon. Does not change the orientations.
sourcepub fn normalized(self) -> Polygon<T>
pub fn normalized(self) -> Polygon<T>
Reorder vertices and holes to get the lexicographically smallest representation of this polygon. Does not change the orientations.
source§impl<T> Polygon<T>where
T: CoordinateType,
impl<T> Polygon<T>where
T: CoordinateType,
sourcepub fn convex_hull(&self) -> SimplePolygon<T>where
T: Ord,
pub fn convex_hull(&self) -> SimplePolygon<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
sourcepub fn lower_left_vertex(&self) -> Point<T>
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));
sourcepub fn orientation<Area>(&self) -> Orientation
pub fn orientation<Area>(&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::<i64>(), Orientation::CounterClockWise);
Trait Implementations§
source§impl BooleanOp<Ratio<i32>> for Polygon<Ratio<i32>>
impl BooleanOp<Ratio<i32>> for Polygon<Ratio<i32>>
source§fn boolean_op(
&self,
operation: Operation,
other: &Polygon<Ratio<i32>>,
polygon_semantics: PolygonSemantics
) -> MultiPolygon<Ratio<i32>>
fn boolean_op( &self, operation: Operation, other: &Polygon<Ratio<i32>>, polygon_semantics: PolygonSemantics ) -> MultiPolygon<Ratio<i32>>
source§fn intersection(&self, other: &Self) -> MultiPolygon<T>
fn intersection(&self, other: &Self) -> MultiPolygon<T>
self & other. Read moresource§fn difference(&self, other: &Self) -> MultiPolygon<T>
fn difference(&self, other: &Self) -> MultiPolygon<T>
self - other. Read moresource§impl BooleanOp<Ratio<i64>> for Polygon<Ratio<i64>>
impl BooleanOp<Ratio<i64>> for Polygon<Ratio<i64>>
source§fn boolean_op(
&self,
operation: Operation,
other: &Polygon<Ratio<i64>>,
polygon_semantics: PolygonSemantics
) -> MultiPolygon<Ratio<i64>>
fn boolean_op( &self, operation: Operation, other: &Polygon<Ratio<i64>>, polygon_semantics: PolygonSemantics ) -> MultiPolygon<Ratio<i64>>
source§fn intersection(&self, other: &Self) -> MultiPolygon<T>
fn intersection(&self, other: &Self) -> MultiPolygon<T>
self & other. Read moresource§fn difference(&self, other: &Self) -> MultiPolygon<T>
fn difference(&self, other: &Self) -> MultiPolygon<T>
self - other. Read moresource§impl BooleanOp<f32> for Polygon<f32>
impl BooleanOp<f32> for Polygon<f32>
source§fn boolean_op(
&self,
operation: Operation,
other: &Polygon<f32>,
polygon_semantics: PolygonSemantics
) -> MultiPolygon<f32>
fn boolean_op( &self, operation: Operation, other: &Polygon<f32>, polygon_semantics: PolygonSemantics ) -> MultiPolygon<f32>
source§fn intersection(&self, other: &Self) -> MultiPolygon<T>
fn intersection(&self, other: &Self) -> MultiPolygon<T>
self & other. Read moresource§fn difference(&self, other: &Self) -> MultiPolygon<T>
fn difference(&self, other: &Self) -> MultiPolygon<T>
self - other. Read moresource§impl BooleanOp<f64> for Polygon<f64>
impl BooleanOp<f64> for Polygon<f64>
source§fn boolean_op(
&self,
operation: Operation,
other: &Polygon<f64>,
polygon_semantics: PolygonSemantics
) -> MultiPolygon<f64>
fn boolean_op( &self, operation: Operation, other: &Polygon<f64>, polygon_semantics: PolygonSemantics ) -> MultiPolygon<f64>
source§fn intersection(&self, other: &Self) -> MultiPolygon<T>
fn intersection(&self, other: &Self) -> MultiPolygon<T>
self & other. Read moresource§fn difference(&self, other: &Self) -> MultiPolygon<T>
fn difference(&self, other: &Self) -> MultiPolygon<T>
self - other. Read moresource§impl BooleanOp<i32> for Polygon<i32>
impl BooleanOp<i32> for Polygon<i32>
source§fn boolean_op(
&self,
operation: Operation,
other: &Polygon<i32>,
polygon_semantics: PolygonSemantics
) -> MultiPolygon<i32>
fn boolean_op( &self, operation: Operation, other: &Polygon<i32>, polygon_semantics: PolygonSemantics ) -> MultiPolygon<i32>
source§fn intersection(&self, other: &Self) -> MultiPolygon<T>
fn intersection(&self, other: &Self) -> MultiPolygon<T>
self & other. Read moresource§fn difference(&self, other: &Self) -> MultiPolygon<T>
fn difference(&self, other: &Self) -> MultiPolygon<T>
self - other. Read moresource§impl BooleanOp<i64> for Polygon<i64>
impl BooleanOp<i64> for Polygon<i64>
source§fn boolean_op(
&self,
operation: Operation,
other: &Polygon<i64>,
polygon_semantics: PolygonSemantics
) -> MultiPolygon<i64>
fn boolean_op( &self, operation: Operation, other: &Polygon<i64>, polygon_semantics: PolygonSemantics ) -> MultiPolygon<i64>
source§fn intersection(&self, other: &Self) -> MultiPolygon<T>
fn intersection(&self, other: &Self) -> MultiPolygon<T>
self & other. Read moresource§fn difference(&self, other: &Self) -> MultiPolygon<T>
fn difference(&self, other: &Self) -> MultiPolygon<T>
self - other. Read moresource§impl<'de, T> Deserialize<'de> for Polygon<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Polygon<T>where
T: Deserialize<'de>,
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Polygon<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Polygon<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl<T, A> DoubledOrientedArea<A> for Polygon<T>
impl<T, A> DoubledOrientedArea<A> for Polygon<T>
source§fn area_doubled_oriented(&self) -> A
fn area_doubled_oriented(&self) -> A
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);
source§impl<T> From<&SimplePolygon<T>> for Polygon<T>where
T: Copy,
impl<T> From<&SimplePolygon<T>> for Polygon<T>where
T: Copy,
Create a polygon from a simple polygon.
source§fn from(simple_polygon: &SimplePolygon<T>) -> Polygon<T>
fn from(simple_polygon: &SimplePolygon<T>) -> Polygon<T>
source§impl<'a, T, P> From<&'a Vec<P>> for Polygon<T>
impl<'a, T, P> From<&'a Vec<P>> for Polygon<T>
Create a polygon from a Vec of values convertible to Points.
source§impl<T> From<SimplePolygon<T>> for Polygon<T>
impl<T> From<SimplePolygon<T>> for Polygon<T>
Create a polygon from a simple polygon.
source§fn from(simple_polygon: SimplePolygon<T>) -> Polygon<T>
fn from(simple_polygon: SimplePolygon<T>) -> Polygon<T>
source§impl<T, P> From<Vec<P>> for Polygon<T>
impl<T, P> From<Vec<P>> for Polygon<T>
Create a polygon from a Vec of values convertible to Points.
source§impl<T, P> FromIterator<P> for Polygon<T>
impl<T, P> FromIterator<P> for Polygon<T>
Create a polygon from a iterator of values convertible to Points.
source§impl<T> MapPointwise<T> for Polygon<T>where
T: CoordinateType,
impl<T> MapPointwise<T> for Polygon<T>where
T: CoordinateType,
source§impl<T> PartialEq for Polygon<T>where
T: PartialEq,
impl<T> PartialEq for Polygon<T>where
T: PartialEq,
source§impl<T> Serialize for Polygon<T>where
T: Serialize,
impl<T> Serialize for Polygon<T>where
T: Serialize,
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
source§impl<T> TryBoundingBox<T> for Polygon<T>where
T: Copy + PartialOrd,
impl<T> TryBoundingBox<T> for Polygon<T>where
T: Copy + PartialOrd,
source§fn try_bounding_box(&self) -> Option<Rect<T>>
fn try_bounding_box(&self) -> Option<Rect<T>>
source§impl<T, Dst> TryCastCoord<T, Dst> for Polygon<T>
impl<T, Dst> TryCastCoord<T, Dst> for Polygon<T>
source§impl<T> WindingNumber<T> for Polygon<T>where
T: CoordinateType,
impl<T> WindingNumber<T> for Polygon<T>where
T: CoordinateType,
source§fn winding_number(&self, point: Point<T>) -> isize
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.
impl<T> Eq for Polygon<T>where
T: Eq,
impl<T> StructuralPartialEq for Polygon<T>
Auto Trait Implementations§
impl<T> Freeze for Polygon<T>
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more