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
use crate::{polygon, CoordNum, Coordinate, Line, Polygon};
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Triangle<T: CoordNum>(pub Coordinate<T>, pub Coordinate<T>, pub Coordinate<T>);
impl<T: CoordNum> Triangle<T> {
pub fn to_array(&self) -> [Coordinate<T>; 3] {
[self.0, self.1, self.2]
}
pub fn to_lines(&self) -> [Line<T>; 3] {
[
Line::new(self.0, self.1),
Line::new(self.1, self.2),
Line::new(self.2, self.0),
]
}
pub fn to_polygon(self) -> Polygon<T> {
polygon![self.0, self.1, self.2, self.0]
}
}
impl<IC: Into<Coordinate<T>> + Copy, T: CoordNum> From<[IC; 3]> for Triangle<T> {
fn from(array: [IC; 3]) -> Triangle<T> {
Triangle(array[0].into(), array[1].into(), array[2].into())
}
}