@@ -186,6 +186,30 @@ mod test {
186
186
} ;
187
187
}
188
188
189
+ macro_rules! impl_affine_approx_test {
190
+ ( $prim: ident, $type: ident, $from: ident, $mat: ident, $ones: expr) => {
191
+ let ones = $mat:: from( $ones) ;
192
+ let one_eps = ones * $mat:: default_epsilon( ) ;
193
+ let two_eps = one_eps + one_eps;
194
+
195
+ let one_ulp = ones * $prim:: from_bits( $prim:: to_bits( 1.0 ) + 1 ) ;
196
+ let four_ulp = ones * $prim:: from_bits( $prim:: to_bits( 1.0 ) + 16 ) ;
197
+
198
+ approx:: assert_abs_diff_eq!( $type:: $from( ones) , $type:: $from( ones) ) ;
199
+ approx:: assert_abs_diff_eq!( $type:: $from( ones) , $type:: $from( ones + one_eps) ) ;
200
+ approx:: assert_abs_diff_eq!( $type:: $from( ones) , $type:: $from( ones - one_eps) ) ;
201
+
202
+ approx:: assert_abs_diff_ne!( $type:: $from( ones) , $type:: $from( ones + two_eps) ) ;
203
+ approx:: assert_abs_diff_ne!( $type:: $from( ones) , $type:: $from( ones - two_eps) ) ;
204
+
205
+ approx:: assert_relative_eq!( $type:: $from( ones) , $type:: $from( ones) ) ;
206
+ approx:: assert_relative_ne!( $type:: $from( ones) , $type:: $from( ones - ones) ) ;
207
+
208
+ // defaults to 4 ulps and I have no idea how to pass other parameters to this macro :)
209
+ approx:: assert_ulps_eq!( $type:: $from( ones) , $type:: $from( one_ulp) ) ;
210
+ approx:: assert_ulps_ne!( $type:: $from( ones) , $type:: $from( four_ulp) ) ;
211
+ } ;
212
+ }
189
213
#[ test]
190
214
fn test_approx ( ) {
191
215
const ONESF32 : [ f32 ; 16 ] = [ 1.0 ; 16 ] ;
@@ -199,8 +223,20 @@ mod test {
199
223
impl_approx_test ! ( f32 , Mat3 , Mat3 :: from_cols_slice( & ONESF32 ) ) ;
200
224
impl_approx_test ! ( f32 , Mat3A , Mat3A :: from_cols_slice( & ONESF32 ) ) ;
201
225
impl_approx_test ! ( f32 , Mat4 , Mat4 :: from_cols_slice( & ONESF32 ) ) ;
202
- // impl_approx_test!(f32, Affine2, Affine2::from_cols_slice(&ONESF32));
203
- // impl_approx_test!(f32, Affine3A, Affine3A::from_cols_slice(&ONESF32));
226
+ impl_affine_approx_test ! (
227
+ f32 ,
228
+ Affine2 ,
229
+ from_mat3,
230
+ Mat3 ,
231
+ Affine2 :: from_cols_slice( & ONESF32 )
232
+ ) ;
233
+ impl_affine_approx_test ! (
234
+ f32 ,
235
+ Affine3A ,
236
+ from_mat4,
237
+ Mat4 ,
238
+ Affine3A :: from_cols_slice( & ONESF32 )
239
+ ) ;
204
240
205
241
const ONESF64 : [ f64 ; 16 ] = [ 1.0 ; 16 ] ;
206
242
impl_approx_test ! ( f64 , DVec2 ) ;
@@ -210,7 +246,19 @@ mod test {
210
246
impl_approx_test ! ( f64 , DMat2 , DMat2 :: from_cols_slice( & ONESF64 ) ) ;
211
247
impl_approx_test ! ( f64 , DMat3 , DMat3 :: from_cols_slice( & ONESF64 ) ) ;
212
248
impl_approx_test ! ( f64 , DMat4 , DMat4 :: from_cols_slice( & ONESF64 ) ) ;
213
- // impl_approx_test!(f64, DAffine2, DAffine2::from_cols_slice(&ONESF64));
214
- // impl_approx_test!(f64, DAffine3, DAffine3::from_cols_slice(&ONESF64));
249
+ impl_affine_approx_test ! (
250
+ f64 ,
251
+ DAffine2 ,
252
+ from_mat3,
253
+ DMat3 ,
254
+ DAffine2 :: from_cols_slice( & ONESF64 )
255
+ ) ;
256
+ impl_affine_approx_test ! (
257
+ f64 ,
258
+ DAffine3 ,
259
+ from_mat4,
260
+ DMat4 ,
261
+ DAffine3 :: from_cols_slice( & ONESF64 )
262
+ ) ;
215
263
}
216
264
}
0 commit comments