1
1
// Take a look at the license at the top of the repository in the LICENSE file.
2
2
3
- use std:: fmt;
3
+ use std:: { fmt, ops } ;
4
4
5
5
use glib:: translate:: * ;
6
6
@@ -219,49 +219,47 @@ impl Default for Matrix {
219
219
}
220
220
}
221
221
222
- #[ cfg( test) ]
223
- mod tests {
224
- use super :: Matrix ;
225
- #[ test]
226
- fn test_matrix_values ( ) {
227
- let matrix = Matrix :: new_identity ( ) ;
228
- assert_eq ! (
229
- matrix. values( ) ,
230
- & [
231
- [ 1.0 , 0.0 , 0.0 , 0.0 ] ,
232
- [ 0.0 , 1.0 , 0.0 , 0.0 ] ,
233
- [ 0.0 , 0.0 , 1.0 , 0.0 ] ,
234
- [ 0.0 , 0.0 , 0.0 , 1.0 ]
235
- ] ,
236
- ) ;
222
+ // Scalar multiplication
223
+ impl ops:: Mul < Matrix > for f32 {
224
+ type Output = Matrix ;
225
+
226
+ fn mul ( self , mut rhs : Matrix ) -> Self :: Output {
227
+ rhs. scale ( self , self , self ) ;
228
+ rhs
237
229
}
238
230
}
239
231
240
- impl std:: ops:: Mul < Matrix > for Matrix {
232
+ // Matrix-matrix/-vector multiplication
233
+ impl ops:: Mul < Matrix > for Matrix {
241
234
type Output = Matrix ;
242
235
243
236
fn mul ( self , rhs : Matrix ) -> Self :: Output {
244
237
( & self ) . multiply ( & rhs)
245
238
}
246
239
}
240
+ impl ops:: MulAssign < Matrix > for Matrix {
241
+ fn mul_assign ( & mut self , rhs : Matrix ) {
242
+ * self = * self * rhs;
243
+ }
244
+ }
247
245
248
- impl std :: ops:: Mul < Vec4 > for Matrix {
246
+ impl ops:: Mul < Vec4 > for Matrix {
249
247
type Output = Vec4 ;
250
248
251
249
fn mul ( self , rhs : Vec4 ) -> Self :: Output {
252
250
( & self ) . transform_vec4 ( & rhs)
253
251
}
254
252
}
255
253
256
- impl std :: ops:: Mul < Vec3 > for Matrix {
254
+ impl ops:: Mul < Vec3 > for Matrix {
257
255
type Output = Vec3 ;
258
-
256
+
259
257
fn mul ( self , rhs : Vec3 ) -> Self :: Output {
260
258
( & self ) . transform_vec3 ( & rhs)
261
259
}
262
260
}
263
261
264
- impl std :: ops:: Mul < Point > for Matrix {
262
+ impl ops:: Mul < Point > for Matrix {
265
263
type Output = Point ;
266
264
267
265
fn mul ( self , rhs : Point ) -> Self :: Output {
@@ -270,11 +268,29 @@ impl std::ops::Mul<Point> for Matrix {
270
268
}
271
269
272
270
273
- impl std :: ops:: Mul < Point3D > for Matrix {
271
+ impl ops:: Mul < Point3D > for Matrix {
274
272
type Output = Point3D ;
275
273
276
274
fn mul ( self , rhs : Point3D ) -> Self :: Output {
277
275
( & self ) . transform_point3d ( & rhs)
278
276
}
279
277
}
280
278
279
+
280
+ #[ cfg( test) ]
281
+ mod tests {
282
+ use super :: Matrix ;
283
+ #[ test]
284
+ fn test_matrix_values ( ) {
285
+ let matrix = Matrix :: new_identity ( ) ;
286
+ assert_eq ! (
287
+ matrix. values( ) ,
288
+ & [
289
+ [ 1.0 , 0.0 , 0.0 , 0.0 ] ,
290
+ [ 0.0 , 1.0 , 0.0 , 0.0 ] ,
291
+ [ 0.0 , 0.0 , 1.0 , 0.0 ] ,
292
+ [ 0.0 , 0.0 , 0.0 , 1.0 ]
293
+ ] ,
294
+ ) ;
295
+ }
296
+ }
0 commit comments