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
use array_init::array_init;
use std::ops::Index;
use std::ops::Sub;
use super::Point;
use super::Vector;
impl<'a, 'b, T, const N: usize> Sub<&'a Point<T, N>> for &'b Point<T, N>
where
T: Sub<T, Output = T> + Clone,
{
type Output = Vector<T, N>;
fn sub(self: &'b Point<T, N>, other: &'a Point<T, N>) -> Self::Output {
Vector(array_init(|i| {
self.array.index(i).clone() - other.array.index(i).clone()
}))
}
}
impl<T, const N: usize> Sub<Point<T, N>> for Point<T, N>
where
T: Sub<T, Output = T> + Clone,
{
type Output = Vector<T, N>;
fn sub(self: Point<T, N>, other: Point<T, N>) -> Self::Output {
Sub::sub(&self, &other)
}
}