diff --git a/src/base/cg.rs b/src/base/cg.rs index 4029dbc3..d23d5cd3 100644 --- a/src/base/cg.rs +++ b/src/base/cg.rs @@ -294,7 +294,8 @@ impl> SquareMatrix { for i in 0..D::dim() { for j in 0..D::dim() - 1 { - self[(j, i)] += shift[j] * self[(D::dim() - 1, i)]; + let add = shift[j] * self[(D::dim() - 1, i)]; + self[(j, i)] += add; } } } diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 6c1db1d6..7119a8ad 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -1594,6 +1594,19 @@ impl> Unit> { /// Computes the spherical linear interpolation between two unit vectors. + /// + /// # Examples: + /// + /// ``` + /// # use nalgebra::geometry::UnitQuaternion; + /// + /// let q1 = UnitQuaternion::from_euler_angles(std::f32::consts::FRAC_PI_4, 0.0, 0.0); + /// let q2 = UnitQuaternion::from_euler_angles(-std::f32::consts::PI, 0.0, 0.0); + /// + /// let q = q1.slerp(&q2, 1.0 / 3.0); + /// + /// assert_eq!(q.euler_angles(), (std::f32::consts::FRAC_PI_2, 0.0, 0.0)); + /// ``` pub fn slerp>( &self, rhs: &Unit>, diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 2986dc12..40c085f2 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -945,13 +945,7 @@ impl UnitQuaternion { #[inline] pub fn angle(&self) -> N { let w = self.quaternion().scalar().abs(); - - // Handle inaccuracies that make break `.acos`. - if w >= N::one() { - N::zero() - } else { - w.acos() * crate::convert(2.0f64) - } + self.quaternion().imag().norm().atan2(w) * crate::convert(2.0f64) } /// The underlying quaternion.