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
use kurbo::Vec2;
pub trait RoundFrom<T> {
fn round_from(x: T) -> Self;
}
pub trait RoundInto<T> {
fn round_into(self) -> T;
}
impl<T, U> RoundInto<U> for T
where
U: RoundFrom<T>,
{
fn round_into(self) -> U {
U::round_from(self)
}
}
impl RoundFrom<f64> for f32 {
fn round_from(x: f64) -> f32 {
x as f32
}
}
impl RoundFrom<f32> for f64 {
fn round_from(x: f32) -> f64 {
x as f64
}
}
impl RoundFrom<Vec2> for (f32, f32) {
fn round_from(p: Vec2) -> (f32, f32) {
(p.x as f32, p.y as f32)
}
}
impl RoundFrom<(f32, f32)> for Vec2 {
fn round_from(p: (f32, f32)) -> Vec2 {
Vec2::new(p.0 as f64, p.1 as f64)
}
}
impl RoundFrom<Vec2> for (f64, f64) {
fn round_from(p: Vec2) -> (f64, f64) {
(p.x, p.y)
}
}
impl RoundFrom<(f64, f64)> for Vec2 {
fn round_from(p: (f64, f64)) -> Vec2 {
Vec2::new(p.0, p.1)
}
}
impl<T> RoundFrom<T> for T {
fn round_from(x: T) -> T {
x
}
}