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
48
49
50
51
52
53
54
55
use fj_math::{Point, Segment};
use crate::{local::Local, objects::Cycle};
use super::{curves::approx_curve, edges::approx_edge, Tolerance};
#[derive(Debug, Eq, PartialEq, Hash)]
pub struct CycleApprox {
pub points: Vec<Local<Point<2>>>,
}
impl CycleApprox {
pub fn new(cycle: &Cycle, tolerance: Tolerance) -> Self {
let mut points = Vec::new();
for edge in &cycle.edges {
let mut edge_points = Vec::new();
approx_curve(&edge.curve(), tolerance, &mut edge_points);
approx_edge(edge.vertices, &mut edge_points);
points.extend(edge_points.into_iter().map(|point| {
let local =
edge.curve.local().point_from_curve_coords(point.local());
Local::new(local, point.global())
}));
}
points.dedup_by(|a, b| a.global() == b.global());
Self { points }
}
pub fn segments(&self) -> Vec<Segment<3>> {
let mut segments = Vec::new();
for segment in self.points.windows(2) {
let segment = [segment[0], segment[1]];
segments.push(Segment::from(segment.map(|point| point.global())));
}
segments
}
}