diff --git a/src/mat_macros.rs b/src/mat_macros.rs index 79a25be9..8fdd13ea 100644 --- a/src/mat_macros.rs +++ b/src/mat_macros.rs @@ -28,6 +28,7 @@ macro_rules! mat_cast_impl( macro_rules! iterable_impl( ($t: ident, $dim: expr) => ( impl Iterable for $t { + #[inline] fn iter<'l>(&'l self) -> VecIterator<'l, N> { unsafe { cast::transmute::<&'l $t, &'l [N, ..$dim * $dim]>(self).iter() @@ -40,6 +41,7 @@ macro_rules! iterable_impl( macro_rules! iterable_mut_impl( ($t: ident, $dim: expr) => ( impl IterableMut for $t { + #[inline] fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { unsafe { cast::transmute::<&'l mut $t, &'l mut [N, ..$dim * $dim]>(self).mut_iter() @@ -103,6 +105,7 @@ macro_rules! indexable_impl( macro_rules! column_impl( ($t: ident, $dim: expr) => ( impl + IterableMut> Column for $t { + #[inline] fn set_column(&mut self, col: uint, v: V) { for (i, e) in v.iter().enumerate() { if i == Dim::dim::<$t>() { @@ -113,6 +116,7 @@ macro_rules! column_impl( } } + #[inline] fn column(&self, col: uint) -> V { let mut res = Zero::zero::(); @@ -133,21 +137,22 @@ macro_rules! column_impl( macro_rules! mul_impl( ($t: ident, $dim: expr) => ( impl Mul<$t, $t> for $t { + #[inline] fn mul(&self, other: &$t) -> $t { let mut res: $t = Zero::zero(); - + for i in range(0u, $dim) { for j in range(0u, $dim) { let mut acc = Zero::zero::(); - + for k in range(0u, $dim) { acc = acc + self.at((i, k)) * other.at((k, j)); } - + res.set((i, j), acc); } } - + res } } @@ -157,16 +162,17 @@ macro_rules! mul_impl( macro_rules! rmul_impl( ($t: ident, $v: ident, $dim: expr) => ( impl RMul<$v> for $t { + #[inline] fn rmul(&self, other: &$v) -> $v { let mut res : $v = Zero::zero(); - + for i in range(0u, $dim) { for j in range(0u, $dim) { let val = res.at(i) + other.at(j) * self.at((i, j)); res.set(i, val) } } - + res } } @@ -176,16 +182,17 @@ macro_rules! rmul_impl( macro_rules! lmul_impl( ($t: ident, $v: ident, $dim: expr) => ( impl LMul<$v> for $t { + #[inline] fn lmul(&self, other: &$v) -> $v { let mut res : $v = Zero::zero(); - + for i in range(0u, $dim) { for j in range(0u, $dim) { let val = res.at(i) + other.at(j) * self.at((j, i)); res.set(i, val) } } - + res } } @@ -200,7 +207,7 @@ macro_rules! transform_impl( fn transform_vec(&self, v: &$v) -> $v { self.rmul(v) } - + #[inline] fn inv_transform(&self, v: &$v) -> $v { match self.inverse() { @@ -219,7 +226,7 @@ macro_rules! inv_impl( #[inline] fn inverse(&self) -> Option<$t> { let mut res : $t = self.clone(); - + if res.inplace_inverse() { Some(res) } @@ -227,11 +234,11 @@ macro_rules! inv_impl( None } } - + fn inplace_inverse(&mut self) -> bool { let mut res: $t = One::one(); let _0N: N = Zero::zero(); - + // inversion using Gauss-Jordan elimination for k in range(0u, $dim) { // search a non-zero value on the k-th column @@ -288,7 +295,7 @@ macro_rules! inv_impl( } } } - + *self = res; true @@ -303,12 +310,13 @@ macro_rules! transpose_impl( #[inline] fn transposed(&self) -> $t { let mut res = self.clone(); - + res.transpose(); - + res } - + + #[inline] fn transpose(&mut self) { for i in range(1u, $dim) { for j in range(0u, i) { @@ -327,20 +335,20 @@ macro_rules! approx_eq_impl( fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } - + #[inline] fn approx_eq(&self, other: &$t) -> bool { let mut zip = self.iter().zip(other.iter()); - + do zip.all |(a, b)| { a.approx_eq(b) } } - + #[inline] fn approx_eq_eps(&self, other: &$t, epsilon: &N) -> bool { let mut zip = self.iter().zip(other.iter()); - + do zip.all |(a, b)| { a.approx_eq_eps(b, epsilon) } @@ -352,6 +360,7 @@ macro_rules! approx_eq_impl( macro_rules! to_homogeneous_impl( ($t: ident, $t2: ident, $dim: expr, $dim2: expr) => ( impl ToHomogeneous<$t2> for $t { + #[inline] fn to_homogeneous(&self) -> $t2 { let mut res: $t2 = One::one(); @@ -370,6 +379,7 @@ macro_rules! to_homogeneous_impl( macro_rules! from_homogeneous_impl( ($t: ident, $t2: ident, $dim: expr, $dim2: expr) => ( impl FromHomogeneous<$t2> for $t { + #[inline] fn from(m: &$t2) -> $t { let mut res: $t = One::one(); diff --git a/src/mat_spec.rs b/src/mat_spec.rs index b446bd5d..2924e046 100644 --- a/src/mat_spec.rs +++ b/src/mat_spec.rs @@ -89,7 +89,7 @@ Inv for Mat3 { } else { *self = Mat3::new( - (minor_m12_m23 / det), + (minor_m12_m23 / det), ((self.m13 * self.m32 - self.m33 * self.m12) / det), ((self.m12 * self.m23 - self.m22 * self.m13) / det), diff --git a/src/vec0_spec.rs b/src/vec0_spec.rs index 1a389842..f707c2b0 100644 --- a/src/vec0_spec.rs +++ b/src/vec0_spec.rs @@ -17,230 +17,235 @@ use traits::indexable::Indexable; use vec; impl vec::Vec0 { - /// Creates a new vector. - #[inline] - pub fn new() -> vec::Vec0 { - vec::Vec0 - } + /// Creates a new vector. + #[inline] + pub fn new() -> vec::Vec0 { + vec::Vec0 + } } impl Indexable for vec::Vec0 { - #[inline] - pub fn at(&self, _: uint) -> N { - fail!("Cannot index a Vec0.") - } + #[inline] + pub fn at(&self, _: uint) -> N { + fail!("Cannot index a Vec0.") + } - #[inline] - pub fn set(&mut self, _: uint, _: N) { - - } + #[inline] + pub fn set(&mut self, _: uint, _: N) { - #[inline] - pub fn swap(&mut self, _: uint, _: uint) { - - } + } + + #[inline] + pub fn swap(&mut self, _: uint, _: uint) { + + } } impl vec::Vec0 { - /// Creates a new vector. The parameter is not taken in account. - #[inline] - pub fn new_repeat(_: N) -> vec::Vec0 { - vec::Vec0 - } + /// Creates a new vector. The parameter is not taken in account. + #[inline] + pub fn new_repeat(_: N) -> vec::Vec0 { + vec::Vec0 + } } impl Iterable for vec::Vec0 { - fn iter<'l>(&'l self) -> VecIterator<'l, N> { - unsafe { cast::transmute::<&'l vec::Vec0, &'l [N, ..0]>(self).iter() } - } + #[inline] + fn iter<'l>(&'l self) -> VecIterator<'l, N> { + unsafe { cast::transmute::<&'l vec::Vec0, &'l [N, ..0]>(self).iter() } + } } impl IterableMut for vec::Vec0 { - fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { - unsafe { cast::transmute::<&'l mut vec::Vec0, &'l mut [N, ..0]>(self).mut_iter() } - } + #[inline] + fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { + unsafe { cast::transmute::<&'l mut vec::Vec0, &'l mut [N, ..0]>(self).mut_iter() } + } } impl Dim for vec::Vec0 { - #[inline] - fn dim() -> uint { - 0 - } + #[inline] + fn dim() -> uint { + 0 + } } impl> Basis for vec::Vec0 { - pub fn canonical_basis(_: &fn(vec::Vec0)) { } + #[inline(always)] + pub fn canonical_basis(_: &fn(vec::Vec0)) { } - pub fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0)) { } + #[inline(always)] + pub fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0)) { } } impl> Add, vec::Vec0> for vec::Vec0 { - #[inline] - fn add(&self, _: &vec::Vec0) -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn add(&self, _: &vec::Vec0) -> vec::Vec0 { + vec::Vec0 + } } impl> Sub, vec::Vec0> for vec::Vec0 { - #[inline] - fn sub(&self, _: &vec::Vec0) -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn sub(&self, _: &vec::Vec0) -> vec::Vec0 { + vec::Vec0 + } } impl> Neg> for vec::Vec0 { - #[inline] - fn neg(&self) -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn neg(&self) -> vec::Vec0 { + vec::Vec0 + } } impl Dot for vec::Vec0 { - #[inline] - fn dot(&self, _: &vec::Vec0) -> N { - Zero::zero() - } + #[inline] + fn dot(&self, _: &vec::Vec0) -> N { + Zero::zero() + } } impl SubDot for vec::Vec0 { - #[inline] - fn sub_dot(&self, _: &vec::Vec0, _: &vec::Vec0) -> N { - Zero::zero() - } + #[inline] + fn sub_dot(&self, _: &vec::Vec0, _: &vec::Vec0) -> N { + Zero::zero() + } } impl> ScalarMul for vec::Vec0 { - #[inline] - fn scalar_mul(&self, _: &N) -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn scalar_mul(&self, _: &N) -> vec::Vec0 { + vec::Vec0 + } - #[inline] - fn scalar_mul_inplace(&mut self, _: &N) { } + #[inline] + fn scalar_mul_inplace(&mut self, _: &N) { } } impl> ScalarDiv for vec::Vec0 { - #[inline] - fn scalar_div(&self, _: &N) -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn scalar_div(&self, _: &N) -> vec::Vec0 { + vec::Vec0 + } - #[inline] - fn scalar_div_inplace(&mut self, _: &N) { } + #[inline] + fn scalar_div_inplace(&mut self, _: &N) { } } impl> ScalarAdd for vec::Vec0 { - #[inline] - fn scalar_add(&self, _: &N) -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn scalar_add(&self, _: &N) -> vec::Vec0 { + vec::Vec0 + } - #[inline] - fn scalar_add_inplace(&mut self, _: &N) { } + #[inline] + fn scalar_add_inplace(&mut self, _: &N) { } } impl> ScalarSub for vec::Vec0 { - #[inline] - fn scalar_sub(&self, _: &N) -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn scalar_sub(&self, _: &N) -> vec::Vec0 { + vec::Vec0 + } - #[inline] - fn scalar_sub_inplace(&mut self, _: &N) { } + #[inline] + fn scalar_sub_inplace(&mut self, _: &N) { } } impl + Neg> Translation> for vec::Vec0 { - #[inline] - fn translation(&self) -> vec::Vec0 { - self.clone() - } + #[inline] + fn translation(&self) -> vec::Vec0 { + self.clone() + } - #[inline] - fn inv_translation(&self) -> vec::Vec0 { - -self - } + #[inline] + fn inv_translation(&self) -> vec::Vec0 { + -self + } - #[inline] - fn translate_by(&mut self, t: &vec::Vec0) { - *self = *self + *t; - } + #[inline] + fn translate_by(&mut self, t: &vec::Vec0) { + *self = *self + *t; + } } impl + Neg + Clone> Translatable, vec::Vec0> for vec::Vec0 { - #[inline] - fn translated(&self, t: &vec::Vec0) -> vec::Vec0 { - self + *t - } + #[inline] + fn translated(&self, t: &vec::Vec0) -> vec::Vec0 { + self + *t + } } impl Norm for vec::Vec0 { - #[inline] - fn sqnorm(&self) -> N { - self.dot(self) - } + #[inline] + fn sqnorm(&self) -> N { + self.dot(self) + } - #[inline] - fn norm(&self) -> N { - self.sqnorm().sqrt() - } + #[inline] + fn norm(&self) -> N { + self.sqnorm().sqrt() + } - #[inline] - fn normalized(&self) -> vec::Vec0 { - let mut res : vec::Vec0 = self.clone(); + #[inline] + fn normalized(&self) -> vec::Vec0 { + let mut res : vec::Vec0 = self.clone(); - res.normalize(); + res.normalize(); - res - } + res + } - #[inline] - fn normalize(&mut self) -> N { - let l = self.norm(); + #[inline] + fn normalize(&mut self) -> N { + let l = self.norm(); - self.scalar_div_inplace(&l); + self.scalar_div_inplace(&l); - l - } + l + } } impl> ApproxEq for vec::Vec0 { - #[inline] - fn approx_epsilon() -> N { - ApproxEq::approx_epsilon::() - } + #[inline] + fn approx_epsilon() -> N { + ApproxEq::approx_epsilon::() + } - #[inline] - fn approx_eq(&self, _: &vec::Vec0) -> bool { - true - } + #[inline] + fn approx_eq(&self, _: &vec::Vec0) -> bool { + true + } - #[inline] - fn approx_eq_eps(&self, _: &vec::Vec0, _: &N) -> bool { - true - } + #[inline] + fn approx_eq_eps(&self, _: &vec::Vec0, _: &N) -> bool { + true + } } impl One for vec::Vec0 { - #[inline] - fn one() -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn one() -> vec::Vec0 { + vec::Vec0 + } } impl> FromIterator for vec::Vec0 { - fn from_iterator(_: &mut Iter) -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn from_iterator(_: &mut Iter) -> vec::Vec0 { + vec::Vec0 + } } impl Bounded for vec::Vec0 { - #[inline] - fn max_value() -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn max_value() -> vec::Vec0 { + vec::Vec0 + } - #[inline] - fn min_value() -> vec::Vec0 { - vec::Vec0 - } + #[inline] + fn min_value() -> vec::Vec0 { + vec::Vec0 + } } diff --git a/src/vec_macros.rs b/src/vec_macros.rs index c404a8c1..e28bb7ae 100644 --- a/src/vec_macros.rs +++ b/src/vec_macros.rs @@ -147,6 +147,7 @@ macro_rules! new_repeat_impl( macro_rules! iterable_impl( ($t: ident, $dim: expr) => ( impl Iterable for $t { + #[inline] fn iter<'l>(&'l self) -> VecIterator<'l, N> { unsafe { cast::transmute::<&'l $t, &'l [N, ..$dim]>(self).iter() @@ -159,6 +160,7 @@ macro_rules! iterable_impl( macro_rules! iterable_mut_impl( ($t: ident, $dim: expr) => ( impl IterableMut for $t { + #[inline] fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { unsafe { cast::transmute::<&'l mut $t, &'l mut [N, ..$dim]>(self).mut_iter() @@ -182,6 +184,7 @@ macro_rules! dim_impl( macro_rules! basis_impl( ($t: ident, $dim: expr) => ( impl> Basis for $t { + #[inline] pub fn canonical_basis(f: &fn($t)) { for i in range(0u, $dim) { let mut basis_element : $t = Zero::zero(); @@ -192,6 +195,7 @@ macro_rules! basis_impl( } } + #[inline] pub fn orthonormal_subspace_basis(&self, f: &fn($t)) { // compute the basis of the orthogonal subspace using Gram-Schmidt // orthogonalization algorithm @@ -451,6 +455,7 @@ macro_rules! one_impl( macro_rules! from_iterator_impl( ($t: ident, $param0: ident $(, $paramN: ident)*) => ( impl> FromIterator for $t { + #[inline] fn from_iterator($param0: &mut Iter) -> $t { $t::new($param0.next().unwrap() $(, $paramN.next().unwrap())*) } diff --git a/src/vec_spec.rs b/src/vec_spec.rs index f18282a4..ce01ccd8 100644 --- a/src/vec_spec.rs +++ b/src/vec_spec.rs @@ -143,6 +143,7 @@ static SAMPLES_3_F64: [Vec3, ..42] = [ ]; impl UniformSphereSample for Vec2 { + #[inline(always)] pub fn sample(f: &fn(&'static Vec2)) { for sample in SAMPLES_2_F64.iter() { f(sample) @@ -151,6 +152,7 @@ impl UniformSphereSample for Vec2 { } impl UniformSphereSample for Vec3 { + #[inline(always)] pub fn sample(f: &fn(&'static Vec3)) { for sample in SAMPLES_3_F64.iter() { f(sample)