From 35ab64b086c23a97474d9d59cf0f0ea742bc64d9 Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Sun, 9 Dec 2018 15:16:06 -0500 Subject: [PATCH] Rename `Rotation::unwrap` to `Rotation::into_inner` and deprecate `Rotation::unwrap` See #460 --- src/geometry/quaternion_conversion.rs | 2 +- src/geometry/rotation.rs | 12 +++++++++-- src/geometry/rotation_conversion.rs | 4 ++-- src/geometry/rotation_ops.rs | 30 +++++++++++++-------------- src/geometry/unit_complex.rs | 2 +- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/geometry/quaternion_conversion.rs b/src/geometry/quaternion_conversion.rs index 0f8a0d68..c2d70726 100644 --- a/src/geometry/quaternion_conversion.rs +++ b/src/geometry/quaternion_conversion.rs @@ -228,7 +228,7 @@ impl From> for Matrix4 { impl From> for Matrix3 { #[inline] fn from(q: UnitQuaternion) -> Matrix3 { - q.to_rotation_matrix().unwrap() + q.to_rotation_matrix().into_inner() } } diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 5a4e4723..299ddb1e 100644 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -154,7 +154,7 @@ where DefaultAllocator: Allocator /// # use nalgebra::{Rotation2, Rotation3, Vector3, Matrix2, Matrix3}; /// # use std::f32; /// let rot = Rotation3::from_axis_angle(&Vector3::z_axis(), f32::consts::FRAC_PI_6); - /// let mat = rot.unwrap(); + /// let mat = rot.into_inner(); /// let expected = Matrix3::new(0.8660254, -0.5, 0.0, /// 0.5, 0.8660254, 0.0, /// 0.0, 0.0, 1.0); @@ -162,12 +162,20 @@ where DefaultAllocator: Allocator /// /// /// let rot = Rotation2::new(f32::consts::FRAC_PI_6); - /// let mat = rot.unwrap(); + /// let mat = rot.into_inner(); /// let expected = Matrix2::new(0.8660254, -0.5, /// 0.5, 0.8660254); /// assert_eq!(mat, expected); /// ``` #[inline] + pub fn into_inner(self) -> MatrixN { + self.matrix + } + + /// Unwraps the underlying matrix. + /// Deprecated: Use [Rotation::into_inner] instead. + #[deprecated(note="use `.into_inner()` instead")] + #[inline] pub fn unwrap(self) -> MatrixN { self.matrix } diff --git a/src/geometry/rotation_conversion.rs b/src/geometry/rotation_conversion.rs index ecabb71f..3b574041 100644 --- a/src/geometry/rotation_conversion.rs +++ b/src/geometry/rotation_conversion.rs @@ -227,7 +227,7 @@ impl From> for Matrix3 { impl From> for Matrix2 { #[inline] fn from(q: Rotation2) -> Matrix2 { - q.unwrap() + q.into_inner() } } @@ -241,6 +241,6 @@ impl From> for Matrix4 { impl From> for Matrix3 { #[inline] fn from(q: Rotation3) -> Matrix3 { - q.unwrap() + q.into_inner() } } diff --git a/src/geometry/rotation_ops.rs b/src/geometry/rotation_ops.rs index e7cccd4b..fae70921 100644 --- a/src/geometry/rotation_ops.rs +++ b/src/geometry/rotation_ops.rs @@ -46,9 +46,9 @@ md_impl_all!( Mul, mul; (D, D), (D, D) for D: DimName; self: Rotation, right: Rotation, Output = Rotation; - [val val] => Rotation::from_matrix_unchecked(self.unwrap() * right.unwrap()); - [ref val] => Rotation::from_matrix_unchecked(self.matrix() * right.unwrap()); - [val ref] => Rotation::from_matrix_unchecked(self.unwrap() * right.matrix()); + [val val] => Rotation::from_matrix_unchecked(self.into_inner() * right.into_inner()); + [ref val] => Rotation::from_matrix_unchecked(self.matrix() * right.into_inner()); + [val ref] => Rotation::from_matrix_unchecked(self.into_inner() * right.matrix()); [ref ref] => Rotation::from_matrix_unchecked(self.matrix() * right.matrix()); ); @@ -71,9 +71,9 @@ md_impl_all!( where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Rotation, right: Matrix, Output = MatrixMN; - [val val] => self.unwrap() * right; + [val val] => self.into_inner() * right; [ref val] => self.matrix() * right; - [val ref] => self.unwrap() * right; + [val ref] => self.into_inner() * right; [ref ref] => self.matrix() * right; ); @@ -84,8 +84,8 @@ md_impl_all!( where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Matrix, right: Rotation, Output = MatrixMN; - [val val] => self * right.unwrap(); - [ref val] => self * right.unwrap(); + [val val] => self * right.into_inner(); + [ref val] => self * right.into_inner(); [val ref] => self * right.matrix(); [ref ref] => self * right.matrix(); ); @@ -112,9 +112,9 @@ md_impl_all!( where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Rotation, right: Point, Output = Point; - [val val] => self.unwrap() * right; + [val val] => self.into_inner() * right; [ref val] => self.matrix() * right; - [val ref] => self.unwrap() * right; + [val ref] => self.into_inner() * right; [ref ref] => self.matrix() * right; ); @@ -125,9 +125,9 @@ md_impl_all!( where DefaultAllocator: Allocator where ShapeConstraint: AreMultipliable; self: Rotation, right: Unit>, Output = Unit>; - [val val] => Unit::new_unchecked(self.unwrap() * right.into_inner()); + [val val] => Unit::new_unchecked(self.into_inner() * right.into_inner()); [ref val] => Unit::new_unchecked(self.matrix() * right.into_inner()); - [val ref] => Unit::new_unchecked(self.unwrap() * right.as_ref()); + [val ref] => Unit::new_unchecked(self.into_inner() * right.as_ref()); [ref ref] => Unit::new_unchecked(self.matrix() * right.as_ref()); ); @@ -138,7 +138,7 @@ md_assign_impl_all!( MulAssign, mul_assign; (D, D), (D, D) for D: DimName; self: Rotation, right: Rotation; - [val] => self.matrix_mut_unchecked().mul_assign(right.unwrap()); + [val] => self.matrix_mut_unchecked().mul_assign(right.into_inner()); [ref] => self.matrix_mut_unchecked().mul_assign(right.matrix()); ); @@ -146,7 +146,7 @@ md_assign_impl_all!( DivAssign, div_assign; (D, D), (D, D) for D: DimName; self: Rotation, right: Rotation; - [val] => self.matrix_mut_unchecked().mul_assign(right.inverse().unwrap()); + [val] => self.matrix_mut_unchecked().mul_assign(right.inverse().into_inner()); [ref] => self.matrix_mut_unchecked().mul_assign(right.inverse().matrix()); ); @@ -160,7 +160,7 @@ md_assign_impl_all!( MulAssign, mul_assign; (R1, C1), (C1, C1) for R1: DimName, C1: DimName; self: MatrixMN, right: Rotation; - [val] => self.mul_assign(right.unwrap()); + [val] => self.mul_assign(right.into_inner()); [ref] => self.mul_assign(right.matrix()); ); @@ -168,6 +168,6 @@ md_assign_impl_all!( DivAssign, div_assign; (R1, C1), (C1, C1) for R1: DimName, C1: DimName; self: MatrixMN, right: Rotation; - [val] => self.mul_assign(right.inverse().unwrap()); + [val] => self.mul_assign(right.inverse().into_inner()); [ref] => self.mul_assign(right.inverse().matrix()); ); diff --git a/src/geometry/unit_complex.rs b/src/geometry/unit_complex.rs index 32bb0238..14b31d2f 100644 --- a/src/geometry/unit_complex.rs +++ b/src/geometry/unit_complex.rs @@ -320,6 +320,6 @@ impl From> for Matrix3 { impl From> for Matrix2 { #[inline] fn from(q: UnitComplex) -> Matrix2 { - q.to_rotation_matrix().unwrap() + q.to_rotation_matrix().into_inner() } }