| 96 } |
96 } |
| 97 } |
97 } |
| 98 } |
98 } |
| 99 } |
99 } |
| 100 |
100 |
| 101 macro_rules! impl_scalarop { |
101 // macro_rules! impl_scalarop { |
| 102 (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => { |
102 // (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => { |
| 103 impl_scalarop!(@doit: $field, |
103 // impl_scalarop!(@doit: $field, |
| |
104 // $trait, $fn; |
| |
105 // maybe_lifetime!($refl, &'l Pair<$a,$b>), |
| |
106 // (maybe_lifetime!($refl, &'l $a), |
| |
107 // maybe_lifetime!($refl, &'l $b)); |
| |
108 // $refl); |
| |
109 // }; |
| |
110 // (@doit: $field : ty, |
| |
111 // $trait:ident, $fn:ident; |
| |
112 // $self:ty, ($aself:ty, $bself:ty); |
| |
113 // $refl:ident) => { |
| |
114 // // Scalar as Rhs |
| |
115 // impl<'l> $trait<$field> |
| |
116 // for $self |
| |
117 // where $aself: $trait<$field>, |
| |
118 // $bself: $trait<$field> { |
| |
119 // type Output = Pair<<$aself as $trait<$field>>::Output, |
| |
120 // <$bself as $trait<$field>>::Output>; |
| |
121 // #[inline] |
| |
122 // fn $fn(self, a : $field) -> Self::Output { |
| |
123 // Pair(maybe_ref!($refl, self.0).$fn(a), |
| |
124 // maybe_ref!($refl, self.1).$fn(a)) |
| |
125 // } |
| |
126 // } |
| |
127 // } |
| |
128 // } |
| |
129 // |
| |
130 |
| |
131 macro_rules! impl_scalarop_gen { |
| |
132 ($field : ty, $trait : ident, $fn : ident, $refl:ident) => { |
| |
133 impl_scalarop_gen!(@doit: $field, |
| 104 $trait, $fn; |
134 $trait, $fn; |
| 105 maybe_lifetime!($refl, &'l Pair<$a,$b>), |
135 maybe_lifetime!($refl, &'l Pair<A,B>), |
| 106 (maybe_lifetime!($refl, &'l $a), |
136 (maybe_lifetime!($refl, &'l A), |
| 107 maybe_lifetime!($refl, &'l $b)); |
137 maybe_lifetime!($refl, &'l B)); |
| 108 $refl); |
138 $refl); |
| 109 }; |
139 }; |
| 110 (@doit: $field : ty, |
140 (@doit: $field : ty, |
| 111 $trait:ident, $fn:ident; |
141 $trait:ident, $fn:ident; |
| 112 $self:ty, ($aself:ty, $bself:ty); |
142 $self:ty, ($aself:ty, $bself:ty); |
| 113 $refl:ident) => { |
143 $refl:ident) => { |
| 114 // Scalar as Rhs |
144 // Scalar as Rhs |
| 115 impl<'l> $trait<$field> |
145 impl<'l, A, B> $trait<$field> |
| 116 for $self |
146 for $self |
| 117 where $aself: $trait<$field>, |
147 where $aself: $trait<$field>, |
| 118 $bself: $trait<$field> { |
148 $bself: $trait<$field> { |
| 119 type Output = Pair<<$aself as $trait<$field>>::Output, |
149 type Output = Pair<<$aself as $trait<$field>>::Output, |
| 120 <$bself as $trait<$field>>::Output>; |
150 <$bself as $trait<$field>>::Output>; |
| 202 (($a:ty, $b:ty), $field:ty) => { |
232 (($a:ty, $b:ty), $field:ty) => { |
| 203 impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add); |
233 impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add); |
| 204 impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub); |
234 impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub); |
| 205 impl_pair_vectorspace_ops!(@assign, ($a, $b), AddAssign, add_assign); |
235 impl_pair_vectorspace_ops!(@assign, ($a, $b), AddAssign, add_assign); |
| 206 impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign); |
236 impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign); |
| 207 impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul); |
237 // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul); |
| 208 impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div); |
238 // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div); |
| 209 // Compiler overflow |
239 // Compiler overflow |
| 210 // $( |
240 // $( |
| 211 // impl_pair_vectorspace_ops!(@scalar_lhs, ($a, $b), $field, $impl_scalarlhs_op, Mul, mul); |
241 // impl_pair_vectorspace_ops!(@scalar_lhs, ($a, $b), $field, $impl_scalarlhs_op, Mul, mul); |
| 212 // )* |
242 // )* |
| 213 impl_pair_vectorspace_ops!(@scalar_assign, ($a, $b), $field, MulAssign, mul_assign); |
243 impl_pair_vectorspace_ops!(@scalar_assign, ($a, $b), $field, MulAssign, mul_assign); |
| 238 (@unary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => { |
268 (@unary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => { |
| 239 impl_unaryop!(($a, $b), $trait, $fn, ref); |
269 impl_unaryop!(($a, $b), $trait, $fn, ref); |
| 240 impl_unaryop!(($a, $b), $trait, $fn, noref); |
270 impl_unaryop!(($a, $b), $trait, $fn, noref); |
| 241 }; |
271 }; |
| 242 } |
272 } |
| |
273 |
| |
274 // TODO: add what we can here. |
| |
275 #[macro_export] |
| |
276 macro_rules! impl_pair_vectorspace_ops_gen { |
| |
277 ($field:ty) => { |
| |
278 // impl_pair_vectorspace_ops_gen!(@binary, Add, add); |
| |
279 // impl_pair_vectorspace_ops_gen!(@binary, Sub, sub); |
| |
280 // impl_pair_vectorspace_ops_gen!(@assign, AddAssign, add_assign); |
| |
281 // impl_pair_vectorspace_ops_gen!(@assign, SubAssign, sub_assign); |
| |
282 impl_pair_vectorspace_ops_gen!(@scalar, $field, Mul, mul); |
| |
283 impl_pair_vectorspace_ops_gen!(@scalar, $field, Div, div); |
| |
284 // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, MulAssign, mul_assign); |
| |
285 // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, DivAssign, div_assign); |
| |
286 // impl_pair_vectorspace_ops_gen!(@unary, Neg, neg); |
| |
287 }; |
| |
288 // (@binary, $trait : ident, $fn : ident) => { |
| |
289 // impl_binop_gen!(($a, $b), $trait, $fn, ref, ref); |
| |
290 // impl_binop_gen!(($a, $b), $trait, $fn, ref, noref); |
| |
291 // impl_binop_gen!(($a, $b), $trait, $fn, noref, ref); |
| |
292 // impl_binop_gen!(($a, $b), $trait, $fn, noref, noref); |
| |
293 // }; |
| |
294 // (@assign, $trait : ident, $fn :ident) => { |
| |
295 // impl_assignop_gen!(($a, $b), $trait, $fn, ref); |
| |
296 // impl_assignop_gen!(($a, $b), $trait, $fn, noref); |
| |
297 // }; |
| |
298 (@scalar, $field : ty, $trait : ident, $fn :ident) => { |
| |
299 impl_scalarop_gen!($field, $trait, $fn, ref); |
| |
300 impl_scalarop_gen!($field, $trait, $fn, noref); |
| |
301 }; |
| |
302 // (@scalar_lhs, $field : ty, $trait : ident, $fn : ident) => { |
| |
303 // impl_scalarlhs_op_gen!(($a, $b), $field, $trait, $fn, ref); |
| |
304 // impl_scalarlhs_op_gen!(($a, $b), $field, $trait, $fn, noref); |
| |
305 // }; |
| |
306 // (@scalar_assign, $field : ty, $trait : ident, $fn : ident) => { |
| |
307 // impl_scalar_assignop_gen!(($a, $b), $field, $trait, $fn); |
| |
308 // }; |
| |
309 // (@unary, $trait : ident, $fn : ident) => { |
| |
310 // impl_unaryop_gen!(($a, $b), $trait, $fn, ref); |
| |
311 // impl_unaryop_gen!(($a, $b), $trait, $fn, noref); |
| |
312 // }; |
| |
313 } |
| |
314 |
| |
315 impl_pair_vectorspace_ops_gen!(f32); |
| |
316 impl_pair_vectorspace_ops_gen!(f64); |
| 243 |
317 |
| 244 impl_pair_vectorspace_ops!((f32, f32), f32); |
318 impl_pair_vectorspace_ops!((f32, f32), f32); |
| 245 impl_pair_vectorspace_ops!((f64, f64), f64); |
319 impl_pair_vectorspace_ops!((f64, f64), f64); |
| 246 |
320 |
| 247 type PairOutput<F, A, B> = Pair<<A as Euclidean<F>>::Output, <B as Euclidean<F>>::Output>; |
321 type PairOutput<F, A, B> = Pair<<A as Euclidean<F>>::Output, <B as Euclidean<F>>::Output>; |