From 90e40aaec0dc7cc69ee4b08130df4276ac5d35d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Wed, 16 Oct 2013 21:44:33 +0200 Subject: [PATCH] Make most out-of-place methods static. This is to make people prefer the functional style. Things like `a.dot(b)` dont make sense per se (there is no reason for `a` to have a different status than `b`). Using static methods avoid this. In-place methods are left unchanged. --- src/lib.rs | 2 +- src/na.rs | 36 +++++++++++++++++------------------ src/structs/dmat.rs | 29 ++++++++++++++-------------- src/structs/dvec.rs | 33 +++++++++++++++++--------------- src/structs/iso_macros.rs | 6 +++--- src/structs/mat_macros.rs | 12 ++++++------ src/structs/rot.rs | 10 +++++----- src/structs/rot_macros.rs | 8 ++++---- src/structs/spec/vec.rs | 40 +++++++++++++++++++-------------------- src/structs/spec/vec0.rs | 18 +++++++++--------- src/structs/vec_macros.rs | 32 +++++++++++++++---------------- src/traits/geometry.rs | 16 ++++++++-------- src/traits/operations.rs | 12 ++++++------ src/traits/structure.rs | 2 +- 14 files changed, 130 insertions(+), 126 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 366b977b..4b2d2ac7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,7 +113,7 @@ Feel free to add your project to this list if you happen to use **nalgebra**! #[deny(non_camel_case_types)]; #[deny(non_uppercase_statics)]; #[deny(unnecessary_qualification)]; -#[deny(missing_doc)]; +#[warn(missing_doc)]; #[feature(macro_rules)]; extern mod std; diff --git a/src/na.rs b/src/na.rs index c920825f..a1de5eeb 100644 --- a/src/na.rs +++ b/src/na.rs @@ -300,11 +300,11 @@ pub fn append_rotation_wrt_point, /// Rotates a copy of `m` by `amount` using `m.translation()` as the pivot point. #[inline(always)] -pub fn rotate_wrt_center, - AV, - M: RotationWithTranslation>( - m: &M, - amount: &AV) -> M { +pub fn append_rotation_wrt_center, + AV, + M: RotationWithTranslation>( + m: &M, + amount: &AV) -> M { RotationWithTranslation::append_rotation_wrt_center_cpy(m, amount) } @@ -373,13 +373,13 @@ pub fn inv_transform>(m: &M, v: &V) -> V { /// Computes the dot product of two vectors. #[inline(always)] pub fn dot, N>(a: &V, b: &V) -> N { - a.dot(b) + Dot::dot(a, b) } /// Computes a subtraction followed by a dot product. #[inline(always)] pub fn sub_dot, N>(a: &V, b: &V, c: &V) -> N { - a.sub_dot(b, c) + Dot::sub_dot(a, b, c) } /* @@ -389,13 +389,13 @@ pub fn sub_dot, N>(a: &V, b: &V, c: &V) -> N { /// Computes the L2 norm of a vector. #[inline(always)] pub fn norm, N: Algebraic>(v: &V) -> N { - v.norm() + Norm::norm(v) } /// Computes the squared L2 norm of a vector. #[inline(always)] pub fn sqnorm, N: Algebraic>(v: &V) -> N { - v.sqnorm() + Norm::sqnorm(v) } /// Gets the normalized version of a vector. @@ -411,7 +411,7 @@ pub fn normalize, N: Algebraic>(v: &V) -> V { /// Computes the cross product of two vectors. #[inline(always)] pub fn cross, AV>(a: &LV, b: &LV) -> AV { - a.cross(b) + Cross::cross(a, b) } /* @@ -422,7 +422,7 @@ pub fn cross, AV>(a: &LV, b: &LV) -> AV { /// product. #[inline(always)] pub fn cross_matrix, M>(v: &V) -> M { - v.cross_matrix() + CrossMatrix::cross_matrix(v) } /* @@ -432,7 +432,7 @@ pub fn cross_matrix, M>(v: &V) -> M { /// Converts a matrix or vector to homogoneous coordinates. #[inline(always)] pub fn to_homogeneous, Res>(m: &M) -> Res { - m.to_homogeneous() + ToHomogeneous::to_homogeneous(m) } /* @@ -472,8 +472,8 @@ pub fn sample_sphere(f: &fn(V)) { /// Computes a component-wise absolute value. #[inline(always)] -pub fn absolute, Res>(m: &M) -> Res { - m.absolute() +pub fn abs, Res>(m: &M) -> Res { + Absolute::abs(m) } /* @@ -503,7 +503,7 @@ pub fn transpose(m: &M) -> M { /// Computes the outer product of two vectors. #[inline(always)] pub fn outer, M>(a: &V, b: &V) -> M { - a.outer(b) + Outer::outer(a, b) } /* @@ -513,7 +513,7 @@ pub fn outer, M>(a: &V, b: &V) -> M { /// Computes the covariance of a set of observations. #[inline(always)] pub fn cov, Res>(observations: &M) -> Res { - observations.cov() + Cov::cov(observations) } /* @@ -523,7 +523,7 @@ pub fn cov, Res>(observations: &M) -> Res { /// Computes the mean of a set of observations. #[inline(always)] pub fn mean>(observations: &M) -> N { - observations.mean() + Mean::mean(observations) } // @@ -545,7 +545,7 @@ pub fn canonical_basis(f: &fn(V) -> bool) { /// Computes the basis of the orthonormal subspace of a given vector. #[inline(always)] pub fn orthonormal_subspace_basis(v: &V, f: &fn(V) -> bool) { - v.orthonormal_subspace_basis(f) + Basis::orthonormal_subspace_basis(v, f) } /* diff --git a/src/structs/dmat.rs b/src/structs/dmat.rs index 8286a05a..464a9237 100644 --- a/src/structs/dmat.rs +++ b/src/structs/dmat.rs @@ -65,6 +65,7 @@ impl DMat { self.mij.iter().all(|e| e.is_zero()) } + #[inline] pub fn reset(&mut self) { for mij in self.mij.mut_iter() { *mij = Zero::zero(); @@ -416,14 +417,14 @@ impl Transpose for DMat { } impl + Clone> Mean> for DMat { - fn mean(&self) -> DVec { - let mut res: DVec = DVec::new_zeros(self.ncols); - let normalizer: N = Cast::from(1.0f32 / Cast::from(self.nrows)); + fn mean(m: &DMat) -> DVec { + let mut res: DVec = DVec::new_zeros(m.ncols); + let normalizer: N = Cast::from(1.0f32 / Cast::from(m.nrows)); - for i in range(0u, self.nrows) { - for j in range(0u, self.ncols) { + for i in range(0u, m.nrows) { + for j in range(0u, m.ncols) { unsafe { - let acc = res.at_fast(j) + self.at_fast(i, j) * normalizer; + let acc = res.at_fast(j) + m.at_fast(i, j) * normalizer; res.set_fast(j, acc); } } @@ -435,23 +436,23 @@ impl + Clone> Mean> for DMat { impl + DMatDivRhs> + ToStr > Cov> for DMat { // FIXME: this could be heavily optimized, removing all temporaries by merging loops. - fn cov(&self) -> DMat { - assert!(self.nrows > 1); + fn cov(m: &DMat) -> DMat { + assert!(m.nrows > 1); - let mut centered = unsafe { DMat::new_uninitialized(self.nrows, self.ncols) }; - let mean = self.mean(); + let mut centered = unsafe { DMat::new_uninitialized(m.nrows, m.ncols) }; + let mean = Mean::mean(m); // FIXME: use the rows iterator when available - for i in range(0u, self.nrows) { - for j in range(0u, self.ncols) { + for i in range(0u, m.nrows) { + for j in range(0u, m.ncols) { unsafe { - centered.set_fast(i, j, self.at_fast(i, j) - mean.at_fast(j)); + centered.set_fast(i, j, m.at_fast(i, j) - mean.at_fast(j)); } } } // FIXME: return a triangular matrix? - let fnormalizer: f32 = Cast::from(self.nrows() - 1); + let fnormalizer: f32 = Cast::from(m.nrows() - 1); let normalizer: N = Cast::from(fnormalizer); // FIXME: this will do 2 allocations for temporaries! (Transpose::transpose_cpy(¢ered) * centered) / normalizer diff --git a/src/structs/dvec.rs b/src/structs/dvec.rs index 08302f31..2da09dba 100644 --- a/src/structs/dvec.rs +++ b/src/structs/dvec.rs @@ -92,6 +92,7 @@ impl DVec { *self.at.unsafe_mut_ref(i) = val } + /// Gets a reference to of this vector datas. #[inline] pub fn as_vec<'r>(&'r self) -> &'r [N] { let data: &'r [N] = self.at; @@ -99,6 +100,7 @@ impl DVec { data } + /// Gets a mutable reference to of this vector datas. #[inline] pub fn as_mut_vec<'r>(&'r mut self) -> &'r mut [N] { let data: &'r mut [N] = self.at; @@ -106,6 +108,7 @@ impl DVec { data } + /// Extracts this vector datas. #[inline] pub fn to_vec(self) -> ~[N] { self.at @@ -211,13 +214,13 @@ impl + DVecMulRhs>> DVec let mut elt = basis_element.clone(); - elt = elt - self * basis_element.dot(self); + elt = elt - self * Dot::dot(&basis_element, self); for v in res.iter() { - elt = elt - v * elt.dot(v) + elt = elt - v * Dot::dot(&elt, v) }; - if !elt.sqnorm().approx_eq(&Zero::zero()) { + if !Norm::sqnorm(&elt).approx_eq(&Zero::zero()) { res.push(Norm::normalize_cpy(&elt)); } } @@ -257,24 +260,24 @@ impl> Neg> for DVec { impl Dot for DVec { #[inline] - fn dot(&self, other: &DVec) -> N { - assert!(self.at.len() == other.at.len()); + fn dot(a: &DVec, b: &DVec) -> N { + assert!(a.at.len() == b.at.len()); let mut res: N = Zero::zero(); - for i in range(0u, self.at.len()) { - res = res + unsafe { self.at_fast(i) * other.at_fast(i) }; + for i in range(0u, a.at.len()) { + res = res + unsafe { a.at_fast(i) * b.at_fast(i) }; } res } #[inline] - fn sub_dot(&self, a: &DVec, b: &DVec) -> N { + fn sub_dot(a: &DVec, b: &DVec, c: &DVec) -> N { let mut res: N = Zero::zero(); - for i in range(0u, self.at.len()) { - res = res + unsafe { (self.at_fast(i) - a.at_fast(i)) * b.at_fast(i) }; + for i in range(0u, a.at.len()) { + res = res + unsafe { (a.at_fast(i) - b.at_fast(i)) * c.at_fast(i) }; } res @@ -283,13 +286,13 @@ impl Dot for DVec { impl Norm for DVec { #[inline] - fn sqnorm(&self) -> N { - self.dot(self) + fn sqnorm(v: &DVec) -> N { + Dot::dot(v, v) } #[inline] - fn norm(&self) -> N { - self.sqnorm().sqrt() + fn norm(v: &DVec) -> N { + Norm::sqnorm(v).sqrt() } #[inline] @@ -303,7 +306,7 @@ impl Norm for DVec { #[inline] fn normalize(&mut self) -> N { - let l = self.norm(); + let l = Norm::norm(self); for i in range(0u, self.at.len()) { self.at[i] = self.at[i] / l; diff --git a/src/structs/iso_macros.rs b/src/structs/iso_macros.rs index 16bdf7de..bdf0cb2b 100644 --- a/src/structs/iso_macros.rs +++ b/src/structs/iso_macros.rs @@ -297,13 +297,13 @@ macro_rules! inv_impl( macro_rules! to_homogeneous_impl( ($t: ident, $th: ident) => ( impl ToHomogeneous<$th> for $t { - fn to_homogeneous(&self) -> $th { - let mut res = self.rotation.to_homogeneous(); + fn to_homogeneous(m: &$t) -> $th { + let mut res = ToHomogeneous::to_homogeneous(&m.rotation); // copy the translation let dim = Dim::dim(None::<$th>); - res.set_col(dim - 1, self.translation.to_homogeneous()); + res.set_col(dim - 1, ToHomogeneous::to_homogeneous(&m.translation)); res } diff --git a/src/structs/mat_macros.rs b/src/structs/mat_macros.rs index fbe6659a..9f383a8e 100644 --- a/src/structs/mat_macros.rs +++ b/src/structs/mat_macros.rs @@ -113,8 +113,8 @@ macro_rules! absolute_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( impl Absolute<$t> for $t { #[inline] - fn absolute(&self) -> $t { - $t::new(self.$comp0.abs() $(, self.$compN.abs() )*) + fn abs(m: &$t) -> $t { + $t::new(m.$comp0.abs() $(, m.$compN.abs() )*) } } ) @@ -469,12 +469,12 @@ macro_rules! to_homogeneous_impl( ($t: ident, $t2: ident, $dim: expr, $dim2: expr) => ( impl ToHomogeneous<$t2> for $t { #[inline] - fn to_homogeneous(&self) -> $t2 { + fn to_homogeneous(m: &$t) -> $t2 { let mut res: $t2 = One::one(); for i in range(0u, $dim) { for j in range(0u, $dim) { - res.set((i, j), self.at((i, j))) + res.set((i, j), m.at((i, j))) } } @@ -510,12 +510,12 @@ macro_rules! outer_impl( ($t: ident, $m: ident) => ( impl + Zero + Clone> Outer<$m> for $t { #[inline] - fn outer(&self, other: &$t) -> $m { + fn outer(a: &$t, b: &$t) -> $m { let mut res: $m = Zero::zero(); for i in range(0u, Dim::dim(None::<$t>)) { for j in range(0u, Dim::dim(None::<$t>)) { - res.set((i, j), self.at(i) * other.at(j)) + res.set((i, j), a.at(i) * b.at(j)) } } diff --git a/src/structs/rot.rs b/src/structs/rot.rs index 0eca0c63..116f97a0 100644 --- a/src/structs/rot.rs +++ b/src/structs/rot.rs @@ -106,7 +106,7 @@ impl Rot3 { /// * `axisangle` - A vector representing the rotation. Its magnitude is the amount of rotation /// in radian. Its direction is the axis of rotation. pub fn new(axisangle: Vec3) -> Rot3 { - if axisangle.sqnorm().is_zero() { + if Norm::sqnorm(&axisangle).is_zero() { One::one() } else { @@ -152,8 +152,8 @@ impl Rot3 { /// with `at`. Non-colinearity is not checked. pub fn look_at(&mut self, at: &Vec3, up: &Vec3) { let xaxis = Norm::normalize_cpy(at); - let zaxis = Norm::normalize_cpy(&up.cross(&xaxis)); - let yaxis = zaxis.cross(&xaxis); + let zaxis = Norm::normalize_cpy(&Cross::cross(up, &xaxis)); + let yaxis = Cross::cross(&zaxis, &xaxis); self.submat = Mat3::new( xaxis.x.clone(), yaxis.x.clone(), zaxis.x.clone(), @@ -170,8 +170,8 @@ impl Rot3 { /// with `at`. Non-colinearity is not checked. pub fn look_at_z(&mut self, at: &Vec3, up: &Vec3) { let zaxis = Norm::normalize_cpy(at); - let xaxis = Norm::normalize_cpy(&up.cross(&zaxis)); - let yaxis = zaxis.cross(&xaxis); + let xaxis = Norm::normalize_cpy(&Cross::cross(up, &zaxis)); + let yaxis = Cross::cross(&zaxis, &xaxis); self.submat = Mat3::new( xaxis.x.clone(), yaxis.x.clone(), zaxis.x.clone(), diff --git a/src/structs/rot_macros.rs b/src/structs/rot_macros.rs index d5c19367..03353be2 100644 --- a/src/structs/rot_macros.rs +++ b/src/structs/rot_macros.rs @@ -190,8 +190,8 @@ macro_rules! to_homogeneous_impl( ($t: ident, $tm: ident) => ( impl ToHomogeneous<$tm> for $t { #[inline] - fn to_homogeneous(&self) -> $tm { - self.submat.to_homogeneous() + fn to_homogeneous(m: &$t) -> $tm { + ToHomogeneous::to_homogeneous(&m.submat) } } ) @@ -223,8 +223,8 @@ macro_rules! absolute_impl( ($t: ident, $tm: ident) => ( impl Absolute<$tm> for $t { #[inline] - fn absolute(&self) -> $tm { - self.submat.absolute() + fn abs(m: &$t) -> $tm { + Absolute::abs(&m.submat) } } ) diff --git a/src/structs/spec/vec.rs b/src/structs/spec/vec.rs index 34c2f7e9..ab660f5e 100644 --- a/src/structs/spec/vec.rs +++ b/src/structs/spec/vec.rs @@ -6,37 +6,37 @@ use structs::mat::Mat3; impl + Sub> Cross> for Vec2 { #[inline] - fn cross(&self, other : &Vec2) -> Vec1 { - Vec1::new(self.x * other.y - self.y * other.x) + fn cross(a: &Vec2, b: &Vec2) -> Vec1 { + Vec1::new(a.x * b.y - a.y * b.x) } } // FIXME: instead of returning a Vec2, define a Mat2x1 matrix? impl + Clone> CrossMatrix> for Vec2 { #[inline] - fn cross_matrix(&self) -> Vec2 { - Vec2::new(-self.y, self.x.clone()) + fn cross_matrix(v: &Vec2) -> Vec2 { + Vec2::new(-v.y, v.x.clone()) } } impl + Sub> Cross> for Vec3 { #[inline] - fn cross(&self, other : &Vec3) -> Vec3 { + fn cross(a: &Vec3, b: &Vec3) -> Vec3 { Vec3::new( - self.y * other.z - self.z * other.y, - self.z * other.x - self.x * other.z, - self.x * other.y - self.y * other.x + a.y * b.z - a.z * b.y, + a.z * b.x - a.x * b.z, + a.x * b.y - a.y * b.x ) } } impl + Zero + Clone> CrossMatrix> for Vec3 { #[inline] - fn cross_matrix(&self) -> Mat3 { + fn cross_matrix(v: &Vec3) -> Mat3 { Mat3::new( - Zero::zero() , -self.z, self.y.clone(), - self.z.clone(), Zero::zero(), -self.x, - -self.y , self.x.clone(), Zero::zero() + Zero::zero(), -v.z , v.y.clone(), + v.z.clone() , Zero::zero(), -v.x, + -v.y , v.x.clone() , Zero::zero() ) } } @@ -75,7 +75,7 @@ impl Basis for Vec1 { } #[inline(always)] - fn orthonormal_subspace_basis(&self, _: &fn(Vec1) -> bool ) { } + fn orthonormal_subspace_basis(_: &Vec1, _: &fn(Vec1) -> bool ) { } } impl> Basis for Vec2 { @@ -86,8 +86,8 @@ impl> Basis for Vec2 { } #[inline] - fn orthonormal_subspace_basis(&self, f: &fn(Vec2) -> bool) { - f(Vec2::new(-self.y, self.x.clone())); + fn orthonormal_subspace_basis(n: &Vec2, f: &fn(Vec2) -> bool) { + f(Vec2::new(-n.y, n.x.clone())); } } @@ -100,16 +100,16 @@ impl Basis for Vec3 { } #[inline(always)] - fn orthonormal_subspace_basis(&self, f: &fn(Vec3) -> bool) { + fn orthonormal_subspace_basis(n: &Vec3, f: &fn(Vec3) -> bool) { let a = - if self.x.clone().abs() > self.y.clone().abs() { - Norm::normalize_cpy(&Vec3::new(self.z.clone(), Zero::zero(), -self.x)) + if n.x.clone().abs() > n.y.clone().abs() { + Norm::normalize_cpy(&Vec3::new(n.z.clone(), Zero::zero(), -n.x)) } else { - Norm::normalize_cpy(&Vec3::new(Zero::zero(), -self.z, self.y.clone())) + Norm::normalize_cpy(&Vec3::new(Zero::zero(), -n.z, n.y.clone())) }; - if !f(a.cross(self)) { return }; + if !f(Cross::cross(&a, n)) { return }; f(a); } } diff --git a/src/structs/spec/vec0.rs b/src/structs/spec/vec0.rs index d8f65d3d..f4c928a0 100644 --- a/src/structs/spec/vec0.rs +++ b/src/structs/spec/vec0.rs @@ -66,7 +66,7 @@ impl Basis for vec::Vec0 { fn canonical_basis(_: &fn(vec::Vec0) -> bool) { } #[inline(always)] - fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0) -> bool) { } + fn orthonormal_subspace_basis(_: &vec::Vec0, _: &fn(vec::Vec0) -> bool) { } } impl Add> for vec::Vec0 { @@ -92,12 +92,12 @@ impl> Neg> for vec::Vec0 { impl Dot for vec::Vec0 { #[inline] - fn dot(&self, _: &vec::Vec0) -> N { + fn dot(_: &vec::Vec0, _: &vec::Vec0) -> N { Zero::zero() } #[inline] - fn sub_dot(&self, _: &vec::Vec0, _: &vec::Vec0) -> N { + fn sub_dot(_: &vec::Vec0, _: &vec::Vec0, _: &vec::Vec0) -> N { Zero::zero() } } @@ -154,18 +154,18 @@ impl + Neg> Translation> for vec::Vec0 { impl Norm for vec::Vec0 { #[inline] - fn sqnorm(&self) -> N { - self.dot(self) + fn sqnorm(_: &vec::Vec0) -> N { + Zero::zero() } #[inline] - fn norm(&self) -> N { - self.sqnorm().sqrt() + fn norm(_: &vec::Vec0) -> N { + Zero::zero() } #[inline] - fn normalize_cpy(v: &vec::Vec0) -> vec::Vec0 { - v.clone() + fn normalize_cpy(_: &vec::Vec0) -> vec::Vec0 { + Zero::zero() } #[inline] diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index 5bb3e5f7..4021e7d8 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -228,7 +228,7 @@ macro_rules! basis_impl( } #[inline] - fn orthonormal_subspace_basis(&self, f: &fn($t) -> bool) { + fn orthonormal_subspace_basis(n: &$t, f: &fn($t) -> bool) { // compute the basis of the orthogonal subspace using Gram-Schmidt // orthogonalization algorithm let mut basis: ~[$t] = ~[]; @@ -246,13 +246,13 @@ macro_rules! basis_impl( let mut elt = basis_element.clone(); - elt = elt - *self * basis_element.dot(self); + elt = elt - *n * Dot::dot(&basis_element, n); for v in basis.iter() { - elt = elt - v * elt.dot(v) + elt = elt - v * Dot::dot(&elt, v) }; - if !elt.sqnorm().approx_eq(&Zero::zero()) { + if !Norm::sqnorm(&elt).approx_eq(&Zero::zero()) { let new_element = Norm::normalize_cpy(&elt); if !f(new_element.clone()) { return }; @@ -324,13 +324,13 @@ macro_rules! dot_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( impl Dot for $t { #[inline] - fn dot(&self, other: &$t) -> N { - self.$comp0 * other.$comp0 $(+ self.$compN * other.$compN )* + fn dot(a: &$t, b: &$t) -> N { + a.$comp0 * b.$comp0 $(+ a.$compN * b.$compN )* } #[inline] - fn sub_dot(&self, a: &$t, b: &$t) -> N { - (self.$comp0 - a.$comp0) * b.$comp0 $(+ (self.$compN - a.$compN) * b.$compN )* + fn sub_dot(a: &$t, b: &$t, c: &$t) -> N { + (a.$comp0 - b.$comp0) * c.$comp0 $(+ (a.$compN - b.$compN) * c.$compN )* } } ) @@ -425,13 +425,13 @@ macro_rules! norm_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( impl Norm for $t { #[inline] - fn sqnorm(&self) -> N { - self.dot(self) + fn sqnorm(v: &$t) -> N { + Dot::dot(v, v) } #[inline] - fn norm(&self) -> N { - self.sqnorm().sqrt() + fn norm(v: &$t) -> N { + Norm::sqnorm(v).sqrt() } #[inline] @@ -445,7 +445,7 @@ macro_rules! norm_impl( #[inline] fn normalize(&mut self) -> N { - let l = self.norm(); + let l = Norm::norm(self); self.$comp0 = self.$comp0 / l; $(self.$compN = self.$compN / l;)* @@ -545,11 +545,11 @@ macro_rules! bounded_impl( macro_rules! to_homogeneous_impl( ($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => ( impl ToHomogeneous<$t2> for $t { - fn to_homogeneous(&self) -> $t2 { + fn to_homogeneous(v: &$t) -> $t2 { let mut res: $t2 = One::one(); - res.$comp0 = self.$comp0.clone(); - $( res.$compN = self.$compN.clone(); )* + res.$comp0 = v.$comp0.clone(); + $( res.$compN = v.$compN.clone(); )* res } diff --git a/src/traits/geometry.rs b/src/traits/geometry.rs index 7f9f396c..eae6433f 100644 --- a/src/traits/geometry.rs +++ b/src/traits/geometry.rs @@ -201,7 +201,7 @@ pub trait Transform { pub trait Dot { /// Computes the dot (inner) product of two vectors. #[inline] - fn dot(&self, &Self) -> N; + fn dot(&Self, &Self) -> N; /** * Short-cut to compute the projection of a point on a vector, but without @@ -214,22 +214,22 @@ pub trait Dot { * */ #[inline] - fn sub_dot(&self, b: &Self, c: &Self) -> N; + fn sub_dot(a: &Self, b: &Self, c: &Self) -> N; } /// Traits of objects having an euclidian norm. pub trait Norm { /// Computes the norm of `self`. #[inline] - fn norm(&self) -> N { - self.sqnorm().sqrt() + fn norm(v: &Self) -> N { + Norm::sqnorm(v).sqrt() } /// Computes the squared norm of `self`. /// /// This is usually faster than computing the norm itself. #[inline] - fn sqnorm(&self) -> N; + fn sqnorm(&Self) -> N; /// Gets the normalized version of a copy of `v`. #[inline] @@ -245,7 +245,7 @@ pub trait Norm { */ pub trait Cross { /// Computes the cross product between two elements (usually vectors). - fn cross(&self, other: &Self) -> V; + fn cross(&Self, other: &Self) -> V; } /** @@ -254,13 +254,13 @@ pub trait Cross { pub trait CrossMatrix { /// The matrix associated to any cross product with this vector. I.e. `v.cross(anything)` = /// `v.cross_matrix().rmul(anything)`. - fn cross_matrix(&self) -> M; + fn cross_matrix(&Self) -> M; } /// Traits of objects which can be put in homogeneous coordinates form. pub trait ToHomogeneous { /// Gets the homogeneous coordinates form of this object. - fn to_homogeneous(&self) -> U; + fn to_homogeneous(&Self) -> U; } /// Traits of objects which can be build from an homogeneous coordinate form. diff --git a/src/traits/operations.rs b/src/traits/operations.rs index 6b981f71..1593ee2b 100644 --- a/src/traits/operations.rs +++ b/src/traits/operations.rs @@ -6,7 +6,7 @@ pub trait Absolute { /// Computes some absolute value of this object. /// Typically, this will make all component of a matrix or vector positive. - fn absolute(&self) -> A; + fn abs(&Self) -> A; } /// Trait of objects having an inverse. Typically used to implement matrix inverse. @@ -30,7 +30,7 @@ pub trait Transpose { /// Traits of objects having an outer product. pub trait Outer { /// Computes the outer product: `self * other` - fn outer(&self, other: &Self) -> M; + fn outer(a: &Self, b: &Self) -> M; } /// Trait for computing the covariance of a set of data. @@ -39,14 +39,14 @@ pub trait Cov { /// /// * For matrices, observations are stored in its rows. /// * For vectors, observations are stored in its components (thus are 1-dimensional). - fn cov(&self) -> M; + fn cov(&Self) -> M; /// Computes the covariance of the obsevations stored by `self`: /// /// * For matrices, observations are stored in its rows. /// * For vectors, observations are stored in its components (thus are 1-dimensional). - fn cov_to(&self, out: &mut M) { - *out = self.cov() + fn cov_to(m: &Self, out: &mut M) { + *out = Cov::cov(m) } } @@ -56,7 +56,7 @@ pub trait Mean { /// /// * For matrices, observations are stored in its rows. /// * For vectors, observations are stored in its components (thus are 1-dimensional). - fn mean(&self) -> N; + fn mean(&Self) -> N; } // /// Cholesky decomposition. diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 87bae128..116f3b9d 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -60,7 +60,7 @@ pub trait Basis { fn canonical_basis(&fn(Self) -> bool); /// Iterates through a basis of the subspace orthogonal to `self`. - fn orthonormal_subspace_basis(&self, &fn(Self) -> bool); + fn orthonormal_subspace_basis(&Self, &fn(Self) -> bool); } /// Trait to access rows of a matrix or a vector.