Struct iron_shapes::polygon::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 SimplePolygon
s.
Fields
exterior: SimplePolygon<T>
The outer hull of the polygon.
interiors: Vec<SimplePolygon<T>>
A list of holes in the polygon.
Implementations
sourceimpl<T: CoordinateType> Polygon<T>
impl<T: CoordinateType> Polygon<T>
sourcepub fn new<I>(i: I) -> Self where
I: Into<Self>,
pub fn new<I>(i: I) -> Self where
I: Into<Self>,
Create a new polygon from a sequence of points.
sourcepub fn new_with_holes<E, I>(exterior: E, holes: Vec<I>) -> Self where
E: Into<SimplePolygon<T>>,
I: Into<SimplePolygon<T>>,
pub fn new_with_holes<E, I>(exterior: E, holes: Vec<I>) -> Self where
E: Into<SimplePolygon<T>>,
I: Into<SimplePolygon<T>>,
Create a new polygon from a hull and a list of holes.
sourcepub fn convex_hull(&self) -> Polygon<T> where
T: Ord,
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
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 where
Area: Num + From<T> + PartialOrd,
pub fn orientation<Area>(&self) -> Orientation where
Area: Num + From<T> + PartialOrd,
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
sourceimpl<T, A> DoubledOrientedArea<A> for Polygon<T> where
T: CoordinateType,
A: Num + From<T>,
impl<T, A> DoubledOrientedArea<A> for Polygon<T> where
T: CoordinateType,
A: Num + From<T>,
sourcefn 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);
sourceimpl<'a, T, P> From<&'a Vec<P, Global>> for Polygon<T> where
T: CoordinateType,
Point<T>: From<&'a P>,
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 Point
s.
sourceimpl<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.
sourcefn from(simple_polygon: &SimplePolygon<T>) -> Self
fn from(simple_polygon: &SimplePolygon<T>) -> Self
Converts to this type from the input type.
sourceimpl<T> From<SimplePolygon<T>> for Polygon<T>
impl<T> From<SimplePolygon<T>> for Polygon<T>
Create a polygon from a simple polygon.
sourcefn from(simple_polygon: SimplePolygon<T>) -> Self
fn from(simple_polygon: SimplePolygon<T>) -> Self
Converts to this type from the input type.
sourceimpl<T, P> From<Vec<P, Global>> for Polygon<T> where
T: Copy,
Point<T>: From<P>,
impl<T, P> From<Vec<P, Global>> for Polygon<T> where
T: Copy,
Point<T>: From<P>,
Create a polygon from a Vec
of values convertible to Point
s.
sourceimpl<T, P> FromIterator<P> for Polygon<T> where
T: Copy,
P: Into<Point<T>>,
impl<T, P> FromIterator<P> for Polygon<T> where
T: Copy,
P: Into<Point<T>>,
Create a polygon from a iterator of values convertible to Point
s.
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = P>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = P>,
Creates a value from an iterator. Read more
sourceimpl<T> MapPointwise<T> for Polygon<T> where
T: CoordinateType,
impl<T> MapPointwise<T> for Polygon<T> where
T: CoordinateType,
sourceimpl<T> TryBoundingBox<T> for Polygon<T> where
T: Copy + PartialOrd,
impl<T> TryBoundingBox<T> for Polygon<T> where
T: Copy + PartialOrd,
sourcefn try_bounding_box(&self) -> Option<Rect<T>>
fn try_bounding_box(&self) -> Option<Rect<T>>
Return the bounding box of this geometry if a bounding box is defined.
sourceimpl<T: CoordinateType + NumCast, Dst: CoordinateType + NumCast> TryCastCoord<T, Dst> for Polygon<T>
impl<T: CoordinateType + NumCast, Dst: CoordinateType + NumCast> TryCastCoord<T, Dst> for Polygon<T>
sourceimpl<T> WindingNumber<T> for Polygon<T> where
T: CoordinateType,
impl<T> WindingNumber<T> for Polygon<T> where
T: CoordinateType,
sourcefn 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.
sourcefn contains_point_non_oriented(&self, point: Point<T>) -> bool
fn contains_point_non_oriented(&self, point: Point<T>) -> bool
Check if point
is inside the polygon, i.e. the polygons winds around the point
a non-zero number of times. Read more
sourcefn contains_point(&self, point: Point<T>) -> bool
fn contains_point(&self, point: Point<T>) -> bool
Check if point
is inside the polygon, i.e. the polygon winds around the point
an odd number of times. Read more
impl<T: PartialEq> Eq for Polygon<T>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<S, T> RotateOrtho<T> for S where
T: Copy + Zero + Sub<T, Output = T>,
S: MapPointwise<T>,
impl<S, T> RotateOrtho<T> for S where
T: Copy + Zero + Sub<T, Output = T>,
S: MapPointwise<T>,
sourcefn rotate_ortho(&self, a: Angle) -> S
fn rotate_ortho(&self, a: Angle) -> S
Rotate the geometrical shape by a multiple of 90 degrees.