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
use array_init::array_init;
use std::ops::Index;
use std::ops::Sub;

use super::Point;
use super::Vector;

// Compiler bug: https://github.com/rust-lang/rust/issues/39959
// When the bug has been fixed then we can get rid of the 'Clone' requirement.
// point - point = 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(raw_arr_sub(&self.array, &other.array))
    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)
  }
}