clippy: Prefer unwrap_or_else to unwrap_or.

This commit is contained in:
Bruce Mitchener 2018-10-05 10:21:38 +07:00 committed by Sébastien Crozet
parent 71011c080e
commit cb96cdb794
5 changed files with 9 additions and 9 deletions

View File

@ -86,7 +86,7 @@ pub fn unproject<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, vie
/// * `viewport` - Specifies the current viewport. /// * `viewport` - Specifies the current viewport.
pub fn unproject_no<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> { pub fn unproject_no<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
let _2: N = na::convert(2.0); let _2: N = na::convert(2.0);
let transform = (proj * model).try_inverse().unwrap_or(TMat4::zeros()); let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
let pt = TVec4::new( let pt = TVec4::new(
_2 * (win.x - viewport.x) / viewport.z - N::one(), _2 * (win.x - viewport.x) / viewport.z - N::one(),
_2 * (win.y - viewport.y) / viewport.w - N::one(), _2 * (win.y - viewport.y) / viewport.w - N::one(),
@ -109,7 +109,7 @@ pub fn unproject_no<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>,
/// * `viewport` - Specifies the current viewport. /// * `viewport` - Specifies the current viewport.
pub fn unproject_zo<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> { pub fn unproject_zo<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
let _2: N = na::convert(2.0); let _2: N = na::convert(2.0);
let transform = (proj * model).try_inverse().unwrap_or(TMat4::zeros()); let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
let pt = TVec4::new( let pt = TVec4::new(
_2 * (win.x - viewport.x) / viewport.z - N::one(), _2 * (win.x - viewport.x) / viewport.z - N::one(),
_2 * (win.y - viewport.y) / viewport.w - N::one(), _2 * (win.y - viewport.y) / viewport.w - N::one(),

View File

@ -9,7 +9,7 @@ pub fn quat_conjugate<N: Real>(q: &Qua<N>) -> Qua<N> {
/// The inverse of `q`. /// The inverse of `q`.
pub fn quat_inverse<N: Real>(q: &Qua<N>) -> Qua<N> { pub fn quat_inverse<N: Real>(q: &Qua<N>) -> Qua<N> {
q.try_inverse().unwrap_or(na::zero()) q.try_inverse().unwrap_or_else(na::zero)
} }
//pub fn quat_isinf<N: Real>(x: &Qua<N>) -> TVec<bool, U4> { //pub fn quat_isinf<N: Real>(x: &Qua<N>) -> TVec<bool, U4> {

View File

@ -7,11 +7,11 @@ use aliases::TMat;
pub fn affine_inverse<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D> pub fn affine_inverse<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
where DefaultAllocator: Alloc<N, D, D> { where DefaultAllocator: Alloc<N, D, D> {
// FIXME: this should be optimized. // FIXME: this should be optimized.
m.try_inverse().unwrap_or(TMat::<_, D, D>::zeros()) m.try_inverse().unwrap_or_else(TMat::<_, D, D>::zeros)
} }
/// Compute the transpose of the inverse of a matrix. /// Compute the transpose of the inverse of a matrix.
pub fn inverse_transpose<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D> pub fn inverse_transpose<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
where DefaultAllocator: Alloc<N, D, D> { where DefaultAllocator: Alloc<N, D, D> {
m.try_inverse().unwrap_or(TMat::<_, D, D>::zeros()).transpose() m.try_inverse().unwrap_or_else(TMat::<_, D, D>::zeros).transpose()
} }

View File

@ -54,7 +54,7 @@ pub fn quat_rotate_vec<N: Real>(q: &Qua<N>, v: &TVec4<N>) -> TVec4<N> {
/// The rotation required to align `orig` to `dest`. /// The rotation required to align `orig` to `dest`.
pub fn quat_rotation<N: Real>(orig: &TVec3<N>, dest: &TVec3<N>) -> Qua<N> { pub fn quat_rotation<N: Real>(orig: &TVec3<N>, dest: &TVec3<N>) -> Qua<N> {
UnitQuaternion::rotation_between(orig, dest).unwrap_or(UnitQuaternion::identity()).unwrap() UnitQuaternion::rotation_between(orig, dest).unwrap_or_else(UnitQuaternion::identity).unwrap()
} }
/// The spherical linear interpolation between two quaternions. /// The spherical linear interpolation between two quaternions.

View File

@ -12,7 +12,7 @@ pub fn determinant<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> N
/// The inverse of the matrix `m`. /// The inverse of the matrix `m`.
pub fn inverse<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> TMat<N, D, D> pub fn inverse<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> TMat<N, D, D>
where DefaultAllocator: Alloc<N, D, D> { where DefaultAllocator: Alloc<N, D, D> {
m.clone().try_inverse().unwrap_or(TMat::<N, D, D>::zeros()) m.clone().try_inverse().unwrap_or_else(TMat::<N, D, D>::zeros)
} }
/// Component-wise multiplication of two matrices. /// Component-wise multiplication of two matrices.