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
use fj_math::Point;
use crate::objects::{Cycle, HalfEdge, Surface};
pub struct CycleBuilder {
surface: Surface,
}
impl CycleBuilder {
pub fn new(surface: Surface) -> Self {
Self { surface }
}
pub fn polygon_from_points(
&self,
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 half_edges = Vec::new();
for points in points.windows(2) {
let points = [points[0], points[1]];
half_edges.push(
HalfEdge::build(self.surface).line_segment_from_points(points),
);
}
Cycle::new(self.surface, half_edges)
}
}