1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use fj_math::Point;
use super::{Edge, Surface};
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Cycle {
pub edges: Vec<Edge>,
}
impl Cycle {
pub fn polygon_from_points(
surface: &Surface,
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Cycle {
let mut points: Vec<_> = points.into_iter().map(Into::into).collect();
if let Some(point) = points.first().cloned() {
points.push(point);
}
let mut edges = Vec::new();
for points in points.windows(2) {
let points = [points[0], points[1]];
edges.push(Edge::line_segment_from_points(surface, points));
}
Cycle { edges }
}
pub fn edges(&self) -> impl Iterator<Item = Edge> + '_ {
self.edges.iter().cloned()
}
}