From cb96cdb79499724b9c327c8b1b59a28cc352e17e Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Fri, 5 Oct 2018 10:21:38 +0700 Subject: [PATCH] clippy: Prefer unwrap_or_else to unwrap_or. --- nalgebra-glm/src/ext/matrix_projection.rs | 4 ++-- nalgebra-glm/src/ext/quaternion_common.rs | 2 +- nalgebra-glm/src/gtc/matrix_inverse.rs | 6 +++--- nalgebra-glm/src/gtx/quaternion.rs | 2 +- nalgebra-glm/src/matrix.rs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nalgebra-glm/src/ext/matrix_projection.rs b/nalgebra-glm/src/ext/matrix_projection.rs index ec0392c6..50f08371 100644 --- a/nalgebra-glm/src/ext/matrix_projection.rs +++ b/nalgebra-glm/src/ext/matrix_projection.rs @@ -86,7 +86,7 @@ pub fn unproject(win: &TVec3, model: &TMat4, proj: &TMat4, vie /// * `viewport` - Specifies the current viewport. pub fn unproject_no(win: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { 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( _2 * (win.x - viewport.x) / viewport.z - N::one(), _2 * (win.y - viewport.y) / viewport.w - N::one(), @@ -109,7 +109,7 @@ pub fn unproject_no(win: &TVec3, model: &TMat4, proj: &TMat4, /// * `viewport` - Specifies the current viewport. pub fn unproject_zo(win: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { 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( _2 * (win.x - viewport.x) / viewport.z - N::one(), _2 * (win.y - viewport.y) / viewport.w - N::one(), diff --git a/nalgebra-glm/src/ext/quaternion_common.rs b/nalgebra-glm/src/ext/quaternion_common.rs index fec1928e..84af997d 100644 --- a/nalgebra-glm/src/ext/quaternion_common.rs +++ b/nalgebra-glm/src/ext/quaternion_common.rs @@ -9,7 +9,7 @@ pub fn quat_conjugate(q: &Qua) -> Qua { /// The inverse of `q`. pub fn quat_inverse(q: &Qua) -> Qua { - q.try_inverse().unwrap_or(na::zero()) + q.try_inverse().unwrap_or_else(na::zero) } //pub fn quat_isinf(x: &Qua) -> TVec { diff --git a/nalgebra-glm/src/gtc/matrix_inverse.rs b/nalgebra-glm/src/gtc/matrix_inverse.rs index 61861729..0ccfca86 100644 --- a/nalgebra-glm/src/gtc/matrix_inverse.rs +++ b/nalgebra-glm/src/gtc/matrix_inverse.rs @@ -7,11 +7,11 @@ use aliases::TMat; pub fn affine_inverse(m: TMat) -> TMat where DefaultAllocator: Alloc { // 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. pub fn inverse_transpose(m: TMat) -> TMat where DefaultAllocator: Alloc { - m.try_inverse().unwrap_or(TMat::<_, D, D>::zeros()).transpose() -} \ No newline at end of file + m.try_inverse().unwrap_or_else(TMat::<_, D, D>::zeros).transpose() +} diff --git a/nalgebra-glm/src/gtx/quaternion.rs b/nalgebra-glm/src/gtx/quaternion.rs index 1023aa76..a490352d 100644 --- a/nalgebra-glm/src/gtx/quaternion.rs +++ b/nalgebra-glm/src/gtx/quaternion.rs @@ -54,7 +54,7 @@ pub fn quat_rotate_vec(q: &Qua, v: &TVec4) -> TVec4 { /// The rotation required to align `orig` to `dest`. pub fn quat_rotation(orig: &TVec3, dest: &TVec3) -> Qua { - 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. diff --git a/nalgebra-glm/src/matrix.rs b/nalgebra-glm/src/matrix.rs index a247a9bf..b61242c9 100644 --- a/nalgebra-glm/src/matrix.rs +++ b/nalgebra-glm/src/matrix.rs @@ -12,7 +12,7 @@ pub fn determinant(m: &TMat) -> N /// The inverse of the matrix `m`. pub fn inverse(m: &TMat) -> TMat where DefaultAllocator: Alloc { - m.clone().try_inverse().unwrap_or(TMat::::zeros()) + m.clone().try_inverse().unwrap_or_else(TMat::::zeros) } /// Component-wise multiplication of two matrices. @@ -31,4 +31,4 @@ pub fn outer_product(c: &TVec, r: & pub fn transpose(x: &TMat) -> TMat where DefaultAllocator: Alloc { x.transpose() -} \ No newline at end of file +}