diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index 5e65ebf3..e68bf2d5 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -20,6 +20,7 @@ pub struct Rotmat impl Rotmat { + #[inline(always)] fn submat(&self) -> M { self.submat } } @@ -67,12 +68,15 @@ pub fn rotmat3 + One + Sub + Add + impl + Trigonometric + Neg + Mul + Add + Copy> Rotation> for Rotmat> { + #[inline(always)] fn rotation(&self) -> Vec1 { Vec1::new(-(self.submat.m12 / self.submat.m11).atan()) } + #[inline(always)] fn rotated(&self, rot: &Vec1) -> Rotmat> { rotmat2(rot.x) * *self } + #[inline(always)] fn rotate(&mut self, rot: &Vec1) { *self = self.rotated(rot) } } @@ -81,18 +85,22 @@ impl + Trigonometric + Neg + Mul + Add + Copy + One + Sub> Rotation<(Vec3, N)> for Rotmat> { + #[inline(always)] fn rotation(&self) -> (Vec3, N) { fail!("Not yet implemented.") } + #[inline(always)] fn rotated(&self, &(axis, angle): &(Vec3, N)) -> Rotmat> { rotmat3(&axis, angle) * *self } + #[inline(always)] fn rotate(&mut self, rot: &(Vec3, N)) { *self = self.rotated(rot) } } impl> Rand for Rotmat> { + #[inline(always)] fn rand(rng: &mut R) -> Rotmat> { rotmat2(rng.gen()) } } @@ -101,57 +109,67 @@ impl + One + Sub + Add + Mul> Rand for Rotmat> { + #[inline(always)] fn rand(rng: &mut R) -> Rotmat> { rotmat3(&rng.gen(), rng.gen()) } } impl Dim for Rotmat { + #[inline(always)] fn dim() -> uint { Dim::dim::() } } impl One for Rotmat { + #[inline(always)] fn one() -> Rotmat { Rotmat { submat: One::one() } } } impl> Mul, Rotmat> for Rotmat { + #[inline(always)] fn mul(&self, other: &Rotmat) -> Rotmat { Rotmat { submat: self.submat.mul(&other.submat) } } } impl> RMul for Rotmat { + #[inline(always)] fn rmul(&self, other: &V) -> V { self.submat.rmul(other) } } impl> LMul for Rotmat { + #[inline(always)] fn lmul(&self, other: &V) -> V { self.submat.lmul(other) } } impl DeltaTransform for Rotmat { + #[inline(always)] fn delta_transform(&self) -> M { self.submat } } impl + Copy, V: Copy> DeltaTransformVector for Rotmat { + #[inline(always)] fn delta_transform_vector(&self, v: &V) -> V { self.submat.rmul(v) } } impl Inv for Rotmat { + #[inline(always)] fn invert(&mut self) { self.transpose() } + #[inline(always)] fn inverse(&self) -> Rotmat { self.transposed() } } @@ -159,21 +177,26 @@ impl Inv for Rotmat impl Transpose for Rotmat { + #[inline(always)] fn transposed(&self) -> Rotmat { Rotmat { submat: self.submat.transposed() } } + #[inline(always)] fn transpose(&mut self) { self.submat.transpose() } } impl, M: ApproxEq> ApproxEq for Rotmat { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &Rotmat) -> bool { self.submat.approx_eq(&other.submat) } + #[inline(always)] fn approx_eq_eps(&self, other: &Rotmat, epsilon: &N) -> bool { self.submat.approx_eq_eps(&other.submat, epsilon) } } diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index 201e48bd..d7a3f706 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -16,27 +16,34 @@ pub struct Transform priv subtrans : V } -pub fn transform(mat: &M, trans: &V) --> Transform -{ Transform { submat: *mat, subtrans: *trans } } +impl Transform +{ + #[inline(always)] + pub fn new(mat: &M, trans: &V) -> Transform + { Transform { submat: *mat, subtrans: *trans } } +} impl Dim for Transform { + #[inline(always)] fn dim() -> uint { Dim::dim::() } } impl One for Transform { + #[inline(always)] fn one() -> Transform { Transform { submat: One::one(), subtrans: Zero::zero() } } } impl Zero for Transform { + #[inline(always)] fn zero() -> Transform { Transform { submat: Zero::zero(), subtrans: Zero::zero() } } + #[inline(always)] fn is_zero(&self) -> bool { self.submat.is_zero() && self.subtrans.is_zero() } } @@ -44,6 +51,7 @@ impl Zero for Transform impl + Mul, V:Copy + Add> Mul, Transform> for Transform { + #[inline(always)] fn mul(&self, other: &Transform) -> Transform { Transform { submat: self.submat * other.submat, @@ -53,24 +61,29 @@ Mul, Transform> for Transform impl, V: Add> RMul for Transform { + #[inline(always)] fn rmul(&self, other: &V) -> V { self.submat.rmul(other) + self.subtrans } } impl, V: Add> LMul for Transform { + #[inline(always)] fn lmul(&self, other: &V) -> V { self.submat.lmul(other) + self.subtrans } } impl> Translation for Transform { + #[inline(always)] fn translation(&self) -> V { self.subtrans.translation() } + #[inline(always)] fn translated(&self, t: &V) -> Transform - { transform(&self.submat, &self.subtrans.translated(t)) } + { Transform::new(&self.submat, &self.subtrans.translated(t)) } + #[inline(always)] fn translate(&mut self, t: &V) { self.subtrans.translate(t) } } @@ -78,17 +91,20 @@ impl> Translation for Transform impl + Copy + RMul + One, V: Copy, AV> Rotation for Transform { + #[inline(always)] fn rotation(&self) -> AV { self.submat.rotation() } + #[inline(always)] fn rotated(&self, rot: &AV) -> Transform { // FIXME: this does not seem opitmal let delta = One::one::().rotated(rot); - transform(&self.submat.rotated(rot), &delta.rmul(&self.subtrans)) + Transform::new(&self.submat.rotated(rot), &delta.rmul(&self.subtrans)) } + #[inline(always)] fn rotate(&mut self, rot: &AV) { // FIXME: this does not seem opitmal @@ -100,12 +116,14 @@ Rotation for Transform impl DeltaTransform for Transform { + #[inline(always)] fn delta_transform(&self) -> M { self.submat } } impl + Copy, V> DeltaTransformVector for Transform { + #[inline(always)] fn delta_transform_vector(&self, v: &V) -> V { self.submat.rmul(v) } } @@ -113,12 +131,14 @@ impl + Copy, V> DeltaTransformVector for Transform impl, V:Copy + Neg> Inv for Transform { + #[inline(always)] fn invert(&mut self) { self.submat.invert(); self.subtrans = self.submat.rmul(&-self.subtrans); } + #[inline(always)] fn inverse(&self) -> Transform { let mut res = *self; @@ -132,15 +152,18 @@ Inv for Transform impl, M:ApproxEq, V:ApproxEq> ApproxEq for Transform { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &Transform) -> bool { self.submat.approx_eq(&other.submat) && self.subtrans.approx_eq(&other.subtrans) } + #[inline(always)] fn approx_eq_eps(&self, other: &Transform, epsilon: &N) -> bool { self.submat.approx_eq_eps(&other.submat, epsilon) && @@ -150,6 +173,7 @@ ApproxEq for Transform impl Rand for Transform { + #[inline(always)] fn rand(rng: &mut R) -> Transform - { transform(&rng.gen(), &rng.gen()) } + { Transform::new(&rng.gen(), &rng.gen()) } } diff --git a/src/dim1/mat1.rs b/src/dim1/mat1.rs index 2e7024d8..d2766040 100644 --- a/src/dim1/mat1.rs +++ b/src/dim1/mat1.rs @@ -14,6 +14,7 @@ pub struct Mat1 impl Mat1 { + #[inline(always)] pub fn new(m11: N) -> Mat1 { Mat1 @@ -23,39 +24,46 @@ impl Mat1 impl Dim for Mat1 { + #[inline(always)] fn dim() -> uint { 1 } } impl One for Mat1 { + #[inline(always)] fn one() -> Mat1 { return Mat1::new(One::one()) } } impl Zero for Mat1 { + #[inline(always)] fn zero() -> Mat1 { Mat1::new(Zero::zero()) } + #[inline(always)] fn is_zero(&self) -> bool { self.m11.is_zero() } } impl + Add> Mul, Mat1> for Mat1 { + #[inline(always)] fn mul(&self, other: &Mat1) -> Mat1 { Mat1::new(self.m11 * other.m11) } } impl + Mul> RMul> for Mat1 { + #[inline(always)] fn rmul(&self, other: &Vec1) -> Vec1 { Vec1::new(self.m11 * other.x) } } impl + Mul> LMul> for Mat1 { + #[inline(always)] fn lmul(&self, other: &Vec1) -> Vec1 { Vec1::new(self.m11 * other.x) } } @@ -63,6 +71,7 @@ impl + Mul> LMul> for Mat1 impl + Div + Sub + Neg + Zero + One> Inv for Mat1 { + #[inline(always)] fn inverse(&self) -> Mat1 { let mut res : Mat1 = *self; @@ -72,6 +81,7 @@ Inv for Mat1 res } + #[inline(always)] fn invert(&mut self) { assert!(!self.m11.is_zero()); @@ -82,42 +92,52 @@ Inv for Mat1 impl Transpose for Mat1 { + #[inline(always)] fn transposed(&self) -> Mat1 { *self } + #[inline(always)] fn transpose(&mut self) { } } impl> ApproxEq for Mat1 { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &Mat1) -> bool { self.m11.approx_eq(&other.m11) } + #[inline(always)] fn approx_eq_eps(&self, other: &Mat1, epsilon: &N) -> bool { self.m11.approx_eq_eps(&other.m11, epsilon) } } impl Rand for Mat1 { + #[inline(always)] fn rand(rng: &mut R) -> Mat1 { Mat1::new(rng.gen()) } } impl Flatten for Mat1 { + #[inline(always)] fn flat_size() -> uint { 1 } + #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Mat1 { Mat1::new(l[off]) } + #[inline(always)] fn flatten(&self) -> ~[N] { ~[ self.m11 ] } + #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { l[off] = self.m11 } } diff --git a/src/dim1/vec1.rs b/src/dim1/vec1.rs index 76513fa1..66c04ddb 100644 --- a/src/dim1/vec1.rs +++ b/src/dim1/vec1.rs @@ -17,24 +17,28 @@ pub struct Vec1 impl Vec1 { + #[inline(always)] pub fn new(x: N) -> Vec1 { Vec1 {x: x} } } impl Dim for Vec1 { + #[inline(always)] fn dim() -> uint { 1 } } impl> Add, Vec1> for Vec1 { + #[inline(always)] fn add(&self, other: &Vec1) -> Vec1 { Vec1::new(self.x + other.x) } } impl> Sub, Vec1> for Vec1 { + #[inline(always)] fn sub(&self, other: &Vec1) -> Vec1 { Vec1::new(self.x - other.x) } } @@ -42,9 +46,11 @@ impl> Sub, Vec1> for Vec1 impl> ScalarMul for Vec1 { + #[inline(always)] fn scalar_mul(&self, s: &N) -> Vec1 { Vec1 { x: self.x * *s } } + #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) { self.x *= *s; } } @@ -53,9 +59,11 @@ ScalarMul for Vec1 impl> ScalarDiv for Vec1 { + #[inline(always)] fn scalar_div(&self, s: &N) -> Vec1 { Vec1 { x: self.x / *s } } + #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) { self.x /= *s; } } @@ -63,9 +71,11 @@ ScalarDiv for Vec1 impl> ScalarAdd for Vec1 { + #[inline(always)] fn scalar_add(&self, s: &N) -> Vec1 { Vec1 { x: self.x + *s } } + #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) { self.x += *s; } } @@ -73,33 +83,40 @@ ScalarAdd for Vec1 impl> ScalarSub for Vec1 { + #[inline(always)] fn scalar_sub(&self, s: &N) -> Vec1 { Vec1 { x: self.x - *s } } + #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) { self.x -= *s; } } impl> Translation> for Vec1 { + #[inline(always)] fn translation(&self) -> Vec1 { *self } + #[inline(always)] fn translated(&self, t: &Vec1) -> Vec1 { self + *t } + #[inline(always)] fn translate(&mut self, t: &Vec1) { *self += *t } } impl> Dot for Vec1 { + #[inline(always)] fn dot(&self, other : &Vec1) -> N { self.x * other.x } } impl + Sub> SubDot for Vec1 { + #[inline(always)] fn sub_dot(&self, a: &Vec1, b: &Vec1) -> N { (self.x - a.x) * b.x } } @@ -107,15 +124,19 @@ impl + Sub> SubDot for Vec1 impl + Add + Div + Algebraic> Norm for Vec1 { + #[inline(always)] fn sqnorm(&self) -> N { self.dot(self) } + #[inline(always)] fn norm(&self) -> N { self.sqnorm().sqrt() } + #[inline(always)] fn normalized(&self) -> Vec1 { Vec1::new(self.x / self.norm()) } + #[inline(always)] fn normalize(&mut self) -> N { let l = self.norm(); @@ -128,60 +149,73 @@ Norm for Vec1 impl> Neg> for Vec1 { + #[inline(always)] fn neg(&self) -> Vec1 { Vec1::new(-self.x) } } impl Zero for Vec1 { + #[inline(always)] fn zero() -> Vec1 { let _0 = Zero::zero(); Vec1::new(_0) } + #[inline(always)] fn is_zero(&self) -> bool { self.x.is_zero() } } impl Basis for Vec1 { + #[inline(always)] fn canonical_basis() -> ~[Vec1] { ~[ Vec1::new(One::one()) ] } // FIXME: this should be static + #[inline(always)] fn orthogonal_subspace_basis(&self) -> ~[Vec1] { ~[] } } impl> ApproxEq for Vec1 { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &Vec1) -> bool { self.x.approx_eq(&other.x) } + #[inline(always)] fn approx_eq_eps(&self, other: &Vec1, epsilon: &N) -> bool { self.x.approx_eq_eps(&other.x, epsilon) } } impl Rand for Vec1 { + #[inline(always)] fn rand(rng: &mut R) -> Vec1 { Vec1::new(rng.gen()) } } impl Flatten for Vec1 { + #[inline(always)] fn flat_size() -> uint { 1 } + #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Vec1 { Vec1::new(l[off]) } + #[inline(always)] fn flatten(&self) -> ~[N] { ~[ self.x ] } + #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { l[off] = self.x } } diff --git a/src/dim2/mat2.rs b/src/dim2/mat2.rs index f7b934cf..ccbb36a2 100644 --- a/src/dim2/mat2.rs +++ b/src/dim2/mat2.rs @@ -18,6 +18,7 @@ pub struct Mat2 impl Mat2 { + #[inline(always)] pub fn new(m11: N, m12: N, m21: N, m22: N) -> Mat2 { Mat2 @@ -30,12 +31,14 @@ impl Mat2 impl Dim for Mat2 { + #[inline(always)] fn dim() -> uint { 2 } } impl One for Mat2 { + #[inline(always)] fn one() -> Mat2 { let (_0, _1) = (Zero::zero(), One::one()); @@ -46,6 +49,7 @@ impl One for Mat2 impl Zero for Mat2 { + #[inline(always)] fn zero() -> Mat2 { let _0 = Zero::zero(); @@ -53,6 +57,7 @@ impl Zero for Mat2 _0, _0) } + #[inline(always)] fn is_zero(&self) -> bool { self.m11.is_zero() && self.m12.is_zero() && @@ -62,6 +67,7 @@ impl Zero for Mat2 impl + Add> Mul, Mat2> for Mat2 { + #[inline(always)] fn mul(&self, other: &Mat2) -> Mat2 { Mat2::new( @@ -75,6 +81,7 @@ impl + Add> Mul, Mat2> for Mat2 impl + Mul> RMul> for Mat2 { + #[inline(always)] fn rmul(&self, other: &Vec2) -> Vec2 { Vec2::new( @@ -86,6 +93,7 @@ impl + Mul> RMul> for Mat2 impl + Mul> LMul> for Mat2 { + #[inline(always)] fn lmul(&self, other: &Vec2) -> Vec2 { Vec2::new( @@ -98,6 +106,7 @@ impl + Mul> LMul> for Mat2 impl + Div + Sub + Neg + Zero> Inv for Mat2 { + #[inline(always)] fn inverse(&self) -> Mat2 { let mut res : Mat2 = *self; @@ -107,6 +116,7 @@ Inv for Mat2 res } + #[inline(always)] fn invert(&mut self) { let det = self.m11 * self.m22 - self.m21 * self.m12; @@ -120,21 +130,25 @@ Inv for Mat2 impl Transpose for Mat2 { + #[inline(always)] fn transposed(&self) -> Mat2 { Mat2::new(self.m11, self.m21, self.m12, self.m22) } + #[inline(always)] fn transpose(&mut self) { swap(&mut self.m21, &mut self.m12); } } impl> ApproxEq for Mat2 { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &Mat2) -> bool { self.m11.approx_eq(&other.m11) && @@ -144,6 +158,7 @@ impl> ApproxEq for Mat2 self.m22.approx_eq(&other.m22) } + #[inline(always)] fn approx_eq_eps(&self, other: &Mat2, epsilon: &N) -> bool { self.m11.approx_eq_eps(&other.m11, epsilon) && @@ -156,21 +171,26 @@ impl> ApproxEq for Mat2 impl Rand for Mat2 { + #[inline(always)] fn rand(rng: &mut R) -> Mat2 { Mat2::new(rng.gen(), rng.gen(), rng.gen(), rng.gen()) } } impl Flatten for Mat2 { + #[inline(always)] fn flat_size() -> uint { 4 } + #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Mat2 { Mat2::new(l[off], l[off + 1], l[off + 2], l[off + 3]) } + #[inline(always)] fn flatten(&self) -> ~[N] { ~[ self.m11, self.m12, self.m21, self.m22 ] } + #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { l[off] = self.m11; diff --git a/src/dim2/vec2.rs b/src/dim2/vec2.rs index a49f1705..343bcbd4 100644 --- a/src/dim2/vec2.rs +++ b/src/dim2/vec2.rs @@ -21,24 +21,28 @@ pub struct Vec2 impl Vec2 { + #[inline(always)] pub fn new(x: N, y: N) -> Vec2 { Vec2 {x: x, y: y} } } impl Dim for Vec2 { + #[inline(always)] fn dim() -> uint { 2 } } impl> Add, Vec2> for Vec2 { + #[inline(always)] fn add(&self, other: &Vec2) -> Vec2 { Vec2::new(self.x + other.x, self.y + other.y) } } impl> Sub, Vec2> for Vec2 { + #[inline(always)] fn sub(&self, other: &Vec2) -> Vec2 { Vec2::new(self.x - other.x, self.y - other.y) } } @@ -46,9 +50,11 @@ impl> Sub, Vec2> for Vec2 impl> ScalarMul for Vec2 { + #[inline(always)] fn scalar_mul(&self, s: &N) -> Vec2 { Vec2 { x: self.x * *s, y: self.y * *s } } + #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) { self.x *= *s; @@ -60,9 +66,11 @@ ScalarMul for Vec2 impl> ScalarDiv for Vec2 { + #[inline(always)] fn scalar_div(&self, s: &N) -> Vec2 { Vec2 { x: self.x / *s, y: self.y / *s } } + #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) { self.x /= *s; @@ -73,9 +81,11 @@ ScalarDiv for Vec2 impl> ScalarAdd for Vec2 { + #[inline(always)] fn scalar_add(&self, s: &N) -> Vec2 { Vec2 { x: self.x + *s, y: self.y + *s } } + #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) { self.x += *s; @@ -86,9 +96,11 @@ ScalarAdd for Vec2 impl> ScalarSub for Vec2 { + #[inline(always)] fn scalar_sub(&self, s: &N) -> Vec2 { Vec2 { x: self.x - *s, y: self.y - *s } } + #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) { self.x -= *s; @@ -98,24 +110,29 @@ ScalarSub for Vec2 impl> Translation> for Vec2 { + #[inline(always)] fn translation(&self) -> Vec2 { *self } + #[inline(always)] fn translated(&self, t: &Vec2) -> Vec2 { self + *t } + #[inline(always)] fn translate(&mut self, t: &Vec2) { *self += *t; } } impl + Add> Dot for Vec2 { + #[inline(always)] fn dot(&self, other : &Vec2) -> N { self.x * other.x + self.y * other.y } } impl + Add + Sub> SubDot for Vec2 { + #[inline(always)] fn sub_dot(&self, a: &Vec2, b: &Vec2) -> N { (self.x - a.x) * b.x + (self.y - a.y) * b.y } } @@ -123,12 +140,15 @@ impl + Add + Sub> SubDot for Vec2 impl + Add + Div + Algebraic> Norm for Vec2 { + #[inline(always)] fn sqnorm(&self) -> N { self.dot(self) } + #[inline(always)] fn norm(&self) -> N { self.sqnorm().sqrt() } + #[inline(always)] fn normalized(&self) -> Vec2 { let l = self.norm(); @@ -136,6 +156,7 @@ Norm for Vec2 Vec2::new(self.x / l, self.y / l) } + #[inline(always)] fn normalize(&mut self) -> N { let l = self.norm(); @@ -149,30 +170,35 @@ Norm for Vec2 impl + Sub> Cross> for Vec2 { + #[inline(always)] fn cross(&self, other : &Vec2) -> Vec1 { Vec1::new(self.x * other.y - self.y * other.x) } } impl> Neg> for Vec2 { + #[inline(always)] fn neg(&self) -> Vec2 { Vec2::new(-self.x, -self.y) } } impl Zero for Vec2 { + #[inline(always)] fn zero() -> Vec2 { let _0 = Zero::zero(); Vec2::new(_0, _0) } + #[inline(always)] fn is_zero(&self) -> bool { self.x.is_zero() && self.y.is_zero() } } impl> Basis for Vec2 { + #[inline(always)] fn canonical_basis() -> ~[Vec2] { // FIXME: this should be static @@ -180,18 +206,22 @@ impl> Basis for Vec2 Vec2::new(Zero::zero(), One::one()) ] } + #[inline(always)] fn orthogonal_subspace_basis(&self) -> ~[Vec2] { ~[ Vec2::new(-self.y, self.x) ] } } impl> ApproxEq for Vec2 { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &Vec2) -> bool { self.x.approx_eq(&other.x) && self.y.approx_eq(&other.y) } + #[inline(always)] fn approx_eq_eps(&self, other: &Vec2, epsilon: &N) -> bool { self.x.approx_eq_eps(&other.x, epsilon) && @@ -201,21 +231,26 @@ impl> ApproxEq for Vec2 impl Rand for Vec2 { + #[inline(always)] fn rand(rng: &mut R) -> Vec2 { Vec2::new(rng.gen(), rng.gen()) } } impl Flatten for Vec2 { + #[inline(always)] fn flat_size() -> uint { 2 } + #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Vec2 { Vec2::new(l[off], l[off + 1]) } + #[inline(always)] fn flatten(&self) -> ~[N] { ~[ self.x, self.y ] } + #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { l[off] = self.x; diff --git a/src/dim3/mat3.rs b/src/dim3/mat3.rs index 27d6c966..82690c71 100644 --- a/src/dim3/mat3.rs +++ b/src/dim3/mat3.rs @@ -19,6 +19,7 @@ pub struct Mat3 impl Mat3 { + #[inline(always)] pub fn new(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> Mat3 @@ -34,12 +35,14 @@ impl Mat3 impl Dim for Mat3 { + #[inline(always)] fn dim() -> uint { 3 } } impl One for Mat3 { + #[inline(always)] fn one() -> Mat3 { let (_0, _1) = (Zero::zero(), One::one()); @@ -51,6 +54,7 @@ impl One for Mat3 impl Zero for Mat3 { + #[inline(always)] fn zero() -> Mat3 { let _0 = Zero::zero(); @@ -59,6 +63,7 @@ impl Zero for Mat3 _0, _0, _0) } + #[inline(always)] fn is_zero(&self) -> bool { self.m11.is_zero() && self.m12.is_zero() && self.m13.is_zero() && @@ -69,6 +74,7 @@ impl Zero for Mat3 impl + Add> Mul, Mat3> for Mat3 { + #[inline(always)] fn mul(&self, other: &Mat3) -> Mat3 { Mat3::new( @@ -89,6 +95,7 @@ impl + Add> Mul, Mat3> for Mat3 impl + Mul> RMul> for Mat3 { + #[inline(always)] fn rmul(&self, other: &Vec3) -> Vec3 { Vec3::new( @@ -101,6 +108,7 @@ impl + Mul> RMul> for Mat3 impl + Mul> LMul> for Mat3 { + #[inline(always)] fn lmul(&self, other: &Vec3) -> Vec3 { Vec3::new( @@ -114,6 +122,7 @@ impl + Mul> LMul> for Mat3 impl + Div + Sub + Add + Neg + Zero> Inv for Mat3 { + #[inline(always)] fn inverse(&self) -> Mat3 { let mut res = *self; @@ -123,6 +132,7 @@ Inv for Mat3 res } + #[inline(always)] fn invert(&mut self) { let minor_m22_m33 = self.m22 * self.m33 - self.m32 * self.m23; @@ -153,6 +163,7 @@ Inv for Mat3 impl Transpose for Mat3 { + #[inline(always)] fn transposed(&self) -> Mat3 { Mat3::new(self.m11, self.m21, self.m31, @@ -160,6 +171,7 @@ impl Transpose for Mat3 self.m13, self.m23, self.m33) } + #[inline(always)] fn transpose(&mut self) { swap(&mut self.m12, &mut self.m21); @@ -170,9 +182,11 @@ impl Transpose for Mat3 impl> ApproxEq for Mat3 { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &Mat3) -> bool { self.m11.approx_eq(&other.m11) && @@ -188,6 +202,7 @@ impl> ApproxEq for Mat3 self.m33.approx_eq(&other.m33) } + #[inline(always)] fn approx_eq_eps(&self, other: &Mat3, epsilon: &N) -> bool { self.m11.approx_eq_eps(&other.m11, epsilon) && @@ -206,6 +221,7 @@ impl> ApproxEq for Mat3 impl Rand for Mat3 { + #[inline(always)] fn rand(rng: &mut R) -> Mat3 { Mat3::new(rng.gen(), rng.gen(), rng.gen(), @@ -216,14 +232,17 @@ impl Rand for Mat3 impl Flatten for Mat3 { + #[inline(always)] fn flat_size() -> uint { 9 } + #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Mat3 { Mat3::new(l[off + 0], l[off + 1], l[off + 2], l[off + 3], l[off + 4], l[off + 5], l[off + 6], l[off + 7], l[off + 8]) } + #[inline(always)] fn flatten(&self) -> ~[N] { ~[ @@ -233,6 +252,7 @@ impl Flatten for Mat3 ] } + #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { l[off + 0] = self.m11; diff --git a/src/dim3/vec3.rs b/src/dim3/vec3.rs index 500de8df..62746665 100644 --- a/src/dim3/vec3.rs +++ b/src/dim3/vec3.rs @@ -21,24 +21,28 @@ pub struct Vec3 impl Vec3 { + #[inline(always)] pub fn new(x: N, y: N, z: N) -> Vec3 { Vec3 {x: x, y: y, z: z} } } impl Dim for Vec3 { + #[inline(always)] fn dim() -> uint { 3 } } impl> Add, Vec3> for Vec3 { + #[inline(always)] fn add(&self, other: &Vec3) -> Vec3 { Vec3::new(self.x + other.x, self.y + other.y, self.z + other.z) } } impl> Sub, Vec3> for Vec3 { + #[inline(always)] fn sub(&self, other: &Vec3) -> Vec3 { Vec3::new(self.x - other.x, self.y - other.y, self.z - other.z) } } @@ -46,9 +50,11 @@ impl> Sub, Vec3> for Vec3 impl> ScalarMul for Vec3 { + #[inline(always)] fn scalar_mul(&self, s: &N) -> Vec3 { Vec3 { x: self.x * *s, y: self.y * *s, z: self.z * *s } } + #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) { self.x *= *s; @@ -61,9 +67,11 @@ ScalarMul for Vec3 impl> ScalarDiv for Vec3 { + #[inline(always)] fn scalar_div(&self, s: &N) -> Vec3 { Vec3 { x: self.x / *s, y: self.y / *s, z: self.z / *s } } + #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) { self.x /= *s; @@ -75,9 +83,11 @@ ScalarDiv for Vec3 impl> ScalarAdd for Vec3 { + #[inline(always)] fn scalar_add(&self, s: &N) -> Vec3 { Vec3 { x: self.x + *s, y: self.y + *s, z: self.z + *s } } + #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) { self.x += *s; @@ -89,9 +99,11 @@ ScalarAdd for Vec3 impl> ScalarSub for Vec3 { + #[inline(always)] fn scalar_sub(&self, s: &N) -> Vec3 { Vec3 { x: self.x - *s, y: self.y - *s, z: self.z - *s } } + #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) { self.x -= *s; @@ -102,12 +114,15 @@ ScalarSub for Vec3 impl> Translation> for Vec3 { + #[inline(always)] fn translation(&self) -> Vec3 { *self } + #[inline(always)] fn translated(&self, t: &Vec3) -> Vec3 { self + *t } + #[inline(always)] fn translate(&mut self, t: &Vec3) { *self += *t; } } @@ -116,18 +131,21 @@ impl> Translation> for Vec3 impl> Neg> for Vec3 { + #[inline(always)] fn neg(&self) -> Vec3 { Vec3::new(-self.x, -self.y, -self.z) } } impl + Add> Dot for Vec3 { + #[inline(always)] fn dot(&self, other : &Vec3) -> N { self.x * other.x + self.y * other.y + self.z * other.z } } impl + Add + Sub> SubDot for Vec3 { + #[inline(always)] fn sub_dot(&self, a: &Vec3, b: &Vec3) -> N { (self.x - a.x) * b.x + (self.y - a.y) * b.y + (self.z - a.z) * b.z } } @@ -135,12 +153,15 @@ impl + Add + Sub> SubDot for Vec3 impl + Add + Div + Algebraic> Norm for Vec3 { + #[inline(always)] fn sqnorm(&self) -> N { self.dot(self) } + #[inline(always)] fn norm(&self) -> N { self.sqnorm().sqrt() } + #[inline(always)] fn normalized(&self) -> Vec3 { let l = self.norm(); @@ -148,6 +169,7 @@ Norm for Vec3 Vec3::new(self.x / l, self.y / l, self.z / l) } + #[inline(always)] fn normalize(&mut self) -> N { let l = self.norm(); @@ -162,6 +184,7 @@ Norm for Vec3 impl + Sub> Cross> for Vec3 { + #[inline(always)] fn cross(&self, other : &Vec3) -> Vec3 { Vec3::new( @@ -174,12 +197,14 @@ impl + Sub> Cross> for Vec3 impl Zero for Vec3 { + #[inline(always)] fn zero() -> Vec3 { let _0 = Zero::zero(); Vec3::new(_0, _0, _0) } + #[inline(always)] fn is_zero(&self) -> bool { self.x.is_zero() && self.y.is_zero() && self.z.is_zero() } } @@ -188,6 +213,7 @@ impl + Ord + Mul + Sub + Add + Div + Algebraic> Basis for Vec3 { + #[inline(always)] fn canonical_basis() -> ~[Vec3] { // FIXME: this should be static @@ -196,6 +222,7 @@ Basis for Vec3 Vec3::new(Zero::zero(), Zero::zero(), One::one()) ] } + #[inline(always)] fn orthogonal_subspace_basis(&self) -> ~[Vec3] { let a = @@ -210,9 +237,11 @@ Basis for Vec3 impl> ApproxEq for Vec3 { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &Vec3) -> bool { self.x.approx_eq(&other.x) && @@ -220,6 +249,7 @@ impl> ApproxEq for Vec3 self.z.approx_eq(&other.z) } + #[inline(always)] fn approx_eq_eps(&self, other: &Vec3, epsilon: &N) -> bool { self.x.approx_eq_eps(&other.x, epsilon) && @@ -230,21 +260,26 @@ impl> ApproxEq for Vec3 impl Rand for Vec3 { + #[inline(always)] fn rand(rng: &mut R) -> Vec3 { Vec3::new(rng.gen(), rng.gen(), rng.gen()) } } impl Flatten for Vec3 { + #[inline(always)] fn flat_size() -> uint { 3 } + #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Vec3 { Vec3::new(l[off], l[off + 1], l[off + 2]) } + #[inline(always)] fn flatten(&self) -> ~[N] { ~[ self.x, self.y, self.z ] } + #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { l[off] = self.x; diff --git a/src/ndim/dmat.rs b/src/ndim/dmat.rs index b46b41d0..7a17bdc8 100644 --- a/src/ndim/dmat.rs +++ b/src/ndim/dmat.rs @@ -16,12 +16,15 @@ pub struct DMat mij: ~[N] } +#[inline(always)] pub fn zero_mat_with_dim(dim: uint) -> DMat { DMat { dim: dim, mij: from_elem(dim * dim, Zero::zero()) } } +#[inline(always)] pub fn is_zero_mat(mat: &DMat) -> bool { mat.mij.all(|e| e.is_zero()) } +#[inline(always)] pub fn one_mat_with_dim(dim: uint) -> DMat { let mut res = zero_mat_with_dim(dim); @@ -35,9 +38,11 @@ pub fn one_mat_with_dim(dim: uint) -> DMat impl DMat { + #[inline(always)] pub fn offset(&self, i: uint, j: uint) -> uint { i * self.dim + j } + #[inline(always)] pub fn set(&mut self, i: uint, j: uint, t: &N) { assert!(i < self.dim); @@ -45,6 +50,7 @@ impl DMat self.mij[self.offset(i, j)] = *t } + #[inline(always)] pub fn at(&self, i: uint, j: uint) -> N { assert!(i < self.dim); @@ -55,6 +61,7 @@ impl DMat impl Index<(uint, uint), N> for DMat { + #[inline(always)] fn index(&self, &(i, j): &(uint, uint)) -> N { self.at(i, j) } } @@ -129,6 +136,7 @@ LMul> for DMat impl Inv for DMat { + #[inline(always)] fn inverse(&self) -> DMat { let mut res : DMat = self.clone(); @@ -217,6 +225,7 @@ Inv for DMat impl Transpose for DMat { + #[inline(always)] fn transposed(&self) -> DMat { let mut res = copy *self; @@ -245,9 +254,11 @@ impl Transpose for DMat impl> ApproxEq for DMat { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &DMat) -> bool { let mut zip = self.mij.iter().zip(other.mij.iter()); @@ -255,6 +266,7 @@ impl> ApproxEq for DMat do zip.all |(a, b)| { a.approx_eq(b) } } + #[inline(always)] fn approx_eq_eps(&self, other: &DMat, epsilon: &N) -> bool { let mut zip = self.mij.iter().zip(other.mij.iter()); diff --git a/src/ndim/dvec.rs b/src/ndim/dvec.rs index eb060151..f9db1385 100644 --- a/src/ndim/dvec.rs +++ b/src/ndim/dvec.rs @@ -17,9 +17,11 @@ pub struct DVec at: ~[N] } +#[inline(always)] pub fn zero_vec_with_dim(dim: uint) -> DVec { DVec { at: from_elem(dim, Zero::zero::()) } } +#[inline(always)] pub fn is_zero_vec(vec: &DVec) -> bool { vec.at.all(|e| e.is_zero()) } @@ -77,6 +79,7 @@ impl> DVec impl> Add, DVec> for DVec { + #[inline(always)] fn add(&self, other: &DVec) -> DVec { assert!(self.at.len() == other.at.len()); @@ -86,6 +89,7 @@ impl> Add, DVec> for DVec impl> Sub, DVec> for DVec { + #[inline(always)] fn sub(&self, other: &DVec) -> DVec { assert!(self.at.len() == other.at.len()); @@ -95,6 +99,7 @@ impl> Sub, DVec> for DVec impl> Neg> for DVec { + #[inline(always)] fn neg(&self) -> DVec { DVec { at: map(self.at, |a| -a) } } } @@ -102,6 +107,7 @@ impl> Neg> for DVec impl Dot for DVec { + #[inline(always)] fn dot(&self, other: &DVec) -> N { assert!(self.at.len() == other.at.len()); @@ -117,6 +123,7 @@ Dot for DVec impl SubDot for DVec { + #[inline(always)] fn sub_dot(&self, a: &DVec, b: &DVec) -> N { let mut res = Zero::zero::(); @@ -131,9 +138,11 @@ impl SubDot for DVec impl> ScalarMul for DVec { + #[inline(always)] fn scalar_mul(&self, s: &N) -> DVec { DVec { at: map(self.at, |a| a * *s) } } + #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| @@ -145,9 +154,11 @@ ScalarMul for DVec impl> ScalarDiv for DVec { + #[inline(always)] fn scalar_div(&self, s: &N) -> DVec { DVec { at: map(self.at, |a| a / *s) } } + #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| @@ -158,9 +169,11 @@ ScalarDiv for DVec impl> ScalarAdd for DVec { + #[inline(always)] fn scalar_add(&self, s: &N) -> DVec { DVec { at: map(self.at, |a| a + *s) } } + #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| @@ -171,9 +184,11 @@ ScalarAdd for DVec impl> ScalarSub for DVec { + #[inline(always)] fn scalar_sub(&self, s: &N) -> DVec { DVec { at: map(self.at, |a| a - *s) } } + #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| @@ -183,12 +198,15 @@ ScalarSub for DVec impl> Translation> for DVec { + #[inline(always)] fn translation(&self) -> DVec { self.clone() } + #[inline(always)] fn translated(&self, t: &DVec) -> DVec { self + *t } + #[inline(always)] fn translate(&mut self, t: &DVec) { *self = *self + *t; } } @@ -196,12 +214,15 @@ impl> Translation> for DVec impl Norm for DVec { + #[inline(always)] fn sqnorm(&self) -> N { self.dot(self) } + #[inline(always)] fn norm(&self) -> N { self.sqnorm().sqrt() } + #[inline(always)] fn normalized(&self) -> DVec { let mut res : DVec = self.clone(); @@ -211,6 +232,7 @@ Norm for DVec res } + #[inline(always)] fn normalize(&mut self) -> N { let l = self.norm(); @@ -224,9 +246,11 @@ Norm for DVec impl> ApproxEq for DVec { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &DVec) -> bool { let mut zip = self.at.iter().zip(other.at.iter()); @@ -234,6 +258,7 @@ impl> ApproxEq for DVec do zip.all |(a, b)| { a.approx_eq(b) } } + #[inline(always)] fn approx_eq_eps(&self, other: &DVec, epsilon: &N) -> bool { let mut zip = self.at.iter().zip(other.at.iter()); diff --git a/src/ndim/nmat.rs b/src/ndim/nmat.rs index 36c31476..9e0c659d 100644 --- a/src/ndim/nmat.rs +++ b/src/ndim/nmat.rs @@ -21,36 +21,43 @@ pub struct NMat impl NMat { + #[inline(always)] fn offset(i: uint, j: uint) -> uint { i * Dim::dim::() + j } + #[inline(always)] fn set(&mut self, i: uint, j: uint, t: &N) { self.mij.set(i, j, t) } } impl Dim for NMat { + #[inline(always)] fn dim() -> uint { Dim::dim::() } } impl Index<(uint, uint), N> for NMat { + #[inline(always)] fn index(&self, &idx: &(uint, uint)) -> N { self.mij[idx] } } impl One for NMat { + #[inline(always)] fn one() -> NMat { NMat { mij: one_mat_with_dim(Dim::dim::()) } } } impl Zero for NMat { + #[inline(always)] fn zero() -> NMat { NMat { mij: zero_mat_with_dim(Dim::dim::()) } } + #[inline(always)] fn is_zero(&self) -> bool { is_zero_mat(&self.mij) } } @@ -119,15 +126,18 @@ LMul> for NMat impl Inv for NMat { + #[inline(always)] fn inverse(&self) -> NMat { NMat { mij: self.mij.inverse() } } + #[inline(always)] fn invert(&mut self) { self.mij.invert() } } impl Transpose for NMat { + #[inline(always)] fn transposed(&self) -> NMat { let mut res = copy *self; @@ -137,18 +147,22 @@ impl Transpose for NMat res } + #[inline(always)] fn transpose(&mut self) { self.mij.transpose() } } impl> ApproxEq for NMat { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &NMat) -> bool { self.mij.approx_eq(&other.mij) } + #[inline(always)] fn approx_eq_eps(&self, other: &NMat, epsilon: &N) -> bool { self.mij.approx_eq_eps(&other.mij, epsilon) } } @@ -172,9 +186,11 @@ impl Rand for NMat impl Flatten for NMat { + #[inline(always)] fn flat_size() -> uint { Dim::dim::() * Dim::dim::() } + #[inline(always)] fn from_flattened(l: &[N], off: uint) -> NMat { let dim = Dim::dim::(); @@ -186,6 +202,7 @@ impl Flatten for NMat res } + #[inline(always)] fn flatten(&self) -> ~[N] { let dim = Dim::dim::(); @@ -197,6 +214,7 @@ impl Flatten for NMat res } + #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { let dim = Dim::dim::(); diff --git a/src/ndim/nvec.rs b/src/ndim/nvec.rs index c9c656e4..a1185847 100644 --- a/src/ndim/nvec.rs +++ b/src/ndim/nvec.rs @@ -28,30 +28,35 @@ pub struct NVec impl Dim for NVec { + #[inline(always)] fn dim() -> uint { Dim::dim::() } } impl Clone for NVec { + #[inline(always)] fn clone(&self) -> NVec { NVec{ at: self.at.clone() } } } impl> Add, NVec> for NVec { + #[inline(always)] fn add(&self, other: &NVec) -> NVec { NVec { at: self.at + other.at } } } impl> Sub, NVec> for NVec { + #[inline(always)] fn sub(&self, other: &NVec) -> NVec { NVec { at: self.at - other.at } } } impl> Neg> for NVec { + #[inline(always)] fn neg(&self) -> NVec { NVec { at: -self.at } } } @@ -59,12 +64,14 @@ impl> Neg> for NVec impl Dot for NVec { + #[inline(always)] fn dot(&self, other: &NVec) -> N { self.at.dot(&other.at) } } impl SubDot for NVec { + #[inline(always)] fn sub_dot(&self, a: &NVec, b: &NVec) -> N { self.at.sub_dot(&a.at, &b.at) } } @@ -72,9 +79,11 @@ impl SubDot for NVec impl> ScalarMul for NVec { + #[inline(always)] fn scalar_mul(&self, s: &N) -> NVec { NVec { at: self.at.scalar_mul(s) } } + #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) { self.at.scalar_mul_inplace(s) } } @@ -83,9 +92,11 @@ ScalarMul for NVec impl> ScalarDiv for NVec { + #[inline(always)] fn scalar_div(&self, s: &N) -> NVec { NVec { at: self.at.scalar_div(s) } } + #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) { self.at.scalar_div_inplace(s) } } @@ -93,9 +104,11 @@ ScalarDiv for NVec impl> ScalarAdd for NVec { + #[inline(always)] fn scalar_add(&self, s: &N) -> NVec { NVec { at: self.at.scalar_add(s) } } + #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) { self.at.scalar_add_inplace(s) } } @@ -103,21 +116,26 @@ ScalarAdd for NVec impl> ScalarSub for NVec { + #[inline(always)] fn scalar_sub(&self, s: &N) -> NVec { NVec { at: self.at.scalar_sub(s) } } + #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) { self.scalar_sub_inplace(s) } } impl> Translation> for NVec { + #[inline(always)] fn translation(&self) -> NVec { self.clone() } + #[inline(always)] fn translated(&self, t: &NVec) -> NVec { self + *t } + #[inline(always)] fn translate(&mut self, t: &NVec) { *self = *self + *t; } } @@ -125,12 +143,15 @@ impl> Translation> for NVec impl Norm for NVec { + #[inline(always)] fn sqnorm(&self) -> N { self.dot(self) } + #[inline(always)] fn norm(&self) -> N { self.sqnorm().sqrt() } + #[inline(always)] fn normalized(&self) -> NVec { let mut res : NVec = self.clone(); @@ -140,6 +161,7 @@ Norm for NVec res } + #[inline(always)] fn normalize(&mut self) -> N { self.at.normalize() } } @@ -148,9 +170,11 @@ impl> Basis for NVec { + #[inline(always)] fn canonical_basis() -> ~[NVec] { map(DVec::canonical_basis_with_dim(Dim::dim::()), |&e| NVec { at: e }) } + #[inline(always)] fn orthogonal_subspace_basis(&self) -> ~[NVec] { map(self.at.orthogonal_subspace_basis(), |&e| NVec { at: e }) } } @@ -165,27 +189,33 @@ Basis for NVec impl Zero for NVec { + #[inline(always)] fn zero() -> NVec { NVec { at: zero_vec_with_dim(Dim::dim::()) } } + #[inline(always)] fn is_zero(&self) -> bool { is_zero_vec(&self.at) } } impl> ApproxEq for NVec { + #[inline(always)] fn approx_epsilon() -> N { ApproxEq::approx_epsilon::() } + #[inline(always)] fn approx_eq(&self, other: &NVec) -> bool { self.at.approx_eq(&other.at) } + #[inline(always)] fn approx_eq_eps(&self, other: &NVec, epsilon: &N) -> bool { self.at.approx_eq_eps(&other.at, epsilon) } } impl Rand for NVec { + #[inline(always)] fn rand(rng: &mut R) -> NVec { let dim = Dim::dim::(); @@ -200,9 +230,11 @@ impl Rand for NVec impl Flatten for NVec { + #[inline(always)] fn flat_size() -> uint { Dim::dim::() } + #[inline(always)] fn from_flattened(l: &[N], off: uint) -> NVec { let dim = Dim::dim::(); @@ -214,6 +246,7 @@ impl Flatten for NVec res } + #[inline(always)] fn flatten(&self) -> ~[N] { let dim = Dim::dim::(); @@ -225,6 +258,7 @@ impl Flatten for NVec res } + #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { let dim = Dim::dim::(); diff --git a/src/tests/mat.rs b/src/tests/mat.rs index afd49981..c4ff87fd 100644 --- a/src/tests/mat.rs +++ b/src/tests/mat.rs @@ -45,9 +45,9 @@ macro_rules! test_flatten_impl( let v: $t = random(); let mut l: ~[$n] = vec::from_elem(42 + Flatten::flat_size::<$n, $t>(), Zero::zero::<$n>()); - v.to_flattened_inplace(l, 42); + v.flatten_to(l, 42); - assert!(Flatten::from_flattened::<$n, $t>(v.to_flattened(), 0) == v); + assert!(Flatten::from_flattened::<$n, $t>(v.flatten(), 0) == v); assert!(Flatten::from_flattened::<$n, $t>(l, 42) == v); } ) diff --git a/src/tests/vec.rs b/src/tests/vec.rs index 4dc9f479..97464422 100644 --- a/src/tests/vec.rs +++ b/src/tests/vec.rs @@ -86,9 +86,9 @@ macro_rules! test_flatten_impl( let v: $t = random(); let mut l: ~[$n] = vec::from_elem(42 + Flatten::flat_size::<$n, $t>(), Zero::zero::<$n>()); - v.to_flattened_inplace(l, 42); + v.flatten_to(l, 42); - assert!(Flatten::from_flattened::<$n, $t>(v.to_flattened(), 0) == v); + assert!(Flatten::from_flattened::<$n, $t>(v.flatten(), 0) == v); assert!(Flatten::from_flattened::<$n, $t>(l, 42) == v); } ) diff --git a/src/traits/rotation.rs b/src/traits/rotation.rs index bf4a9e37..060d05ca 100644 --- a/src/traits/rotation.rs +++ b/src/traits/rotation.rs @@ -23,6 +23,7 @@ pub trait Rotation * - `ammount`: the rotation to apply. * - `point`: the center of rotation. */ +#[inline(always)] pub fn rotate_wrt_point + Translation, LV: Neg, AV> (m: &M, ammount: &AV, center: &LV) -> M {