Struct libreda_db::layout::prelude::SimplePolygon [−][src]
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
impl<T> SimplePolygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn new(points: Vec<Point<T>, Global>) -> SimplePolygon<T>
[src]
Create a new polygon from a list of points.
The orientation of the points is normalized to counter-clock-wise.
pub fn new_raw(points: Vec<Point<T>, Global>) -> SimplePolygon<T>
[src]
Create a new polygon from a list of points. The points are taken as they are, without reordering or simplification.
pub fn empty() -> SimplePolygon<T>
[src]
Create empty polygon without any vertices.
pub fn len(&self) -> usize
[src]
Get the number of vertices.
pub fn iter(&self) -> Iter<'_, Point<T>>
[src]
Shortcut for self.points.iter()
.
pub fn convex_hull(&self) -> SimplePolygon<T> where
T: Ord,
[src]
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 edges(&self) -> Vec<Edge<T>, Global>
[src]
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))]);
pub fn is_rectilinear(&self) -> bool
[src]
Test if all edges are parallel to the x or y axis.
pub fn lower_left_vertex(&self) -> Point<T>
[src]
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));
pub fn orientation(&self) -> Orientation
[src]
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
impl<T> Clone for SimplePolygon<T> where
T: Clone + CoordinateType,
[src]
T: Clone + CoordinateType,
pub fn clone(&self) -> SimplePolygon<T>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T> Debug for SimplePolygon<T> where
T: Debug + CoordinateType,
[src]
T: Debug + CoordinateType,
impl<T> DoubledOrientedArea<T> for SimplePolygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn area_doubled_oriented(&self) -> T
[src]
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);
impl<T> Eq for SimplePolygon<T> where
T: Eq + CoordinateType,
[src]
T: Eq + CoordinateType,
impl<'_, T> From<&'_ SimplePolygon<T>> for Polygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
Create a polygon from a simple polygon.
pub fn from(simple_polygon: &SimplePolygon<T>) -> Polygon<T>
[src]
impl<I, T, P> From<I> for SimplePolygon<T> where
T: CoordinateType,
I: IntoIterator<Item = P>,
Point<T>: From<P>,
[src]
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 Point
s.
pub fn from(iter: I) -> SimplePolygon<T>
[src]
impl<T> From<SimplePolygon<T>> for Polygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
Create a polygon from a simple polygon.
pub fn from(simple_polygon: SimplePolygon<T>) -> Polygon<T>
[src]
impl<T> From<SimplePolygon<T>> for Geometry<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn from(x: SimplePolygon<T>) -> Geometry<T>
[src]
impl<T, P> FromIterator<P> for SimplePolygon<T> where
T: CoordinateType,
P: Into<Point<T>>,
[src]
T: CoordinateType,
P: Into<Point<T>>,
Create a polygon from a iterator of values convertible to Point
s.
pub fn from_iter<I>(iter: I) -> SimplePolygon<T> where
I: IntoIterator<Item = P>,
[src]
I: IntoIterator<Item = P>,
impl<T> Hash for SimplePolygon<T> where
T: Hash + CoordinateType,
[src]
T: Hash + CoordinateType,
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> MapPointwise<T> for SimplePolygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
impl<T> PartialEq<SimplePolygon<T>> for SimplePolygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn eq(&self, rhs: &SimplePolygon<T>) -> bool
[src]
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.
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T> StructuralEq for SimplePolygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
impl<T> TryBoundingBox<T> for SimplePolygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn try_bounding_box(&self) -> Option<Rect<T>>
[src]
impl<T, Dst> TryCastCoord<T, Dst> for SimplePolygon<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
[src]
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = SimplePolygon<Dst>
Output type of the cast. This is likely the same geometrical type just with other coordinate types. Read more
pub fn try_cast(
&self
) -> Option<<SimplePolygon<T> as TryCastCoord<T, Dst>>::Output>
[src]
&self
) -> Option<<SimplePolygon<T> as TryCastCoord<T, Dst>>::Output>
pub fn cast(&self) -> Self::Output
[src]
impl<T> WindingNumber<T> for SimplePolygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn winding_number(&self, point: Point<T>) -> isize
[src]
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
pub fn contains_point_non_oriented(&self, point: Point<T>) -> bool
[src]
pub fn contains_point(&self, point: Point<T>) -> bool
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for SimplePolygon<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for SimplePolygon<T> where
T: Send,
T: Send,
impl<T> Sync for SimplePolygon<T> where
T: Sync,
T: Sync,
impl<T> Unpin for SimplePolygon<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for SimplePolygon<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<S, T> Mirror<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
[src]
S: MapPointwise<T>,
T: CoordinateType,
pub fn mirror_x(&self) -> S
[src]
Return the geometrical object mirrored at the x
axis.
pub fn mirror_y(&self) -> S
[src]
Return the geometrical object mirrored at the y
axis.
impl<S, T> RotateOrtho<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
[src]
S: MapPointwise<T>,
T: CoordinateType,
pub fn rotate_ortho(&self, a: Angle) -> S
[src]
impl<S, T> Scale<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
[src]
S: MapPointwise<T>,
T: CoordinateType,
impl<T> TextType for T where
T: Clone + Eq + Debug + Hash,
[src]
T: Clone + Eq + Debug + Hash,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<S, T> Translate<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
[src]
S: MapPointwise<T>,
T: CoordinateType,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,