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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

#[doc(hidden)]
pub(crate) trait AddSubArithmetic<T> {
	type Output;
	fn add_other(self, rhs: T) -> Self::Output;
	fn subtract_other(self, rhs: T) -> Self::Output;
	fn add_assign_other(&mut self, rhs: T);
	fn subtract_assign_other(&mut self, rhs: T);
}

#[doc(hidden)]
pub(crate) trait MulDivScalar {
	type Output;
	fn multiply_scalar(self, rhs: f32) -> Self::Output;
	fn divide_scalar(self, rhs: f32) -> Self::Output;
	fn reciprocal_scalar(self, rhs: f32) -> Self::Output;
	fn multiply_assign_scalar(&mut self, rhs: f32);
	fn divide_assign_scalar(&mut self, rhs: f32);
}

#[doc(hidden)]
macro_rules! use_impl_ops {
	() => {
		use core::ops::{Add, AddAssign, Sub, SubAssign, Mul, MulAssign, Div, DivAssign};
	};
}
pub(crate) use use_impl_ops;

#[doc(hidden)]
macro_rules! impl_add {
	($($t:ty)*) => {
		$(
			impl Add<$t> for $t {
				type Output = $t;
				
				fn add(self, rhs: $t) -> Self::Output {
					self.add_other(rhs)
				}
			}
			impl AddAssign<$t> for $t {
				fn add_assign(&mut self, rhs: $t) {
					self.add_assign_other(rhs);
				}
			}
		)*
	};
	($($t1:ty => $t2:ty: $tout:ty)*) => {
		$(
			impl Add<$t2> for $t1 {
				type Output = $tout;
				fn add(self, rhs: $t2) -> Self::Output {
					self.add_other(rhs)
				}
			}
			impl AddAssign<$t2> for $t1 {
				fn add_assign(&mut self, rhs: $t2) {
					self.add_assign_other(rhs);
				}
			}
		)*
	};
}
pub(crate) use impl_add;

#[doc(hidden)]
macro_rules! impl_sub {
	($($t:ty)*) => {
		$(
			impl Sub<$t> for $t {
				type Output = $t;
				
				fn sub(self, rhs: $t) -> Self::Output {
					self.subtract_other(rhs)
				}
			}
			impl SubAssign<$t> for $t {
				fn sub_assign(&mut self, rhs: $t) {
					self.subtract_assign_other(rhs);
				}
			}
		)*
	};
	($($t1:ty => $t2:ty: $tout:ty)*) => {
		$(
			impl Sub<$t2> for $t1 {
				type Output = $tout;
				fn sub(self, rhs: $t2) -> Self::Output {
					self.subtract_other(rhs)
				}
			}
			impl SubAssign<$t2> for $t1 {
				fn sub_assign(&mut self, rhs: $t2) {
					self.subtract_assign_other(rhs);
				}
			}
		)*
	};
}
pub(crate) use impl_sub;

#[doc(hidden)]
macro_rules! impl_mul {
	($($t:ty)*) => {
		$(
			impl Mul<f32> for $t {
				type Output = $t;
				fn mul(self, rhs: f32) -> Self::Output {
					self.multiply_scalar(rhs)
				}
			}
			impl Mul<i32> for $t {
				type Output = $t;
				fn mul(self, rhs: i32) -> Self::Output {
					self.multiply_scalar(rhs as f32)
				}
			}
			impl Mul<$t> for f32 {
				type Output = $t;
				fn mul(self, rhs: $t) -> Self::Output {
					rhs.multiply_scalar(self)
				}
			}
			impl Mul<$t> for i32 {
				type Output = $t;
				fn mul(self, rhs: $t) -> Self::Output {
					rhs.multiply_scalar(self as f32)
				}
			}
			impl MulAssign<f32> for $t {
				fn mul_assign(&mut self, rhs: f32) {
					self.multiply_assign_scalar(rhs);
				}
			}
			impl MulAssign<i32> for $t {
				fn mul_assign(&mut self, rhs: i32) {
					self.multiply_assign_scalar(rhs as f32);
				}
			}
		)*
	};
}
pub(crate) use impl_mul;

#[doc(hidden)]
macro_rules! impl_div {
	($($t:ty)*) => {
		$(
			impl Div<f32> for $t {
				type Output = $t;
				fn div(self, rhs: f32) -> Self::Output {
					self.divide_scalar(rhs)
				}
			}
			impl Div<i32> for $t {
				type Output = $t;
				fn div(self, rhs: i32) -> Self::Output {
					self.divide_scalar(rhs as f32)
				}
			}
			impl Div<$t> for f32 {
				type Output = $t;
				fn div(self, rhs: $t) -> Self::Output {
					rhs.reciprocal_scalar(self)
				}
			}
			impl Div<$t> for i32 {
				type Output = $t;
				fn div(self, rhs: $t) -> Self::Output {
					rhs.reciprocal_scalar(self as f32)
				}
			}
			impl DivAssign<f32> for $t {
				fn div_assign(&mut self, rhs: f32) {
					self.divide_assign_scalar(rhs);
				}
			}
			impl DivAssign<i32> for $t {
				fn div_assign(&mut self, rhs: i32) {
					self.divide_assign_scalar(rhs as f32);
				}
			}
		)*
	};
}
pub(crate) use impl_div;