Rename `Unit::unwrap` to `Unit::into_inner` and deprecate `Unit::unwrap`
See #460
This commit is contained in:
parent
0f66403cbb
commit
35d2381a2a
|
@ -15,7 +15,7 @@ use alga::linear::NormedSpace;
|
|||
|
||||
/// A wrapper that ensures the underlying algebraic entity has a unit norm.
|
||||
///
|
||||
/// Use `.as_ref()` or `.unwrap()` to obtain the underlying value by-reference or by-move.
|
||||
/// Use `.as_ref()` or `.into_inner()` to obtain the underlying value by-reference or by-move.
|
||||
#[repr(transparent)]
|
||||
#[derive(Eq, PartialEq, Clone, Hash, Debug, Copy)]
|
||||
pub struct Unit<T> {
|
||||
|
@ -113,6 +113,14 @@ impl<T> Unit<T> {
|
|||
|
||||
/// Retrieves the underlying value.
|
||||
#[inline]
|
||||
pub fn into_inner(self) -> T {
|
||||
self.value
|
||||
}
|
||||
|
||||
/// Retrieves the underlying value.
|
||||
/// Deprecated: use [Unit::into_inner] instead.
|
||||
#[deprecated(note="use `.into_inner()` instead")]
|
||||
#[inline]
|
||||
pub fn unwrap(self) -> T {
|
||||
self.value
|
||||
}
|
||||
|
@ -143,7 +151,7 @@ where T::Field: RelativeEq
|
|||
{
|
||||
#[inline]
|
||||
fn to_superset(&self) -> T {
|
||||
self.clone().unwrap()
|
||||
self.clone().into_inner()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -156,7 +156,7 @@ impl<N: Real> Quaternion<N> {
|
|||
/// let inv_q = q.try_inverse();
|
||||
///
|
||||
/// assert!(inv_q.is_some());
|
||||
/// assert_relative_eq!(inv_q.unwrap() * q, Quaternion::identity());
|
||||
/// assert_relative_eq!(inv_q.into_inner() * q, Quaternion::identity());
|
||||
///
|
||||
/// //Non-invertible case
|
||||
/// let q = Quaternion::new(0.0, 0.0, 0.0, 0.0);
|
||||
|
@ -747,7 +747,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
Unit::new_unchecked(Quaternion::from(
|
||||
Unit::new_unchecked(self.coords)
|
||||
.slerp(&Unit::new_unchecked(other.coords), t)
|
||||
.unwrap(),
|
||||
.into_inner(),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -771,7 +771,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
{
|
||||
Unit::new_unchecked(self.coords)
|
||||
.try_slerp(&Unit::new_unchecked(other.coords), t, epsilon)
|
||||
.map(|q| Unit::new_unchecked(Quaternion::from(q.unwrap())))
|
||||
.map(|q| Unit::new_unchecked(Quaternion::from(q.into_inner())))
|
||||
}
|
||||
|
||||
/// Compute the conjugate of this unit quaternion in-place.
|
||||
|
@ -837,7 +837,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
#[inline]
|
||||
pub fn scaled_axis(&self) -> Vector3<N> {
|
||||
if let Some(axis) = self.axis() {
|
||||
axis.unwrap() * self.angle()
|
||||
axis.into_inner() * self.angle()
|
||||
} else {
|
||||
Vector3::zero()
|
||||
}
|
||||
|
@ -894,7 +894,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
#[inline]
|
||||
pub fn ln(&self) -> Quaternion<N> {
|
||||
if let Some(v) = self.axis() {
|
||||
Quaternion::from_parts(N::zero(), v.unwrap() * self.angle())
|
||||
Quaternion::from_parts(N::zero(), v.into_inner() * self.angle())
|
||||
} else {
|
||||
Quaternion::zero()
|
||||
}
|
||||
|
@ -914,7 +914,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
/// let angle = 1.2;
|
||||
/// let rot = UnitQuaternion::from_axis_angle(&axis, angle);
|
||||
/// let pow = rot.powf(2.0);
|
||||
/// assert_relative_eq!(pow.axis().unwrap(), axis, epsilon = 1.0e-6);
|
||||
/// assert_relative_eq!(pow.axis().into_inner(), axis, epsilon = 1.0e-6);
|
||||
/// assert_eq!(pow.angle(), 2.4);
|
||||
/// ```
|
||||
#[inline]
|
||||
|
@ -1029,7 +1029,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
impl<N: Real + fmt::Display> fmt::Display for UnitQuaternion<N> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let Some(axis) = self.axis() {
|
||||
let axis = axis.unwrap();
|
||||
let axis = axis.into_inner();
|
||||
write!(
|
||||
f,
|
||||
"UnitQuaternion angle: {} − axis: ({}, {}, {})",
|
||||
|
|
|
@ -76,7 +76,7 @@ impl<N: Real> Quaternion<N> {
|
|||
where SB: Storage<N, U3> {
|
||||
let rot = UnitQuaternion::<N>::from_axis_angle(&axis, theta * ::convert(2.0f64));
|
||||
|
||||
rot.unwrap() * scale
|
||||
rot.into_inner() * scale
|
||||
}
|
||||
|
||||
/// The quaternion multiplicative identity.
|
||||
|
@ -176,7 +176,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
/// let vec = Vector3::new(4.0, 5.0, 6.0);
|
||||
/// let q = UnitQuaternion::from_axis_angle(&axis, angle);
|
||||
///
|
||||
/// assert_eq!(q.axis().unwrap(), axis);
|
||||
/// assert_eq!(q.axis().into_inner(), axis);
|
||||
/// assert_eq!(q.angle(), angle);
|
||||
/// assert_relative_eq!(q * pt, Point3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);
|
||||
/// assert_relative_eq!(q * vec, Vector3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);
|
||||
|
@ -244,7 +244,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
/// let rot = Rotation3::from_axis_angle(&axis, angle);
|
||||
/// let q = UnitQuaternion::from_rotation_matrix(&rot);
|
||||
/// assert_relative_eq!(q.to_rotation_matrix(), rot, epsilon = 1.0e-6);
|
||||
/// assert_relative_eq!(q.axis().unwrap(), rot.axis().unwrap(), epsilon = 1.0e-6);
|
||||
/// assert_relative_eq!(q.axis().into_inner(), rot.axis().into_inner(), epsilon = 1.0e-6);
|
||||
/// assert_relative_eq!(q.angle(), rot.angle(), epsilon = 1.0e-6);
|
||||
/// ```
|
||||
#[inline]
|
||||
|
@ -306,7 +306,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
/// # use nalgebra::{Vector3, UnitQuaternion};
|
||||
/// let a = Vector3::new(1.0, 2.0, 3.0);
|
||||
/// let b = Vector3::new(3.0, 1.0, 2.0);
|
||||
/// let q = UnitQuaternion::rotation_between(&a, &b).unwrap();
|
||||
/// let q = UnitQuaternion::rotation_between(&a, &b).into_inner();
|
||||
/// assert_relative_eq!(q * a, b);
|
||||
/// assert_relative_eq!(q.inverse() * b, a);
|
||||
/// ```
|
||||
|
@ -329,8 +329,8 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
/// # use nalgebra::{Vector3, UnitQuaternion};
|
||||
/// let a = Vector3::new(1.0, 2.0, 3.0);
|
||||
/// let b = Vector3::new(3.0, 1.0, 2.0);
|
||||
/// let q2 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.2).unwrap();
|
||||
/// let q5 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.5).unwrap();
|
||||
/// let q2 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.2).into_inner();
|
||||
/// let q5 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.5).into_inner();
|
||||
/// assert_relative_eq!(q2 * q2 * q2 * q2 * q2 * a, b, epsilon = 1.0e-6);
|
||||
/// assert_relative_eq!(q5 * q5 * a, b, epsilon = 1.0e-6);
|
||||
/// ```
|
||||
|
@ -365,7 +365,7 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
/// # use nalgebra::{Unit, Vector3, UnitQuaternion};
|
||||
/// let a = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
|
||||
/// let b = Unit::new_normalize(Vector3::new(3.0, 1.0, 2.0));
|
||||
/// let q = UnitQuaternion::rotation_between(&a, &b).unwrap();
|
||||
/// let q = UnitQuaternion::rotation_between(&a, &b).into_inner();
|
||||
/// assert_relative_eq!(q * a, b);
|
||||
/// assert_relative_eq!(q.inverse() * b, a);
|
||||
/// ```
|
||||
|
@ -391,8 +391,8 @@ impl<N: Real> UnitQuaternion<N> {
|
|||
/// # use nalgebra::{Unit, Vector3, UnitQuaternion};
|
||||
/// let a = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
|
||||
/// let b = Unit::new_normalize(Vector3::new(3.0, 1.0, 2.0));
|
||||
/// let q2 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.2).unwrap();
|
||||
/// let q5 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.5).unwrap();
|
||||
/// let q2 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.2).into_inner();
|
||||
/// let q5 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.5).into_inner();
|
||||
/// assert_relative_eq!(q2 * q2 * q2 * q2 * q2 * a, b, epsilon = 1.0e-6);
|
||||
/// assert_relative_eq!(q5 * q5 * a, b, epsilon = 1.0e-6);
|
||||
/// ```
|
||||
|
@ -701,7 +701,7 @@ mod tests {
|
|||
let mut rng = rand::prng::XorShiftRng::from_seed([0xAB; 16]);
|
||||
for _ in 0..1000 {
|
||||
let x = rng.gen::<UnitQuaternion<f32>>();
|
||||
assert!(relative_eq!(x.unwrap().norm(), 1.0))
|
||||
assert!(relative_eq!(x.into_inner().norm(), 1.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -469,7 +469,7 @@ quaternion_op_impl!(
|
|||
(U4, U1), (U3, U1) for SB: Storage<N, U3> ;
|
||||
self: &'a UnitQuaternion<N>, rhs: Unit<Vector<N, U3, SB>>,
|
||||
Output = Unit<Vector3<N>> => U3, U4;
|
||||
Unit::new_unchecked(self * rhs.unwrap());
|
||||
Unit::new_unchecked(self * rhs.into_inner());
|
||||
'a);
|
||||
|
||||
quaternion_op_impl!(
|
||||
|
@ -485,7 +485,7 @@ quaternion_op_impl!(
|
|||
(U4, U1), (U3, U1) for SB: Storage<N, U3> ;
|
||||
self: UnitQuaternion<N>, rhs: Unit<Vector<N, U3, SB>>,
|
||||
Output = Unit<Vector3<N>> => U3, U4;
|
||||
Unit::new_unchecked(self * rhs.unwrap());
|
||||
Unit::new_unchecked(self * rhs.into_inner());
|
||||
);
|
||||
|
||||
macro_rules! scalar_op_impl(
|
||||
|
|
|
@ -20,7 +20,7 @@ impl<N: Real, D: Dim, S: Storage<N, D>> Reflection<N, D, S> {
|
|||
/// represents a plane that passes through the origin.
|
||||
pub fn new(axis: Unit<Vector<N, D, S>>, bias: N) -> Reflection<N, D, S> {
|
||||
Reflection {
|
||||
axis: axis.unwrap(),
|
||||
axis: axis.into_inner(),
|
||||
bias: bias,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,8 +125,8 @@ md_impl_all!(
|
|||
where DefaultAllocator: Allocator<N, D>
|
||||
where ShapeConstraint: AreMultipliable<D, D, D, U1>;
|
||||
self: Rotation<N, D>, right: Unit<Vector<N, D, S>>, Output = Unit<VectorN<N, D>>;
|
||||
[val val] => Unit::new_unchecked(self.unwrap() * right.unwrap());
|
||||
[ref val] => Unit::new_unchecked(self.matrix() * right.unwrap());
|
||||
[val val] => Unit::new_unchecked(self.unwrap() * right.into_inner());
|
||||
[ref val] => Unit::new_unchecked(self.matrix() * right.into_inner());
|
||||
[val ref] => Unit::new_unchecked(self.unwrap() * right.as_ref());
|
||||
[ref ref] => Unit::new_unchecked(self.matrix() * right.as_ref());
|
||||
);
|
||||
|
|
|
@ -616,7 +616,7 @@ impl<N: Real> Rotation3<N> {
|
|||
#[inline]
|
||||
pub fn scaled_axis(&self) -> Vector3<N> {
|
||||
if let Some(axis) = self.axis() {
|
||||
axis.unwrap() * self.angle()
|
||||
axis.into_inner() * self.angle()
|
||||
} else {
|
||||
Vector::zero()
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ impl<N: Real> Mul<UnitComplex<N>> for UnitComplex<N> {
|
|||
|
||||
#[inline]
|
||||
fn mul(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
|
||||
Unit::new_unchecked(self.unwrap() * rhs.unwrap())
|
||||
Unit::new_unchecked(self.into_inner() * rhs.into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ impl<'a, N: Real> Mul<UnitComplex<N>> for &'a UnitComplex<N> {
|
|||
|
||||
#[inline]
|
||||
fn mul(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
|
||||
Unit::new_unchecked(self.complex() * rhs.unwrap())
|
||||
Unit::new_unchecked(self.complex() * rhs.into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ impl<'b, N: Real> Mul<&'b UnitComplex<N>> for UnitComplex<N> {
|
|||
|
||||
#[inline]
|
||||
fn mul(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
|
||||
Unit::new_unchecked(self.unwrap() * rhs.complex())
|
||||
Unit::new_unchecked(self.into_inner() * rhs.complex())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ impl<N: Real> Div<UnitComplex<N>> for UnitComplex<N> {
|
|||
|
||||
#[inline]
|
||||
fn div(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
|
||||
Unit::new_unchecked(self.unwrap() * rhs.conjugate().unwrap())
|
||||
Unit::new_unchecked(self.into_inner() * rhs.conjugate().into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ impl<'a, N: Real> Div<UnitComplex<N>> for &'a UnitComplex<N> {
|
|||
|
||||
#[inline]
|
||||
fn div(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
|
||||
Unit::new_unchecked(self.complex() * rhs.conjugate().unwrap())
|
||||
Unit::new_unchecked(self.complex() * rhs.conjugate().into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ impl<'b, N: Real> Div<&'b UnitComplex<N>> for UnitComplex<N> {
|
|||
|
||||
#[inline]
|
||||
fn div(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
|
||||
Unit::new_unchecked(self.unwrap() * rhs.conjugate().unwrap())
|
||||
Unit::new_unchecked(self.into_inner() * rhs.conjugate().into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ impl<'a, 'b, N: Real> Div<&'b UnitComplex<N>> for &'a UnitComplex<N> {
|
|||
|
||||
#[inline]
|
||||
fn div(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
|
||||
Unit::new_unchecked(self.complex() * rhs.conjugate().unwrap())
|
||||
Unit::new_unchecked(self.complex() * rhs.conjugate().into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -412,7 +412,7 @@ where
|
|||
rot.rotate_rows(&mut m);
|
||||
|
||||
if compute_q {
|
||||
let c = rot.unwrap();
|
||||
let c = rot.into_inner();
|
||||
// XXX: we have to build the matrix manually because
|
||||
// rot.to_rotation_matrix().unwrap() causes an ICE.
|
||||
q = Some(MatrixN::from_column_slice_generic(
|
||||
|
|
Loading…
Reference in New Issue