1use std::fmt::Display;
2
3use crate::Vector3;
4
5pub struct Vector2<T> {
7 one: T,
8 two: T
9}
10
11impl<T> Vector2<T> {
12 pub fn new(one: T, two: T) -> Self {
13 return Self {
14 one: one,
15 two: two
16 };
17 }
18}
19
20impl<T> Vector2<T> {
21 pub fn get_one(&self) -> &T {
22 return &self.one;
23 }
24
25 pub fn get_one_mut(&mut self) -> &mut T {
26 return &mut self.one;
27 }
28
29 pub fn get_two(&self) -> &T {
30 return &self.two;
31 }
32
33 pub fn get_two_mut(&mut self) -> &mut T {
34 return &mut self.two;
35 }
36}
37
38impl<T: Default> Default for Vector2<T> {
39 fn default() -> Self {
40 return Self {
41 one: T::default(),
42 two: T::default()
43 };
44 }
45}
46
47impl<T: Clone> Clone for Vector2<T> {
48 fn clone(&self) -> Self {
49 return Self {
50 one: self.one.clone(),
51 two: self.two.clone()
52 };
53 }
54}
55
56impl<T: Copy> Copy for Vector2<T> {}
57
58impl<T> Into<(T, T)> for Vector2<T> {
59 fn into(self) -> (T, T) {
60 return (self.one, self.two);
61 }
62}
63
64impl<T> Into<Vector2<T>> for (T, T) {
65 fn into(self) -> Vector2<T> {
66 return Vector2::new(self.0, self.1);
67 }
68}
69
70impl<T: PartialEq> PartialEq for Vector2<T> {
71 fn eq(&self, other: &Self) -> bool {
72 return self.one == other.one && self.two == other.two;
73 }
74
75 fn ne(&self, other: &Self) -> bool {
76 return !self.eq(other);
77 }
78}
79
80impl<T: Default> Into<Vector3<T>> for Vector2<T> {
81 fn into(self) -> Vector3<T> {
82 return Vector3::new(self.one, self.two, T::default());
83 }
84}
85
86impl<T: Display> Display for Vector2<T> {
87 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88 return write!(f, "[one: {}, two: {}", self.one, self.two);
89 }
90}