pub struct Polygon<T>(pub Vec<T>);Expand description
A closed curve composed of a chain of line segments.
The polygon is represented as a list of points, or vertices, with each pair of consecutive vertices, as well as the first and last vertex, sharing an edge.
Tuple Fields§
§0: Vec<T>Implementations§
Source§impl<T> Polygon<T>
impl<T> Polygon<T>
pub fn new(verts: impl IntoIterator<Item = T>) -> Self
Sourcepub fn edges(&self) -> impl Iterator<Item = Edge<&T>> + '_
pub fn edges(&self) -> impl Iterator<Item = Edge<&T>> + '_
Returns an iterator over the edges of self.
Given a polygon ABC…XYZ, returns the edges AB, BC, …, XY, YZ, ZA.
If self has zero or one vertices, returns an empty iterator.
§Examples
use retrofire_core::geom::{Polygon, Edge};
use retrofire_core::math::{Point2, pt2};
let pts: [Point2; _] = [pt2(0.0, 0.0), pt2(1.0, 1.0), pt2(2.0, 1.0)];
let poly = Polygon::new(pts);
let mut edges = poly.edges();
assert_eq!(edges.next(), Some(Edge(&pts[0], &pts[1])));
assert_eq!(edges.next(), Some(Edge(&pts[1], &pts[2])));
assert_eq!(edges.next(), Some(Edge(&pts[2], &pts[0])));
assert_eq!(edges.next(), None);Trait Implementations§
impl<T: Eq> Eq for Polygon<T>
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
Mutably borrows from an owned value. Read more