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
use std::ops::{
  Add,
  Div,
  Mul,
  Sub,
};

use nalgebra::{
  vector,
  Vector2,
};

#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord)]
/// Vector2 struct
pub struct Vect2<T: std::fmt::Debug> {
  pub x: T,
  pub y: T,
}
impl<T: std::fmt::Debug> From<Vect2<T>> for Vector2<T> {
  fn from(vect2: Vect2<T>) -> Vector2<T> { vector![vect2.x, vect2.y] }
}
impl<T: std::fmt::Debug + std::marker::Copy> From<Vector2<T>> for Vect2<T> {
  fn from(vector2: Vector2<T>) -> Self {
    Self {
      x: vector2.data.0[0][0],
      y: vector2.data.0[0][1],
    }
  }
}
impl<T: std::fmt::Debug + Add<Output = T>> Add for Vect2<T> {
  type Output = Vect2<T>;

  fn add(self, rhs: Vect2<T>) -> Self {
    Self {
      x: self.x + rhs.x,
      y: self.y + rhs.y,
    }
  }
}
impl<T: std::fmt::Debug + Sub<Output = T>> Sub for Vect2<T> {
  type Output = Vect2<T>;

  fn sub(self, rhs: Vect2<T>) -> Self {
    Self {
      x: self.x - rhs.x,
      y: self.y - rhs.y,
    }
  }
}
impl<T: std::fmt::Debug + Mul<Output = T>> Mul for Vect2<T> {
  type Output = Vect2<T>;

  fn mul(self, rhs: Vect2<T>) -> Self {
    Self {
      x: self.x * rhs.x,
      y: self.y * rhs.y,
    }
  }
}
impl<T: std::fmt::Debug + Div<Output = T>> Div for Vect2<T> {
  type Output = Vect2<T>;

  fn div(self, rhs: Vect2<T>) -> Self {
    Self {
      x: self.x / rhs.x,
      y: self.y / rhs.y,
    }
  }
}