1414// limitations under the License.
1515
1616use std:: iter;
17- use std:: mem;
1817use std:: ops:: * ;
1918
2019use num_traits:: { cast, NumCast } ;
@@ -34,6 +33,7 @@ use num::BaseFloat;
3433use point:: Point3 ;
3534use rotation:: { Basis3 , Rotation , Rotation3 } ;
3635use vector:: Vector3 ;
36+ use quaternion;
3737
3838#[ cfg( feature = "mint" ) ]
3939use mint;
@@ -63,7 +63,7 @@ impl<S> Quaternion<S> {
6363 /// Construct a new quaternion from a scalar and a vector.
6464 #[ inline]
6565 pub const fn from_sv ( s : S , v : Vector3 < S > ) -> Quaternion < S > {
66- Quaternion { s : s , v : v }
66+ Quaternion { v , s }
6767 }
6868}
6969
@@ -541,23 +541,22 @@ impl<S: BaseFloat> Rotation3 for Quaternion<S> {
541541impl < S : BaseFloat > From < Quaternion < S > > for [ S ; 4 ] {
542542 #[ inline]
543543 fn from ( v : Quaternion < S > ) -> Self {
544- match v. into ( ) {
545- ( xi, yj, zk, w) => [ xi, yj, zk, w] ,
546- }
544+ let ( xi, yj, zk, w) = v. into ( ) ;
545+ [ xi, yj, zk, w]
547546 }
548547}
549548
550549impl < S : BaseFloat > AsRef < [ S ; 4 ] > for Quaternion < S > {
551550 #[ inline]
552551 fn as_ref ( & self ) -> & [ S ; 4 ] {
553- unsafe { mem :: transmute ( self ) }
552+ unsafe { & * ( self as * const quaternion :: Quaternion < S > as * const [ S ; 4 ] ) }
554553 }
555554}
556555
557556impl < S : BaseFloat > AsMut < [ S ; 4 ] > for Quaternion < S > {
558557 #[ inline]
559558 fn as_mut ( & mut self ) -> & mut [ S ; 4 ] {
560- unsafe { mem :: transmute ( self ) }
559+ unsafe { & mut * ( self as * mut quaternion :: Quaternion < S > as * mut [ S ; 4 ] ) }
561560 }
562561}
563562
@@ -571,63 +570,61 @@ impl<S: BaseFloat> From<[S; 4]> for Quaternion<S> {
571570impl < ' a , S : BaseFloat > From < & ' a [ S ; 4 ] > for & ' a Quaternion < S > {
572571 #[ inline]
573572 fn from ( v : & ' a [ S ; 4 ] ) -> & ' a Quaternion < S > {
574- unsafe { mem :: transmute ( v ) }
573+ unsafe { & * ( v as * const [ S ; 4 ] as * const quaternion :: Quaternion < S > ) }
575574 }
576575}
577576
578577impl < ' a , S : BaseFloat > From < & ' a mut [ S ; 4 ] > for & ' a mut Quaternion < S > {
579578 #[ inline]
580579 fn from ( v : & ' a mut [ S ; 4 ] ) -> & ' a mut Quaternion < S > {
581- unsafe { mem :: transmute ( v ) }
580+ unsafe { & mut * ( v as * mut [ S ; 4 ] as * mut quaternion :: Quaternion < S > ) }
582581 }
583582}
584583
585584impl < S : BaseFloat > From < Quaternion < S > > for ( S , S , S , S ) {
586585 #[ inline]
587586 fn from ( v : Quaternion < S > ) -> Self {
588- match v {
589- Quaternion {
587+ let Quaternion {
590588 s,
591589 v : Vector3 { x, y, z } ,
592- } => ( x , y , z , s ) ,
593- }
590+ } = v ;
591+ ( x , y , z , s )
594592 }
595593}
596594
597595impl < S : BaseFloat > AsRef < ( S , S , S , S ) > for Quaternion < S > {
598596 #[ inline]
599597 fn as_ref ( & self ) -> & ( S , S , S , S ) {
600- unsafe { mem :: transmute ( self ) }
598+ unsafe { & * ( self as * const quaternion :: Quaternion < S > as * const ( S , S , S , S ) ) }
601599 }
602600}
603601
604602impl < S : BaseFloat > AsMut < ( S , S , S , S ) > for Quaternion < S > {
605603 #[ inline]
606604 fn as_mut ( & mut self ) -> & mut ( S , S , S , S ) {
607- unsafe { mem :: transmute ( self ) }
605+ unsafe { & mut * ( self as * mut quaternion :: Quaternion < S > as * mut ( S , S , S , S ) ) }
608606 }
609607}
610608
611609impl < S : BaseFloat > From < ( S , S , S , S ) > for Quaternion < S > {
612610 #[ inline]
613611 fn from ( v : ( S , S , S , S ) ) -> Quaternion < S > {
614- match v {
615- ( xi, yj, zk, w) => Quaternion :: new ( w, xi, yj, zk) ,
616- }
612+ let ( xi, yj, zk, w) = v;
613+ Quaternion :: new ( w, xi, yj, zk)
617614 }
618615}
619616
620617impl < ' a , S : BaseFloat > From < & ' a ( S , S , S , S ) > for & ' a Quaternion < S > {
621618 #[ inline]
622619 fn from ( v : & ' a ( S , S , S , S ) ) -> & ' a Quaternion < S > {
623- unsafe { mem :: transmute ( v ) }
620+ unsafe { & * ( v as * const ( S , S , S , S ) as * const quaternion :: Quaternion < S > ) }
624621 }
625622}
626623
627624impl < ' a , S : BaseFloat > From < & ' a mut ( S , S , S , S ) > for & ' a mut Quaternion < S > {
628625 #[ inline]
629626 fn from ( v : & ' a mut ( S , S , S , S ) ) -> & ' a mut Quaternion < S > {
630- unsafe { mem :: transmute ( v ) }
627+ unsafe { & mut * ( v as * mut ( S , S , S , S ) as * mut quaternion :: Quaternion < S > ) }
631628 }
632629}
633630
0 commit comments