@@ -1492,6 +1492,14 @@ impl std::ops::Mul<f32quat> for f32quat {
14921492 }
14931493}
14941494
1495+ impl std:: ops:: Neg for f32quat {
1496+ type Output = f32quat ;
1497+
1498+ fn neg ( self ) -> Self :: Output {
1499+ self . negate ( )
1500+ }
1501+ }
1502+
14951503#[ derive( Debug , Copy , Clone , PartialEq ) ]
14961504#[ allow( non_camel_case_types) ]
14971505#[ repr( transparent) ]
@@ -1528,6 +1536,20 @@ impl f32quat {
15281536 self . 0 . dot ( & other. 0 )
15291537 }
15301538
1539+ #[ inline]
1540+ #[ doc( alias = "simd_negate" ) ]
1541+ pub fn negate ( self ) -> Self {
1542+ #[ cfg( target_arch = "aarch64" ) ]
1543+ {
1544+ Self ( f32x4 ( unsafe { std:: arch:: aarch64:: vnegq_f32 ( self . 0 . 0 ) } ) )
1545+ }
1546+
1547+ #[ cfg( not( target_arch = "aarch64" ) ) ]
1548+ {
1549+ Self ( f32x4:: with_xyzw ( -self . x ( ) , -self . y ( ) , -self . z ( ) , -self . w ( ) ) )
1550+ }
1551+ }
1552+
15311553 #[ inline]
15321554 pub fn with_angle ( angle : f32 , axis : f32x3 ) -> Self {
15331555 let half_angle = angle * 0.5 ;
@@ -1919,6 +1941,14 @@ mod tests {
19191941 assert_eq ! ( a. dot( & b) , 70.0 ) ;
19201942 }
19211943
1944+ #[ test]
1945+ fn f32quat_negate ( ) {
1946+ let q = f32quat ( f32x4:: with_xyzw ( 1.0 , -2.0 , 3.5 , -4.0 ) ) ;
1947+ let expected = f32quat ( f32x4:: with_xyzw ( -1.0 , 2.0 , -3.5 , 4.0 ) ) ;
1948+ assert_eq ! ( q. negate( ) , expected) ;
1949+ assert_eq ! ( -q, expected) ;
1950+ }
1951+
19221952 #[ test]
19231953 fn f32quat_mul_known_result ( ) {
19241954 let qx = f32quat:: with_angle ( std:: f32:: consts:: FRAC_PI_2 , f32x3:: with_xyz ( 1.0 , 0.0 , 0.0 ) ) ;
0 commit comments