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
use super::*;

impl<T> From<&Self> for Point<T>
where
    T: Clone,
{
    fn from(value: &Self) -> Self {
        Self { x: value.x.clone(), y: value.y.clone() }
    }
}

impl<T> From<(T, T)> for Point<T>
where
    T: Clone,
{
    fn from(p: (T, T)) -> Self {
        Self { x: p.0, y: p.1 }
    }
}

impl<T, V> Add<V> for Point<T>
where
    Point<T>: From<V>,
    T: Add<Output = T>,
{
    type Output = Self;

    fn add(self, rhs: V) -> Self::Output {
        let rhs: Self = rhs.into();
        Point { x: self.x + rhs.x, y: self.y + rhs.y }
    }
}

impl<T, V> Sub<V> for Point<T>
where
    Point<T>: From<V>,
    T: Sub<Output = T>,
{
    type Output = Self;

    fn sub(self, rhs: V) -> Self::Output {
        let rhs: Self = rhs.into();
        Point { x: self.x - rhs.x, y: self.y - rhs.y }
    }
}