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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use crate::{BezPath, Circle, Line, PathEl, Rect, Vec2};
pub trait Shape: Sized {
type BezPathIter: Iterator<Item = PathEl>;
fn to_bez_path(&self, tolerance: f64) -> Self::BezPathIter;
fn into_bez_path(self, tolerance: f64) -> BezPath {
let vec = if let Some(slice) = self.as_path_slice() {
Vec::from(slice)
} else {
self.to_bez_path(tolerance).collect()
};
BezPath::from_vec(vec)
}
fn area(&self) -> f64;
fn perimeter(&self, accuracy: f64) -> f64;
fn winding(&self, pt: Vec2) -> i32;
fn bounding_box(&self) -> Rect;
fn as_line(&self) -> Option<Line> {
None
}
fn as_rect(&self) -> Option<Rect> {
None
}
fn as_circle(&self) -> Option<Circle> {
None
}
fn as_path_slice(&self) -> Option<&[PathEl]> {
None
}
}
impl<'a, T: Shape> Shape for &'a T {
type BezPathIter = T::BezPathIter;
fn to_bez_path(&self, tolerance: f64) -> Self::BezPathIter {
(*self).to_bez_path(tolerance)
}
fn area(&self) -> f64 {
(*self).area()
}
fn perimeter(&self, accuracy: f64) -> f64 {
(*self).perimeter(accuracy)
}
fn winding(&self, pt: Vec2) -> i32 {
(*self).winding(pt)
}
fn bounding_box(&self) -> Rect {
(*self).bounding_box()
}
fn as_line(&self) -> Option<Line> {
(*self).as_line()
}
fn as_rect(&self) -> Option<Rect> {
(*self).as_rect()
}
fn as_path_slice(&self) -> Option<&[PathEl]> {
(*self).as_path_slice()
}
}