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