From efd14f9e882f206ab5014403419935c729a7e99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Mon, 5 Aug 2013 10:15:11 +0200 Subject: [PATCH] Further coding style fixes. --- src/mat_spec.rs | 156 ++++++++++++++++++++++++------------------------ 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/src/mat_spec.rs b/src/mat_spec.rs index bc74ddff..b446bd5d 100644 --- a/src/mat_spec.rs +++ b/src/mat_spec.rs @@ -6,103 +6,103 @@ use traits::inv::Inv; // some specializations: impl Inv for Mat1 { - #[inline] - fn inverse(&self) -> Option> { - let mut res : Mat1 = self.clone(); + #[inline] + fn inverse(&self) -> Option> { + let mut res : Mat1 = self.clone(); - if res.inplace_inverse() { - Some(res) + if res.inplace_inverse() { + Some(res) + } + else { + None + } } - else { - None - } - } - #[inline] - fn inplace_inverse(&mut self) -> bool { - if self.m11.is_zero() { - false + #[inline] + fn inplace_inverse(&mut self) -> bool { + if self.m11.is_zero() { + false + } + else { + self.m11 = One::one::() / self.m11; + true + } } - else { - self.m11 = One::one::() / self.m11; - true - } - } } impl Inv for Mat2 { - #[inline] - fn inverse(&self) -> Option> { - let mut res : Mat2 = self.clone(); + #[inline] + fn inverse(&self) -> Option> { + let mut res : Mat2 = self.clone(); - if res.inplace_inverse() { - Some(res) + if res.inplace_inverse() { + Some(res) + } + else { + None + } } - else { - None - } - } - #[inline] - fn inplace_inverse(&mut self) -> bool { - let det = self.m11 * self.m22 - self.m21 * self.m12; + #[inline] + fn inplace_inverse(&mut self) -> bool { + let det = self.m11 * self.m22 - self.m21 * self.m12; - if det.is_zero() { - false - } - else { - *self = Mat2::new(self.m22 / det , -self.m12 / det, - -self.m21 / det, self.m11 / det); + if det.is_zero() { + false + } + else { + *self = Mat2::new(self.m22 / det , -self.m12 / det, + -self.m21 / det, self.m11 / det); - true + true + } } - } } impl Inv for Mat3 { - #[inline] - fn inverse(&self) -> Option> { - let mut res = self.clone(); + #[inline] + fn inverse(&self) -> Option> { + let mut res = self.clone(); - if res.inplace_inverse() { - Some(res) + if res.inplace_inverse() { + Some(res) + } + else { + None + } } - else { - None + + #[inline] + fn inplace_inverse(&mut self) -> bool { + let minor_m12_m23 = self.m22 * self.m33 - self.m32 * self.m23; + let minor_m11_m23 = self.m21 * self.m33 - self.m31 * self.m23; + let minor_m11_m22 = self.m21 * self.m32 - self.m31 * self.m22; + + let det = self.m11 * minor_m12_m23 + - self.m12 * minor_m11_m23 + + self.m13 * minor_m11_m22; + + if det.is_zero() { + false + } + else { + *self = Mat3::new( + (minor_m12_m23 / det), + ((self.m13 * self.m32 - self.m33 * self.m12) / det), + ((self.m12 * self.m23 - self.m22 * self.m13) / det), + + (-minor_m11_m23 / det), + ((self.m11 * self.m33 - self.m31 * self.m13) / det), + ((self.m13 * self.m21 - self.m23 * self.m11) / det), + + (minor_m11_m22 / det), + ((self.m12 * self.m31 - self.m32 * self.m11) / det), + ((self.m11 * self.m22 - self.m21 * self.m12) / det) + ); + + true + } } - } - - #[inline] - fn inplace_inverse(&mut self) -> bool { - let minor_m12_m23 = self.m22 * self.m33 - self.m32 * self.m23; - let minor_m11_m23 = self.m21 * self.m33 - self.m31 * self.m23; - let minor_m11_m22 = self.m21 * self.m32 - self.m31 * self.m22; - - let det = self.m11 * minor_m12_m23 - - self.m12 * minor_m11_m23 - + self.m13 * minor_m11_m22; - - if det.is_zero() { - false - } - else { - *self = Mat3::new( - (minor_m12_m23 / det), - ((self.m13 * self.m32 - self.m33 * self.m12) / det), - ((self.m12 * self.m23 - self.m22 * self.m13) / det), - - (-minor_m11_m23 / det), - ((self.m11 * self.m33 - self.m31 * self.m13) / det), - ((self.m13 * self.m21 - self.m23 * self.m11) / det), - - (minor_m11_m22 / det), - ((self.m12 * self.m31 - self.m32 * self.m11) / det), - ((self.m11 * self.m22 - self.m21 * self.m12) / det) - ); - - true - } - } }