1- use crate :: core_types:: { Quat , Vector3 } ;
2- use euclid :: { approxeq :: ApproxEq , default , Transform3D , UnknownUnit , Vector3D } ;
1+ use crate :: core_types:: { IsEqualApprox , Quat , Vector3 } ;
2+ use core :: ops :: Mul ;
33
44/// A 3x3 matrix.
55#[ repr( C ) ]
@@ -96,7 +96,7 @@ impl Basis {
9696 #[ inline]
9797 pub fn from_axis_angle ( axis : & Vector3 , phi : f32 ) -> Self {
9898 assert ! (
99- axis. length( ) . approx_eq ( & 1.0 ) ,
99+ axis. length( ) . is_equal_approx ( 1.0 ) ,
100100 "The axis Vector3 must be normalized."
101101 ) ;
102102
@@ -147,7 +147,7 @@ impl Basis {
147147 ] ;
148148
149149 let det: f32 = x. x * co[ 0 ] + x. y * co[ 1 ] + x. z * co[ 2 ] ;
150- assert ! ( !det. approx_eq ( & 0.0 ) , "Determinant was zero" ) ;
150+ assert ! ( !det. is_equal_approx ( 0.0 ) , "Determinant was zero" ) ;
151151
152152 let s: f32 = 1.0 / det;
153153
@@ -210,7 +210,7 @@ impl Basis {
210210 #[ inline]
211211 pub fn orthonormalize ( & mut self ) {
212212 assert ! (
213- !self . determinant( ) . approx_eq ( & 0.0 ) ,
213+ !self . determinant( ) . is_equal_approx ( 0.0 ) ,
214214 "Determinant should not be zero."
215215 ) ;
216216
@@ -219,11 +219,11 @@ impl Basis {
219219 let mut y = self . y ( ) ;
220220 let mut z = self . z ( ) ;
221221
222- x = x. normalize ( ) ;
222+ x = x. normalized ( ) ;
223223 y = y - x * ( x. dot ( y) ) ;
224- y = y. normalize ( ) ;
224+ y = y. normalized ( ) ;
225225 z = z - x * ( x. dot ( z) ) - y * ( y. dot ( z) ) ;
226- z = z. normalize ( ) ;
226+ z = z. normalized ( ) ;
227227
228228 self . set_x ( x) ;
229229 self . set_y ( y) ;
@@ -241,23 +241,23 @@ impl Basis {
241241
242242 /// Returns `true` if `self` and `other` are approximately equal.
243243 #[ inline]
244- pub fn approx_eq ( & self , other : & Basis ) -> bool {
245- self . elements [ 0 ] . approx_eq ( & other. elements [ 0 ] )
246- && self . elements [ 1 ] . approx_eq ( & other. elements [ 1 ] )
247- && self . elements [ 2 ] . approx_eq ( & other. elements [ 2 ] )
244+ pub fn is_equal_approx ( & self , other : & Basis ) -> bool {
245+ self . elements [ 0 ] . is_equal_approx ( other. elements [ 0 ] )
246+ && self . elements [ 1 ] . is_equal_approx ( other. elements [ 1 ] )
247+ && self . elements [ 2 ] . is_equal_approx ( other. elements [ 2 ] )
248248 }
249249
250250 #[ inline]
251251 fn is_orthogonal ( & self ) -> bool {
252252 let identity = Self :: identity ( ) ;
253253 let m = ( * self ) * self . transposed ( ) ;
254- m. approx_eq ( & identity)
254+ m. is_equal_approx ( & identity)
255255 }
256256
257257 #[ inline]
258258 fn is_rotation ( & self ) -> bool {
259259 let det = self . determinant ( ) ;
260- det. approx_eq ( & 1.0 ) && self . is_orthogonal ( )
260+ det. is_equal_approx ( 1.0 ) && self . is_orthogonal ( )
261261 }
262262
263263 /// Multiplies the matrix from left by the rotation matrix: M -> R.M
@@ -328,9 +328,9 @@ impl Basis {
328328 let k = ( i + 2 ) % 3 ;
329329
330330 let elements_arr: [ [ f32 ; 3 ] ; 3 ] = [
331- matrix. elements [ 0 ] . to_array ( ) ,
332- matrix. elements [ 1 ] . to_array ( ) ,
333- matrix. elements [ 2 ] . to_array ( ) ,
331+ * matrix. elements [ 0 ] . as_ref ( ) ,
332+ * matrix. elements [ 1 ] . as_ref ( ) ,
333+ * matrix. elements [ 2 ] . as_ref ( ) ,
334334 ] ;
335335
336336 let mut s = ( elements_arr[ i] [ i] - elements_arr[ j] [ j] - elements_arr[ k] [ k] + 1.0 ) . sqrt ( ) ;
@@ -343,7 +343,7 @@ impl Basis {
343343 }
344344
345345 let [ a, b, c, r] = temp;
346- Quat :: quaternion ( a, b, c, r)
346+ Quat :: new ( a, b, c, r)
347347 }
348348
349349 /// Returns the scale of the matrix.
@@ -384,17 +384,17 @@ impl Basis {
384384 /// See [`Basis::to_quat`](#method.to_quat) if you need a quaternion instead.
385385 #[ inline]
386386 pub fn to_euler ( & self ) -> Vector3 {
387- let mut euler = Vector3 :: zero ( ) ;
387+ let mut euler = Vector3 :: ZERO ;
388388
389389 let m12 = self . elements [ 1 ] . z ;
390390 if m12 < 1.0 {
391391 if m12 > -1.0 {
392392 // is this a pure X rotation?
393- if self . elements [ 1 ] . x . approx_eq ( & 0.0 )
394- && self . elements [ 0 ] . y . approx_eq ( & 0.0 )
395- && self . elements [ 0 ] . z . approx_eq ( & 0.0 )
396- && self . elements [ 2 ] . x . approx_eq ( & 0.0 )
397- && self . elements [ 0 ] . x . approx_eq ( & 1.0 )
393+ if self . elements [ 1 ] . x . is_equal_approx ( 0.0 )
394+ && self . elements [ 0 ] . y . is_equal_approx ( 0.0 )
395+ && self . elements [ 0 ] . z . is_equal_approx ( 0.0 )
396+ && self . elements [ 2 ] . x . is_equal_approx ( 0.0 )
397+ && self . elements [ 0 ] . x . is_equal_approx ( 1.0 )
398398 {
399399 // return the simplest form (human friendlier in editor and scripts)
400400 euler. x = ( -m12) . atan2 ( self . elements [ 1 ] . y ) ;
@@ -471,6 +471,7 @@ impl Basis {
471471 )
472472 }
473473
474+ /*
474475 /// Creates a `Basis` from the rotation and scaling of the provided transform.
475476 #[inline]
476477 pub fn from_transform(transform: &default::Transform3D<f32>) -> Basis {
@@ -494,6 +495,7 @@ impl Basis {
494495 ],
495496 }
496497 }
498+ */
497499
498500 /// Transposed dot product with the **X Axis** of the matrix.
499501 #[ inline]
@@ -580,6 +582,15 @@ impl core::ops::Mul<Basis> for Basis {
580582 }
581583}
582584
585+ impl Mul < Vector3 > for Basis {
586+ type Output = Vector3 ;
587+
588+ #[ inline]
589+ fn mul ( self , rhs : Self :: Output ) -> Self :: Output {
590+ Self :: Output :: new ( self . tdotx ( rhs) , self . tdoty ( rhs) , self . tdotz ( rhs) )
591+ }
592+ }
593+
583594#[ cfg( test) ]
584595#[ allow( clippy:: unreadable_literal) ]
585596mod tests {
@@ -620,7 +631,7 @@ mod tests {
620631 #[ test]
621632 fn set_is_sane ( ) {
622633 let mut basis = Basis {
623- elements : [ Vector3 :: zero ( ) , Vector3 :: zero ( ) , Vector3 :: zero ( ) ] ,
634+ elements : [ Vector3 :: ZERO , Vector3 :: ZERO , Vector3 :: ZERO ] ,
624635 } ;
625636
626637 basis. set_x ( Vector3 :: new ( 1.0 , 4.0 , 7.0 ) ) ;
@@ -634,7 +645,7 @@ mod tests {
634645
635646 fn test_inputs ( ) -> ( Basis , Basis ) {
636647 let v = Vector3 :: new ( 37.51756 , 20.39467 , 49.96816 ) ;
637- let vn = v. normalize ( ) ;
648+ let vn = v. normalized ( ) ;
638649 let b = Basis :: from_euler ( v) ;
639650 let bn = Basis :: from_euler ( vn) ;
640651 ( b, bn)
@@ -644,14 +655,17 @@ mod tests {
644655 fn determinant ( ) {
645656 let ( b, _bn) = test_inputs ( ) ;
646657
647- assert ! ( b. determinant( ) . approx_eq( & 1.0 ) , "Determinant should be 1.0" ) ;
658+ assert ! (
659+ b. determinant( ) . is_equal_approx( 1.0 ) ,
660+ "Determinant should be 1.0"
661+ ) ;
648662 }
649663
650664 #[ test]
651665 fn euler ( ) {
652666 let ( _b, bn) = test_inputs ( ) ;
653667
654- assert ! ( Vector3 :: new( 0.57079 , 0.310283 , 0.760213 ) . approx_eq ( & bn. to_euler( ) ) ) ;
668+ assert ! ( Vector3 :: new( 0.57079 , 0.310283 , 0.760213 ) . is_equal_approx ( bn. to_euler( ) ) ) ;
655669 }
656670
657671 #[ test]
@@ -663,7 +677,7 @@ mod tests {
663677 Vector3 :: new ( -0.288147 , 0.94041 , 0.180557 ) ,
664678 Vector3 :: new ( -0.95445 , -0.297299 , 0.025257 ) ,
665679 ] ) ;
666- assert ! ( expected. approx_eq ( & b. orthonormalized( ) ) ) ;
680+ assert ! ( expected. is_equal_approx ( & b. orthonormalized( ) ) ) ;
667681 }
668682
669683 #[ test]
@@ -675,40 +689,40 @@ mod tests {
675689 Vector3 :: new ( 0.012407 , -0.040492 , -0.007774 ) ,
676690 Vector3 :: new ( -0.682131 , -0.212475 , 0.018051 ) ,
677691 ] ) ;
678- assert ! ( expected. approx_eq ( & b. scaled( & Vector3 :: new( 0.677813 , -0.043058 , 0.714685 ) ) ) ) ;
692+ assert ! ( expected. is_equal_approx ( & b. scaled( & Vector3 :: new( 0.677813 , -0.043058 , 0.714685 ) ) ) ) ;
679693 }
680694
681695 #[ test]
682696 fn rotated ( ) {
683697 let ( b, _bn) = test_inputs ( ) ;
684698
685- let r = Vector3 :: new ( -50.167156 , 60.67781 , -70.04305 ) . normalize ( ) ;
699+ let r = Vector3 :: new ( -50.167156 , 60.67781 , -70.04305 ) . normalized ( ) ;
686700 let expected = Basis :: from_elements ( [
687701 Vector3 :: new ( -0.676245 , 0.113805 , 0.727833 ) ,
688702 Vector3 :: new ( -0.467094 , 0.697765 , -0.54309 ) ,
689703 Vector3 :: new ( -0.569663 , -0.707229 , -0.418703 ) ,
690704 ] ) ;
691- assert ! ( expected. approx_eq ( & b. rotated( r, 1.0 ) ) ) ;
705+ assert ! ( expected. is_equal_approx ( & b. rotated( r, 1.0 ) ) ) ;
692706 }
693707
694708 #[ test]
695709 fn to_quat ( ) {
696710 let ( b, _bn) = test_inputs ( ) ;
697711
698- assert ! ( Quat :: quaternion ( -0.167156 , 0.677813 , -0.043058 , 0.714685 ) . approx_eq ( & b. to_quat( ) ) ) ;
712+ assert ! ( Quat :: new ( -0.167156 , 0.677813 , -0.043058 , 0.714685 ) . is_equal_approx ( & b. to_quat( ) ) ) ;
699713 }
700714
701715 #[ test]
702716 fn scale ( ) {
703717 let ( b, _bn) = test_inputs ( ) ;
704718
705- assert ! ( Vector3 :: new( 1.0 , 1.0 , 1.0 ) . approx_eq ( & b. to_scale( ) ) ) ;
719+ assert ! ( Vector3 :: new( 1.0 , 1.0 , 1.0 ) . is_equal_approx ( b. to_scale( ) ) ) ;
706720 }
707721
708722 #[ test]
709723 fn approx_eq ( ) {
710724 let ( b, _bn) = test_inputs ( ) ;
711- assert ! ( !b. approx_eq ( & Basis :: from_euler( Vector3 :: new( 37.517 , 20.394 , 49.968 ) ) ) ) ;
725+ assert ! ( !b. is_equal_approx ( & Basis :: from_euler( Vector3 :: new( 37.517 , 20.394 , 49.968 ) ) ) ) ;
712726 }
713727
714728 #[ test]
@@ -719,23 +733,23 @@ mod tests {
719733 Vector3 :: new ( -0.165055 , 0.94041 , -0.297299 ) ,
720734 Vector3 :: new ( 0.98324 , 0.180557 , 0.025257 ) ,
721735 ] ) ;
722- assert ! ( expected. approx_eq ( & b. transposed( ) ) ) ;
736+ assert ! ( expected. is_equal_approx ( & b. transposed( ) ) ) ;
723737 }
724738
725739 #[ test]
726740 fn xform ( ) {
727741 let ( b, _bn) = test_inputs ( ) ;
728742
729743 assert ! ( Vector3 :: new( -0.273471 , 0.478102 , -0.690386 )
730- . approx_eq ( & b. xform( Vector3 :: new( 0.5 , 0.7 , -0.2 ) ) ) ) ;
744+ . is_equal_approx ( b. xform( Vector3 :: new( 0.5 , 0.7 , -0.2 ) ) ) ) ;
731745 }
732746
733747 #[ test]
734748 fn xform_inv ( ) {
735749 let ( b, _bn) = test_inputs ( ) ;
736750
737751 assert ! ( Vector3 :: new( -0.884898 , -0.460316 , 0.071165 )
738- . approx_eq ( & b. xform_inv( Vector3 :: new( 0.077431 , -0.165055 , 0.98324 ) ) ) ) ;
752+ . is_equal_approx ( b. xform_inv( Vector3 :: new( 0.077431 , -0.165055 , 0.98324 ) ) ) ) ;
739753 }
740754
741755 #[ test]
@@ -747,6 +761,6 @@ mod tests {
747761 Vector3 :: new ( -0.165055 , 0.94041 , -0.297299 ) ,
748762 Vector3 :: new ( 0.98324 , 0.180557 , 0.025257 ) ,
749763 ] ) ;
750- assert ! ( expected. approx_eq ( & b. inverted( ) ) ) ;
764+ assert ! ( expected. is_equal_approx ( & b. inverted( ) ) ) ;
751765 }
752766}
0 commit comments