1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use super::*;

impl<T> Polygon3D<T> {
    pub fn new<I>(points: I) -> Self
    where
        I: IntoIterator<Item = Point3D<T>>,
    {
        Self { vertex: points.into_iter().collect() }
    }
    pub fn edges(&self) -> impl Iterator<Item = Line3D<&T>> {
        debug_assert!(self.vertex.len() >= 2, "Polygon must have at least two points");
        self.vertex
            .iter()
            .cycle()
            .take(self.vertex.len() + 1)
            .tuple_windows()
            .map(|(a, b)| Line3D { start: a.as_ref(), end: b.as_ref() })
    }
}