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
56
57
58
59
60
61
62
63
64
65
66
67
68
use super::add::*;
use super::sub::*;
use super::chain_add::*;
use super::intersect::*;
use super::super::path::*;
use super::super::super::super::geo::*;
#[derive(Clone, Debug)]
pub enum PathCombine<P: BezierPath>
where P::Point : Coordinate+Coordinate2D {
Path(Vec<P>),
RemoveInteriorPoints(Vec<P>),
Add(Vec<PathCombine<P>>),
Subtract(Vec<PathCombine<P>>),
Intersect(Vec<PathCombine<P>>)
}
pub fn path_combine<P: BezierPathFactory>(operation: PathCombine<P>, accuracy: f64) -> Vec<P>
where P::Point: Coordinate+Coordinate2D {
match operation {
PathCombine::Path(result) => result,
PathCombine::RemoveInteriorPoints(path) => path_remove_interior_points(&path, accuracy),
PathCombine::Add(paths) => path_add_chain(&paths.into_iter().map(|path| path_combine(path, accuracy)).collect(), accuracy),
PathCombine::Subtract(paths) => {
let mut path_iter = paths.into_iter();
let result = path_iter.next().unwrap_or_else(|| PathCombine::Path(vec![]));
let mut result = path_combine(result, accuracy);
while let Some(to_subtract) = path_iter.next() {
let to_subtract = path_combine(to_subtract, accuracy);
result = path_sub(&result, &to_subtract, accuracy);
}
result
}
PathCombine::Intersect(paths) => {
let mut path_iter = paths.into_iter();
let result = path_iter.next().unwrap_or_else(|| PathCombine::Path(vec![]));
let mut result = path_combine(result, accuracy);
while let Some(to_intersect) = path_iter.next() {
let to_intersect = path_combine(to_intersect, accuracy);
result = path_intersect(&result, &to_intersect, accuracy);
}
result
}
}
}