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
use graphics::types;
use graphics::math::Scalar;
use Point;
#[derive(Copy, Clone, Debug)]
pub struct Line {
pub start: Point,
pub end: Point,
}
impl From<Line> for types::Line {
fn from(line: Line) -> types::Line {
[line.start.x, line.start.y, line.end.x, line.end.y]
}
}
impl From<types::Line> for Line {
fn from(line: types::Line) -> Line {
Line {
start: (line[0], line[1]).into(),
end: (line[2], line[3]).into()
}
}
}
impl<T: Into<Point>, U: Into<Point>> From<(T, U)> for Line {
fn from((start, end): (T, U)) -> Line {
Line {
start: start.into(),
end: end.into(),
}
}
}
impl From<Line> for (Point, Point) {
fn from(line: Line) -> (Point, Point) {
(line.start, line.end)
}
}
impl From<(Scalar, Scalar, Scalar, Scalar)> for Line {
fn from((ax, ay, bx, by): (Scalar, Scalar, Scalar, Scalar)) -> Line {
Line {
start: (ax, ay).into(),
end: (bx, by).into(),
}
}
}
impl<T: Copy + Into<Point>> From<[T; 2]> for Line {
fn from(line: [T; 2]) -> Line {
Line {
start: line[0].into(),
end: line[1].into(),
}
}
}