11// Take a look at the license at the top of the repository in the LICENSE file.
22
3- use std:: fmt;
3+ use std:: { fmt, ops } ;
44
55use glib:: translate:: * ;
66
@@ -219,49 +219,47 @@ impl Default for Matrix {
219219 }
220220}
221221
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
237229 }
238230}
239231
240- impl std:: ops:: Mul < Matrix > for Matrix {
232+ // Matrix-matrix/-vector multiplication
233+ impl ops:: Mul < Matrix > for Matrix {
241234 type Output = Matrix ;
242235
243236 fn mul ( self , rhs : Matrix ) -> Self :: Output {
244237 ( & self ) . multiply ( & rhs)
245238 }
246239}
240+ impl ops:: MulAssign < Matrix > for Matrix {
241+ fn mul_assign ( & mut self , rhs : Matrix ) {
242+ * self = * self * rhs;
243+ }
244+ }
247245
248- impl std :: ops:: Mul < Vec4 > for Matrix {
246+ impl ops:: Mul < Vec4 > for Matrix {
249247 type Output = Vec4 ;
250248
251249 fn mul ( self , rhs : Vec4 ) -> Self :: Output {
252250 ( & self ) . transform_vec4 ( & rhs)
253251 }
254252}
255253
256- impl std :: ops:: Mul < Vec3 > for Matrix {
254+ impl ops:: Mul < Vec3 > for Matrix {
257255 type Output = Vec3 ;
258-
256+
259257 fn mul ( self , rhs : Vec3 ) -> Self :: Output {
260258 ( & self ) . transform_vec3 ( & rhs)
261259 }
262260}
263261
264- impl std :: ops:: Mul < Point > for Matrix {
262+ impl ops:: Mul < Point > for Matrix {
265263 type Output = Point ;
266264
267265 fn mul ( self , rhs : Point ) -> Self :: Output {
@@ -270,11 +268,29 @@ impl std::ops::Mul<Point> for Matrix {
270268}
271269
272270
273- impl std :: ops:: Mul < Point3D > for Matrix {
271+ impl ops:: Mul < Point3D > for Matrix {
274272 type Output = Point3D ;
275273
276274 fn mul ( self , rhs : Point3D ) -> Self :: Output {
277275 ( & self ) . transform_point3d ( & rhs)
278276 }
279277}
280278
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