1use super::*;
2
3mod _2d;
4mod _3d;
5mod _4d;
6
7pub use _2d::*;
8pub use _3d::*;
9pub use _4d::*;
10
11macro_rules! left_mul_impl {
12 ($name:ident for $($typ:ty),*) => {$(
13 impl Mul<$name<$typ>> for $typ {
14 type Output = $name<$typ>;
15 fn mul(self, rhs: $name<$typ>) -> $name<$typ> {
16 rhs * self
17 }
18 }
19 )*}
20}
21
22macro_rules! vec_impl_ops {
23 ($name:ident : $($f:tt),*) => {
24 impl<T: Add<Output=T>> Add for $name<T> {
25 type Output = Self;
26 fn add(self, rhs: Self) -> Self {
27 Self {
28 $($f: self.$f + rhs.$f,)*
29 }
30 }
31 }
32
33 impl<T: AddAssign> AddAssign for $name<T> {
34 fn add_assign(&mut self, rhs: Self) {
35 $(self.$f += rhs.$f;)*
36 }
37 }
38
39 impl<T: Sub<Output=T>> Sub for $name<T> {
40 type Output = Self;
41 fn sub(self, rhs: Self) -> Self {
42 Self {
43 $($f: self.$f - rhs.$f,)*
44 }
45 }
46 }
47
48 impl<T: SubAssign> SubAssign for $name<T> {
49 fn sub_assign(&mut self, rhs: Self) {
50 $(self.$f -= rhs.$f;)*
51 }
52 }
53
54 impl<T: Neg<Output=T>> Neg for $name<T> {
55 type Output = Self;
56 fn neg(self) -> Self {
57 Self {
58 $($f: -self.$f,)*
59 }
60 }
61 }
62
63 impl<T: Mul<Output=T>> Mul for $name<T> {
64 type Output = Self;
65 fn mul(self, rhs: Self) -> Self {
66 Self {
67 $($f: self.$f * rhs.$f,)*
68 }
69 }
70 }
71
72 impl<T: MulAssign> MulAssign for $name<T> {
73 fn mul_assign(&mut self, rhs: Self) {
74 $(self.$f *= rhs.$f;)*
75 }
76 }
77
78 impl<T: Div<Output=T>> Div for $name<T> {
79 type Output = Self;
80 fn div(self, rhs: Self) -> Self {
81 Self {
82 $($f: self.$f / rhs.$f,)*
83 }
84 }
85 }
86
87 impl<T: DivAssign> DivAssign for $name<T> {
88 fn div_assign(&mut self, rhs: Self) {
89 $(self.$f /= rhs.$f;)*
90 }
91 }
92
93 impl<T: Copy + Mul<Output=T>> Mul<T> for $name<T> {
94 type Output = Self;
95 fn mul(self, rhs: T) -> Self {
96 Self {
97 $($f: self.$f * rhs,)*
98 }
99 }
100 }
101
102 left_mul_impl!($name for f32, f64, i8, i16, i32, i64, u8, u16, u32, u64, isize, usize);
103
104 impl<T: Copy + MulAssign> MulAssign<T> for $name<T> {
105 fn mul_assign(&mut self, rhs: T) {
106 $(self.$f *= rhs;)*
107 }
108 }
109
110 impl<T: Copy + Div<Output=T>> Div<T> for $name<T> {
111 type Output = Self;
112 fn div(self, rhs: T) -> Self {
113 Self {
114 $($f: self.$f / rhs,)*
115 }
116 }
117 }
118
119 impl<T: Copy + DivAssign> DivAssign<T> for $name<T> {
120 fn div_assign(&mut self, rhs: T) {
121 $(self.$f /= rhs;)*
122 }
123 }
124 };
125}
126
127vec_impl_ops!(vec2: 0, 1);
128vec_impl_ops!(vec3: 0, 1, 2);
129vec_impl_ops!(vec4: 0, 1, 2, 3);