#[inline(always)] -> #[inline]

This commit is contained in:
Sébastien Crozet 2013-06-27 17:40:37 +00:00
parent 6723693b49
commit 8abcdeeedc
13 changed files with 306 additions and 306 deletions

View File

@ -59,11 +59,11 @@ pub fn rotmat3<N: Copy + Trigonometric + Neg<N> + One + Sub<N, N> + Add<N, N> +
impl<N: Div<N, N> + Trigonometric + Neg<N> + Mul<N, N> + Add<N, N> + Copy> impl<N: Div<N, N> + Trigonometric + Neg<N> + Mul<N, N> + Add<N, N> + Copy>
Rotation<Vec1<N>> for Rotmat<Mat2<N>> Rotation<Vec1<N>> for Rotmat<Mat2<N>>
{ {
#[inline(always)] #[inline]
fn rotation(&self) -> Vec1<N> fn rotation(&self) -> Vec1<N>
{ Vec1::new(-(self.submat.m12 / self.submat.m11).atan()) } { Vec1::new(-(self.submat.m12 / self.submat.m11).atan()) }
#[inline(always)] #[inline]
fn rotate(&mut self, rot: &Vec1<N>) fn rotate(&mut self, rot: &Vec1<N>)
{ *self = self.rotated(rot) } { *self = self.rotated(rot) }
} }
@ -71,7 +71,7 @@ Rotation<Vec1<N>> for Rotmat<Mat2<N>>
impl<N: Div<N, N> + Trigonometric + Neg<N> + Mul<N, N> + Add<N, N> + Copy> impl<N: Div<N, N> + Trigonometric + Neg<N> + Mul<N, N> + Add<N, N> + Copy>
Rotatable<Vec1<N>, Rotmat<Mat2<N>>> for Rotmat<Mat2<N>> Rotatable<Vec1<N>, Rotmat<Mat2<N>>> for Rotmat<Mat2<N>>
{ {
#[inline(always)] #[inline]
fn rotated(&self, rot: &Vec1<N>) -> Rotmat<Mat2<N>> fn rotated(&self, rot: &Vec1<N>) -> Rotmat<Mat2<N>>
{ rotmat2(copy rot.x) * *self } { rotmat2(copy rot.x) * *self }
} }
@ -80,11 +80,11 @@ impl<N: Div<N, N> + Trigonometric + Neg<N> + Mul<N, N> + Add<N, N> + Copy +
One + Sub<N, N>> One + Sub<N, N>>
Rotation<(Vec3<N>, N)> for Rotmat<Mat3<N>> Rotation<(Vec3<N>, N)> for Rotmat<Mat3<N>>
{ {
#[inline(always)] #[inline]
fn rotation(&self) -> (Vec3<N>, N) fn rotation(&self) -> (Vec3<N>, N)
{ fail!("Not yet implemented.") } { fail!("Not yet implemented.") }
#[inline(always)] #[inline]
fn rotate(&mut self, rot: &(Vec3<N>, N)) fn rotate(&mut self, rot: &(Vec3<N>, N))
{ *self = self.rotated(rot) } { *self = self.rotated(rot) }
} }
@ -93,14 +93,14 @@ impl<N: Div<N, N> + Trigonometric + Neg<N> + Mul<N, N> + Add<N, N> + Copy +
One + Sub<N, N>> One + Sub<N, N>>
Rotatable<(Vec3<N>, N), Rotmat<Mat3<N>>> for Rotmat<Mat3<N>> Rotatable<(Vec3<N>, N), Rotmat<Mat3<N>>> for Rotmat<Mat3<N>>
{ {
#[inline(always)] #[inline]
fn rotated(&self, &(axis, angle): &(Vec3<N>, N)) -> Rotmat<Mat3<N>> fn rotated(&self, &(axis, angle): &(Vec3<N>, N)) -> Rotmat<Mat3<N>>
{ rotmat3(&axis, angle) * *self } { rotmat3(&axis, angle) * *self }
} }
impl<N: Copy + Rand + Trigonometric + Neg<N>> Rand for Rotmat<Mat2<N>> impl<N: Copy + Rand + Trigonometric + Neg<N>> Rand for Rotmat<Mat2<N>>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Rotmat<Mat2<N>> fn rand<R: Rng>(rng: &mut R) -> Rotmat<Mat2<N>>
{ rotmat2(rng.gen()) } { rotmat2(rng.gen()) }
} }
@ -109,67 +109,67 @@ impl<N: Copy + Rand + Trigonometric + Neg<N> + One + Sub<N, N> + Add<N, N> +
Mul<N, N>> Mul<N, N>>
Rand for Rotmat<Mat3<N>> Rand for Rotmat<Mat3<N>>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Rotmat<Mat3<N>> fn rand<R: Rng>(rng: &mut R) -> Rotmat<Mat3<N>>
{ rotmat3(&rng.gen(), rng.gen()) } { rotmat3(&rng.gen(), rng.gen()) }
} }
impl<M: Dim> Dim for Rotmat<M> impl<M: Dim> Dim for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ Dim::dim::<M>() } { Dim::dim::<M>() }
} }
impl<M: One + Zero> One for Rotmat<M> impl<M: One + Zero> One for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn one() -> Rotmat<M> fn one() -> Rotmat<M>
{ Rotmat { submat: One::one() } } { Rotmat { submat: One::one() } }
} }
impl<M: Mul<M, M>> Mul<Rotmat<M>, Rotmat<M>> for Rotmat<M> impl<M: Mul<M, M>> Mul<Rotmat<M>, Rotmat<M>> for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn mul(&self, other: &Rotmat<M>) -> Rotmat<M> fn mul(&self, other: &Rotmat<M>) -> Rotmat<M>
{ Rotmat { submat: self.submat.mul(&other.submat) } } { Rotmat { submat: self.submat.mul(&other.submat) } }
} }
impl<V, M: RMul<V>> RMul<V> for Rotmat<M> impl<V, M: RMul<V>> RMul<V> for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn rmul(&self, other: &V) -> V fn rmul(&self, other: &V) -> V
{ self.submat.rmul(other) } { self.submat.rmul(other) }
} }
impl<V, M: LMul<V>> LMul<V> for Rotmat<M> impl<V, M: LMul<V>> LMul<V> for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn lmul(&self, other: &V) -> V fn lmul(&self, other: &V) -> V
{ self.submat.lmul(other) } { self.submat.lmul(other) }
} }
impl<M: Copy> DeltaTransform<M> for Rotmat<M> impl<M: Copy> DeltaTransform<M> for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn delta_transform(&self) -> M fn delta_transform(&self) -> M
{ copy self.submat } { copy self.submat }
} }
impl<M: RMul<V>, V> DeltaTransformVector<V> for Rotmat<M> impl<M: RMul<V>, V> DeltaTransformVector<V> for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn delta_transform_vector(&self, v: &V) -> V fn delta_transform_vector(&self, v: &V) -> V
{ self.submat.rmul(v) } { self.submat.rmul(v) }
} }
impl<M: Transpose> Inv for Rotmat<M> impl<M: Transpose> Inv for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn invert(&mut self) fn invert(&mut self)
{ self.transpose() } { self.transpose() }
#[inline(always)] #[inline]
fn inverse(&self) -> Rotmat<M> fn inverse(&self) -> Rotmat<M>
{ self.transposed() } { self.transposed() }
} }
@ -177,26 +177,26 @@ impl<M: Transpose> Inv for Rotmat<M>
impl<M: Transpose> impl<M: Transpose>
Transpose for Rotmat<M> Transpose for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn transposed(&self) -> Rotmat<M> fn transposed(&self) -> Rotmat<M>
{ Rotmat { submat: self.submat.transposed() } } { Rotmat { submat: self.submat.transposed() } }
#[inline(always)] #[inline]
fn transpose(&mut self) fn transpose(&mut self)
{ self.submat.transpose() } { self.submat.transpose() }
} }
impl<N: ApproxEq<N>, M: ApproxEq<N>> ApproxEq<N> for Rotmat<M> impl<N: ApproxEq<N>, M: ApproxEq<N>> ApproxEq<N> for Rotmat<M>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &Rotmat<M>) -> bool fn approx_eq(&self, other: &Rotmat<M>) -> bool
{ self.submat.approx_eq(&other.submat) } { self.submat.approx_eq(&other.submat) }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &Rotmat<M>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &Rotmat<M>, epsilon: &N) -> bool
{ self.submat.approx_eq_eps(&other.submat, epsilon) } { self.submat.approx_eq_eps(&other.submat, epsilon) }
} }

View File

@ -19,32 +19,32 @@ pub struct Transform<M, V>
impl<M, V> Transform<M, V> impl<M, V> Transform<M, V>
{ {
#[inline(always)] #[inline]
pub fn new(mat: M, trans: V) -> Transform<M, V> pub fn new(mat: M, trans: V) -> Transform<M, V>
{ Transform { submat: mat, subtrans: trans } } { Transform { submat: mat, subtrans: trans } }
} }
impl<M:Dim, V> Dim for Transform<M, V> impl<M:Dim, V> Dim for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ Dim::dim::<M>() } { Dim::dim::<M>() }
} }
impl<M: One, V: Zero> One for Transform<M, V> impl<M: One, V: Zero> One for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn one() -> Transform<M, V> fn one() -> Transform<M, V>
{ Transform { submat: One::one(), subtrans: Zero::zero() } } { Transform { submat: One::one(), subtrans: Zero::zero() } }
} }
impl<M: Zero, V: Zero> Zero for Transform<M, V> impl<M: Zero, V: Zero> Zero for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn zero() -> Transform<M, V> fn zero() -> Transform<M, V>
{ Transform { submat: Zero::zero(), subtrans: Zero::zero() } } { Transform { submat: Zero::zero(), subtrans: Zero::zero() } }
#[inline(always)] #[inline]
fn is_zero(&self) -> bool fn is_zero(&self) -> bool
{ self.submat.is_zero() && self.subtrans.is_zero() } { self.submat.is_zero() && self.subtrans.is_zero() }
} }
@ -52,7 +52,7 @@ impl<M: Zero, V: Zero> Zero for Transform<M, V>
impl<M: RMul<V> + Mul<M, M>, V: Add<V, V>> impl<M: RMul<V> + Mul<M, M>, V: Add<V, V>>
Mul<Transform<M, V>, Transform<M, V>> for Transform<M, V> Mul<Transform<M, V>, Transform<M, V>> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn mul(&self, other: &Transform<M, V>) -> Transform<M, V> fn mul(&self, other: &Transform<M, V>) -> Transform<M, V>
{ {
Transform { submat: self.submat * other.submat, Transform { submat: self.submat * other.submat,
@ -62,25 +62,25 @@ Mul<Transform<M, V>, Transform<M, V>> for Transform<M, V>
impl<M: RMul<V>, V: Add<V, V>> RMul<V> for Transform<M, V> impl<M: RMul<V>, V: Add<V, V>> RMul<V> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn rmul(&self, other: &V) -> V fn rmul(&self, other: &V) -> V
{ self.submat.rmul(other) + self.subtrans } { self.submat.rmul(other) + self.subtrans }
} }
impl<M: LMul<V>, V: Add<V, V>> LMul<V> for Transform<M, V> impl<M: LMul<V>, V: Add<V, V>> LMul<V> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn lmul(&self, other: &V) -> V fn lmul(&self, other: &V) -> V
{ self.submat.lmul(other) + self.subtrans } { self.submat.lmul(other) + self.subtrans }
} }
impl<M, V: Translation<V>> Translation<V> for Transform<M, V> impl<M, V: Translation<V>> Translation<V> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn translation(&self) -> V fn translation(&self) -> V
{ self.subtrans.translation() } { self.subtrans.translation() }
#[inline(always)] #[inline]
fn translate(&mut self, t: &V) fn translate(&mut self, t: &V)
{ self.subtrans.translate(t) } { self.subtrans.translate(t) }
} }
@ -88,7 +88,7 @@ impl<M, V: Translation<V>> Translation<V> for Transform<M, V>
impl<M: Copy, V: Translatable<V, Res>, Res: Translation<V>> impl<M: Copy, V: Translatable<V, Res>, Res: Translation<V>>
Translatable<V, Transform<M, Res>> for Transform<M, V> Translatable<V, Transform<M, Res>> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn translated(&self, t: &V) -> Transform<M, Res> fn translated(&self, t: &V) -> Transform<M, Res>
{ Transform::new(copy self.submat, self.subtrans.translated(t)) } { Transform::new(copy self.submat, self.subtrans.translated(t)) }
} }
@ -98,11 +98,11 @@ impl<M: Rotation<AV> + RMul<V> + One,
AV> AV>
Rotation<AV> for Transform<M, V> Rotation<AV> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn rotation(&self) -> AV fn rotation(&self) -> AV
{ self.submat.rotation() } { self.submat.rotation() }
#[inline(always)] #[inline]
fn rotate(&mut self, rot: &AV) fn rotate(&mut self, rot: &AV)
{ {
// FIXME: this does not seem opitmal // FIXME: this does not seem opitmal
@ -119,7 +119,7 @@ impl<M: Rotatable<AV, Res> + One,
AV> AV>
Rotatable<AV, Transform<Res, V>> for Transform<M, V> Rotatable<AV, Transform<Res, V>> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn rotated(&self, rot: &AV) -> Transform<Res, V> fn rotated(&self, rot: &AV) -> Transform<Res, V>
{ {
// FIXME: this does not seem opitmal // FIXME: this does not seem opitmal
@ -149,14 +149,14 @@ Transformable<Transform<M, V>, Transform<M, V>> for Transform<M, V>
impl<M: Copy, V> DeltaTransform<M> for Transform<M, V> impl<M: Copy, V> DeltaTransform<M> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn delta_transform(&self) -> M fn delta_transform(&self) -> M
{ copy self.submat } { copy self.submat }
} }
impl<M: RMul<V>, V> DeltaTransformVector<V> for Transform<M, V> impl<M: RMul<V>, V> DeltaTransformVector<V> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn delta_transform_vector(&self, v: &V) -> V fn delta_transform_vector(&self, v: &V) -> V
{ self.submat.rmul(v) } { self.submat.rmul(v) }
} }
@ -164,14 +164,14 @@ impl<M: RMul<V>, V> DeltaTransformVector<V> for Transform<M, V>
impl<M:Copy + Transpose + Inv + RMul<V>, V: Copy + Neg<V>> impl<M:Copy + Transpose + Inv + RMul<V>, V: Copy + Neg<V>>
Inv for Transform<M, V> Inv for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn invert(&mut self) fn invert(&mut self)
{ {
self.submat.invert(); self.submat.invert();
self.subtrans = self.submat.rmul(&-self.subtrans); self.subtrans = self.submat.rmul(&-self.subtrans);
} }
#[inline(always)] #[inline]
fn inverse(&self) -> Transform<M, V> fn inverse(&self) -> Transform<M, V>
{ {
let mut res = copy *self; let mut res = copy *self;
@ -185,18 +185,18 @@ Inv for Transform<M, V>
impl<N: ApproxEq<N>, M:ApproxEq<N>, V:ApproxEq<N>> impl<N: ApproxEq<N>, M:ApproxEq<N>, V:ApproxEq<N>>
ApproxEq<N> for Transform<M, V> ApproxEq<N> for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &Transform<M, V>) -> bool fn approx_eq(&self, other: &Transform<M, V>) -> bool
{ {
self.submat.approx_eq(&other.submat) && self.submat.approx_eq(&other.submat) &&
self.subtrans.approx_eq(&other.subtrans) self.subtrans.approx_eq(&other.subtrans)
} }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &Transform<M, V>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &Transform<M, V>, epsilon: &N) -> bool
{ {
self.submat.approx_eq_eps(&other.submat, epsilon) && self.submat.approx_eq_eps(&other.submat, epsilon) &&
@ -206,7 +206,7 @@ ApproxEq<N> for Transform<M, V>
impl<M: Rand, V: Rand> Rand for Transform<M, V> impl<M: Rand, V: Rand> Rand for Transform<M, V>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Transform<M, V> fn rand<R: Rng>(rng: &mut R) -> Transform<M, V>
{ Transform::new(rng.gen(), rng.gen()) } { Transform::new(rng.gen(), rng.gen()) }
} }

View File

@ -14,7 +14,7 @@ pub struct Mat1<N>
impl<N> Mat1<N> impl<N> Mat1<N>
{ {
#[inline(always)] #[inline]
pub fn new(m11: N) -> Mat1<N> pub fn new(m11: N) -> Mat1<N>
{ {
Mat1 Mat1
@ -24,46 +24,46 @@ impl<N> Mat1<N>
impl<N> Dim for Mat1<N> impl<N> Dim for Mat1<N>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ 1 } { 1 }
} }
impl<N: One> One for Mat1<N> impl<N: One> One for Mat1<N>
{ {
#[inline(always)] #[inline]
fn one() -> Mat1<N> fn one() -> Mat1<N>
{ return Mat1::new(One::one()) } { return Mat1::new(One::one()) }
} }
impl<N: Zero> Zero for Mat1<N> impl<N: Zero> Zero for Mat1<N>
{ {
#[inline(always)] #[inline]
fn zero() -> Mat1<N> fn zero() -> Mat1<N>
{ Mat1::new(Zero::zero()) } { Mat1::new(Zero::zero()) }
#[inline(always)] #[inline]
fn is_zero(&self) -> bool fn is_zero(&self) -> bool
{ self.m11.is_zero() } { self.m11.is_zero() }
} }
impl<N: Mul<N, N> + Add<N, N>> Mul<Mat1<N>, Mat1<N>> for Mat1<N> impl<N: Mul<N, N> + Add<N, N>> Mul<Mat1<N>, Mat1<N>> for Mat1<N>
{ {
#[inline(always)] #[inline]
fn mul(&self, other: &Mat1<N>) -> Mat1<N> fn mul(&self, other: &Mat1<N>) -> Mat1<N>
{ Mat1::new(self.m11 * other.m11) } { Mat1::new(self.m11 * other.m11) }
} }
impl<N: Add<N, N> + Mul<N, N>> RMul<Vec1<N>> for Mat1<N> impl<N: Add<N, N> + Mul<N, N>> RMul<Vec1<N>> for Mat1<N>
{ {
#[inline(always)] #[inline]
fn rmul(&self, other: &Vec1<N>) -> Vec1<N> fn rmul(&self, other: &Vec1<N>) -> Vec1<N>
{ Vec1::new(self.m11 * other.x) } { Vec1::new(self.m11 * other.x) }
} }
impl<N: Add<N, N> + Mul<N, N>> LMul<Vec1<N>> for Mat1<N> impl<N: Add<N, N> + Mul<N, N>> LMul<Vec1<N>> for Mat1<N>
{ {
#[inline(always)] #[inline]
fn lmul(&self, other: &Vec1<N>) -> Vec1<N> fn lmul(&self, other: &Vec1<N>) -> Vec1<N>
{ Vec1::new(self.m11 * other.x) } { Vec1::new(self.m11 * other.x) }
} }
@ -71,7 +71,7 @@ impl<N: Add<N, N> + Mul<N, N>> LMul<Vec1<N>> for Mat1<N>
impl<N:Copy + Mul<N, N> + Div<N, N> + Sub<N, N> + Neg<N> + Zero + One> impl<N:Copy + Mul<N, N> + Div<N, N> + Sub<N, N> + Neg<N> + Zero + One>
Inv for Mat1<N> Inv for Mat1<N>
{ {
#[inline(always)] #[inline]
fn inverse(&self) -> Mat1<N> fn inverse(&self) -> Mat1<N>
{ {
let mut res : Mat1<N> = copy *self; let mut res : Mat1<N> = copy *self;
@ -81,7 +81,7 @@ Inv for Mat1<N>
res res
} }
#[inline(always)] #[inline]
fn invert(&mut self) fn invert(&mut self)
{ {
assert!(!self.m11.is_zero()); assert!(!self.m11.is_zero());
@ -92,52 +92,52 @@ Inv for Mat1<N>
impl<N: Copy> Transpose for Mat1<N> impl<N: Copy> Transpose for Mat1<N>
{ {
#[inline(always)] #[inline]
fn transposed(&self) -> Mat1<N> fn transposed(&self) -> Mat1<N>
{ copy *self } { copy *self }
#[inline(always)] #[inline]
fn transpose(&mut self) fn transpose(&mut self)
{ } { }
} }
impl<N:ApproxEq<N>> ApproxEq<N> for Mat1<N> impl<N:ApproxEq<N>> ApproxEq<N> for Mat1<N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &Mat1<N>) -> bool fn approx_eq(&self, other: &Mat1<N>) -> bool
{ self.m11.approx_eq(&other.m11) } { self.m11.approx_eq(&other.m11) }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &Mat1<N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &Mat1<N>, epsilon: &N) -> bool
{ self.m11.approx_eq_eps(&other.m11, epsilon) } { self.m11.approx_eq_eps(&other.m11, epsilon) }
} }
impl<N: Rand > Rand for Mat1<N> impl<N: Rand > Rand for Mat1<N>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Mat1<N> fn rand<R: Rng>(rng: &mut R) -> Mat1<N>
{ Mat1::new(rng.gen()) } { Mat1::new(rng.gen()) }
} }
impl<N: Copy> Flatten<N> for Mat1<N> impl<N: Copy> Flatten<N> for Mat1<N>
{ {
#[inline(always)] #[inline]
fn flat_size() -> uint fn flat_size() -> uint
{ 1 } { 1 }
#[inline(always)] #[inline]
fn from_flattened(l: &[N], off: uint) -> Mat1<N> fn from_flattened(l: &[N], off: uint) -> Mat1<N>
{ Mat1::new(copy l[off]) } { Mat1::new(copy l[off]) }
#[inline(always)] #[inline]
fn flatten(&self) -> ~[N] fn flatten(&self) -> ~[N]
{ ~[ copy self.m11 ] } { ~[ copy self.m11 ] }
#[inline(always)] #[inline]
fn flatten_to(&self, l: &mut [N], off: uint) fn flatten_to(&self, l: &mut [N], off: uint)
{ l[off] = copy self.m11 } { l[off] = copy self.m11 }
} }

View File

@ -16,28 +16,28 @@ pub struct Vec1<N>
impl<N> Vec1<N> impl<N> Vec1<N>
{ {
#[inline(always)] #[inline]
pub fn new(x: N) -> Vec1<N> pub fn new(x: N) -> Vec1<N>
{ Vec1 {x: x} } { Vec1 {x: x} }
} }
impl<N> Dim for Vec1<N> impl<N> Dim for Vec1<N>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ 1 } { 1 }
} }
impl<N: Add<N, N>> Add<Vec1<N>, Vec1<N>> for Vec1<N> impl<N: Add<N, N>> Add<Vec1<N>, Vec1<N>> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn add(&self, other: &Vec1<N>) -> Vec1<N> fn add(&self, other: &Vec1<N>) -> Vec1<N>
{ Vec1::new(self.x + other.x) } { Vec1::new(self.x + other.x) }
} }
impl<N: Sub<N, N>> Sub<Vec1<N>, Vec1<N>> for Vec1<N> impl<N: Sub<N, N>> Sub<Vec1<N>, Vec1<N>> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn sub(&self, other: &Vec1<N>) -> Vec1<N> fn sub(&self, other: &Vec1<N>) -> Vec1<N>
{ Vec1::new(self.x - other.x) } { Vec1::new(self.x - other.x) }
} }
@ -45,11 +45,11 @@ impl<N: Sub<N, N>> Sub<Vec1<N>, Vec1<N>> for Vec1<N>
impl<N: Mul<N, N>> impl<N: Mul<N, N>>
ScalarMul<N> for Vec1<N> ScalarMul<N> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn scalar_mul(&self, s: &N) -> Vec1<N> fn scalar_mul(&self, s: &N) -> Vec1<N>
{ Vec1 { x: self.x * *s } } { Vec1 { x: self.x * *s } }
#[inline(always)] #[inline]
fn scalar_mul_inplace(&mut self, s: &N) fn scalar_mul_inplace(&mut self, s: &N)
{ self.x = self.x * *s; } { self.x = self.x * *s; }
} }
@ -58,11 +58,11 @@ ScalarMul<N> for Vec1<N>
impl<N: Div<N, N>> impl<N: Div<N, N>>
ScalarDiv<N> for Vec1<N> ScalarDiv<N> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn scalar_div(&self, s: &N) -> Vec1<N> fn scalar_div(&self, s: &N) -> Vec1<N>
{ Vec1 { x: self.x / *s } } { Vec1 { x: self.x / *s } }
#[inline(always)] #[inline]
fn scalar_div_inplace(&mut self, s: &N) fn scalar_div_inplace(&mut self, s: &N)
{ self.x = self.x / *s; } { self.x = self.x / *s; }
} }
@ -70,11 +70,11 @@ ScalarDiv<N> for Vec1<N>
impl<N: Add<N, N>> impl<N: Add<N, N>>
ScalarAdd<N> for Vec1<N> ScalarAdd<N> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn scalar_add(&self, s: &N) -> Vec1<N> fn scalar_add(&self, s: &N) -> Vec1<N>
{ Vec1 { x: self.x + *s } } { Vec1 { x: self.x + *s } }
#[inline(always)] #[inline]
fn scalar_add_inplace(&mut self, s: &N) fn scalar_add_inplace(&mut self, s: &N)
{ self.x = self.x + *s; } { self.x = self.x + *s; }
} }
@ -82,43 +82,43 @@ ScalarAdd<N> for Vec1<N>
impl<N: Sub<N, N>> impl<N: Sub<N, N>>
ScalarSub<N> for Vec1<N> ScalarSub<N> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn scalar_sub(&self, s: &N) -> Vec1<N> fn scalar_sub(&self, s: &N) -> Vec1<N>
{ Vec1 { x: self.x - *s } } { Vec1 { x: self.x - *s } }
#[inline(always)] #[inline]
fn scalar_sub_inplace(&mut self, s: &N) fn scalar_sub_inplace(&mut self, s: &N)
{ self.x = self.x - *s; } { self.x = self.x - *s; }
} }
impl<N: Copy + Add<N, N>> Translation<Vec1<N>> for Vec1<N> impl<N: Copy + Add<N, N>> Translation<Vec1<N>> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn translation(&self) -> Vec1<N> fn translation(&self) -> Vec1<N>
{ copy *self } { copy *self }
#[inline(always)] #[inline]
fn translate(&mut self, t: &Vec1<N>) fn translate(&mut self, t: &Vec1<N>)
{ *self = *self + *t } { *self = *self + *t }
} }
impl<N: Add<N, N>> Translatable<Vec1<N>, Vec1<N>> for Vec1<N> impl<N: Add<N, N>> Translatable<Vec1<N>, Vec1<N>> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn translated(&self, t: &Vec1<N>) -> Vec1<N> fn translated(&self, t: &Vec1<N>) -> Vec1<N>
{ self + *t } { self + *t }
} }
impl<N: Mul<N, N>> Dot<N> for Vec1<N> impl<N: Mul<N, N>> Dot<N> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn dot(&self, other : &Vec1<N>) -> N fn dot(&self, other : &Vec1<N>) -> N
{ self.x * other.x } { self.x * other.x }
} }
impl<N: Mul<N, N> + Sub<N, N>> SubDot<N> for Vec1<N> impl<N: Mul<N, N> + Sub<N, N>> SubDot<N> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn sub_dot(&self, a: &Vec1<N>, b: &Vec1<N>) -> N fn sub_dot(&self, a: &Vec1<N>, b: &Vec1<N>) -> N
{ (self.x - a.x) * b.x } { (self.x - a.x) * b.x }
} }
@ -126,19 +126,19 @@ impl<N: Mul<N, N> + Sub<N, N>> SubDot<N> for Vec1<N>
impl<N: Mul<N, N> + Add<N, N> + Div<N, N> + Algebraic> impl<N: Mul<N, N> + Add<N, N> + Div<N, N> + Algebraic>
Norm<N> for Vec1<N> Norm<N> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn sqnorm(&self) -> N fn sqnorm(&self) -> N
{ self.dot(self) } { self.dot(self) }
#[inline(always)] #[inline]
fn norm(&self) -> N fn norm(&self) -> N
{ self.sqnorm().sqrt() } { self.sqnorm().sqrt() }
#[inline(always)] #[inline]
fn normalized(&self) -> Vec1<N> fn normalized(&self) -> Vec1<N>
{ Vec1::new(self.x / self.norm()) } { Vec1::new(self.x / self.norm()) }
#[inline(always)] #[inline]
fn normalize(&mut self) -> N fn normalize(&mut self) -> N
{ {
let l = self.norm(); let l = self.norm();
@ -151,84 +151,84 @@ Norm<N> for Vec1<N>
impl<N: Neg<N>> Neg<Vec1<N>> for Vec1<N> impl<N: Neg<N>> Neg<Vec1<N>> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn neg(&self) -> Vec1<N> fn neg(&self) -> Vec1<N>
{ Vec1::new(-self.x) } { Vec1::new(-self.x) }
} }
impl<N: Zero> Zero for Vec1<N> impl<N: Zero> Zero for Vec1<N>
{ {
#[inline(always)] #[inline]
fn zero() -> Vec1<N> fn zero() -> Vec1<N>
{ {
let _0 = Zero::zero(); let _0 = Zero::zero();
Vec1::new(_0) Vec1::new(_0)
} }
#[inline(always)] #[inline]
fn is_zero(&self) -> bool fn is_zero(&self) -> bool
{ self.x.is_zero() } { self.x.is_zero() }
} }
impl<N: One> Basis for Vec1<N> impl<N: One> Basis for Vec1<N>
{ {
#[inline(always)] #[inline]
fn canonical_basis() -> ~[Vec1<N>] fn canonical_basis() -> ~[Vec1<N>]
{ ~[ Vec1::new(One::one()) ] } // FIXME: this should be static { ~[ Vec1::new(One::one()) ] } // FIXME: this should be static
#[inline(always)] #[inline]
fn orthogonal_subspace_basis(&self) -> ~[Vec1<N>] fn orthogonal_subspace_basis(&self) -> ~[Vec1<N>]
{ ~[] } { ~[] }
} }
impl<N:ApproxEq<N>> ApproxEq<N> for Vec1<N> impl<N:ApproxEq<N>> ApproxEq<N> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &Vec1<N>) -> bool fn approx_eq(&self, other: &Vec1<N>) -> bool
{ self.x.approx_eq(&other.x) } { self.x.approx_eq(&other.x) }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &Vec1<N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &Vec1<N>, epsilon: &N) -> bool
{ self.x.approx_eq_eps(&other.x, epsilon) } { self.x.approx_eq_eps(&other.x, epsilon) }
} }
impl<N: Rand> Rand for Vec1<N> impl<N: Rand> Rand for Vec1<N>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Vec1<N> fn rand<R: Rng>(rng: &mut R) -> Vec1<N>
{ Vec1::new(rng.gen()) } { Vec1::new(rng.gen()) }
} }
impl<N: Copy> Flatten<N> for Vec1<N> impl<N: Copy> Flatten<N> for Vec1<N>
{ {
#[inline(always)] #[inline]
fn flat_size() -> uint fn flat_size() -> uint
{ 1 } { 1 }
#[inline(always)] #[inline]
fn from_flattened(l: &[N], off: uint) -> Vec1<N> fn from_flattened(l: &[N], off: uint) -> Vec1<N>
{ Vec1::new(copy l[off]) } { Vec1::new(copy l[off]) }
#[inline(always)] #[inline]
fn flatten(&self) -> ~[N] fn flatten(&self) -> ~[N]
{ ~[ copy self.x ] } { ~[ copy self.x ] }
#[inline(always)] #[inline]
fn flatten_to(&self, l: &mut [N], off: uint) fn flatten_to(&self, l: &mut [N], off: uint)
{ l[off] = copy self.x } { l[off] = copy self.x }
} }
impl<N: Bounded> Bounded for Vec1<N> impl<N: Bounded> Bounded for Vec1<N>
{ {
#[inline(always)] #[inline]
fn max_value() -> Vec1<N> fn max_value() -> Vec1<N>
{ Vec1::new(Bounded::max_value()) } { Vec1::new(Bounded::max_value()) }
#[inline(always)] #[inline]
fn min_value() -> Vec1<N> fn min_value() -> Vec1<N>
{ Vec1::new(Bounded::min_value()) } { Vec1::new(Bounded::min_value()) }
} }

View File

@ -18,7 +18,7 @@ pub struct Mat2<N>
impl<N> Mat2<N> impl<N> Mat2<N>
{ {
#[inline(always)] #[inline]
pub fn new(m11: N, m12: N, m21: N, m22: N) -> Mat2<N> pub fn new(m11: N, m12: N, m21: N, m22: N) -> Mat2<N>
{ {
Mat2 Mat2
@ -31,14 +31,14 @@ impl<N> Mat2<N>
impl<N> Dim for Mat2<N> impl<N> Dim for Mat2<N>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ 2 } { 2 }
} }
impl<N: Copy + One + Zero> One for Mat2<N> impl<N: Copy + One + Zero> One for Mat2<N>
{ {
#[inline(always)] #[inline]
fn one() -> Mat2<N> fn one() -> Mat2<N>
{ {
let (_0, _1) = (Zero::zero(), One::one()); let (_0, _1) = (Zero::zero(), One::one());
@ -49,7 +49,7 @@ impl<N: Copy + One + Zero> One for Mat2<N>
impl<N:Copy + Zero> Zero for Mat2<N> impl<N:Copy + Zero> Zero for Mat2<N>
{ {
#[inline(always)] #[inline]
fn zero() -> Mat2<N> fn zero() -> Mat2<N>
{ {
let _0 = Zero::zero(); let _0 = Zero::zero();
@ -57,7 +57,7 @@ impl<N:Copy + Zero> Zero for Mat2<N>
copy _0, _0) copy _0, _0)
} }
#[inline(always)] #[inline]
fn is_zero(&self) -> bool fn is_zero(&self) -> bool
{ {
self.m11.is_zero() && self.m12.is_zero() && self.m11.is_zero() && self.m12.is_zero() &&
@ -67,7 +67,7 @@ impl<N:Copy + Zero> Zero for Mat2<N>
impl<N: Mul<N, N> + Add<N, N>> Mul<Mat2<N>, Mat2<N>> for Mat2<N> impl<N: Mul<N, N> + Add<N, N>> Mul<Mat2<N>, Mat2<N>> for Mat2<N>
{ {
#[inline(always)] #[inline]
fn mul(&self, other: &Mat2<N>) -> Mat2<N> fn mul(&self, other: &Mat2<N>) -> Mat2<N>
{ {
Mat2::new( Mat2::new(
@ -81,7 +81,7 @@ impl<N: Mul<N, N> + Add<N, N>> Mul<Mat2<N>, Mat2<N>> for Mat2<N>
impl<N: Add<N, N> + Mul<N, N>> RMul<Vec2<N>> for Mat2<N> impl<N: Add<N, N> + Mul<N, N>> RMul<Vec2<N>> for Mat2<N>
{ {
#[inline(always)] #[inline]
fn rmul(&self, other: &Vec2<N>) -> Vec2<N> fn rmul(&self, other: &Vec2<N>) -> Vec2<N>
{ {
Vec2::new( Vec2::new(
@ -93,7 +93,7 @@ impl<N: Add<N, N> + Mul<N, N>> RMul<Vec2<N>> for Mat2<N>
impl<N: Add<N, N> + Mul<N, N>> LMul<Vec2<N>> for Mat2<N> impl<N: Add<N, N> + Mul<N, N>> LMul<Vec2<N>> for Mat2<N>
{ {
#[inline(always)] #[inline]
fn lmul(&self, other: &Vec2<N>) -> Vec2<N> fn lmul(&self, other: &Vec2<N>) -> Vec2<N>
{ {
Vec2::new( Vec2::new(
@ -106,7 +106,7 @@ impl<N: Add<N, N> + Mul<N, N>> LMul<Vec2<N>> for Mat2<N>
impl<N:Copy + Mul<N, N> + Div<N, N> + Sub<N, N> + Neg<N> + Zero> impl<N:Copy + Mul<N, N> + Div<N, N> + Sub<N, N> + Neg<N> + Zero>
Inv for Mat2<N> Inv for Mat2<N>
{ {
#[inline(always)] #[inline]
fn inverse(&self) -> Mat2<N> fn inverse(&self) -> Mat2<N>
{ {
let mut res : Mat2<N> = copy *self; let mut res : Mat2<N> = copy *self;
@ -116,7 +116,7 @@ Inv for Mat2<N>
res res
} }
#[inline(always)] #[inline]
fn invert(&mut self) fn invert(&mut self)
{ {
let det = self.m11 * self.m22 - self.m21 * self.m12; let det = self.m11 * self.m22 - self.m21 * self.m12;
@ -130,25 +130,25 @@ Inv for Mat2<N>
impl<N: Copy> Transpose for Mat2<N> impl<N: Copy> Transpose for Mat2<N>
{ {
#[inline(always)] #[inline]
fn transposed(&self) -> Mat2<N> fn transposed(&self) -> Mat2<N>
{ {
Mat2::new(copy self.m11, copy self.m21, Mat2::new(copy self.m11, copy self.m21,
copy self.m12, copy self.m22) copy self.m12, copy self.m22)
} }
#[inline(always)] #[inline]
fn transpose(&mut self) fn transpose(&mut self)
{ swap(&mut self.m21, &mut self.m12); } { swap(&mut self.m21, &mut self.m12); }
} }
impl<N:ApproxEq<N>> ApproxEq<N> for Mat2<N> impl<N:ApproxEq<N>> ApproxEq<N> for Mat2<N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &Mat2<N>) -> bool fn approx_eq(&self, other: &Mat2<N>) -> bool
{ {
self.m11.approx_eq(&other.m11) && self.m11.approx_eq(&other.m11) &&
@ -158,7 +158,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Mat2<N>
self.m22.approx_eq(&other.m22) self.m22.approx_eq(&other.m22)
} }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &Mat2<N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &Mat2<N>, epsilon: &N) -> bool
{ {
self.m11.approx_eq_eps(&other.m11, epsilon) && self.m11.approx_eq_eps(&other.m11, epsilon) &&
@ -171,26 +171,26 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Mat2<N>
impl<N: Rand> Rand for Mat2<N> impl<N: Rand> Rand for Mat2<N>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Mat2<N> fn rand<R: Rng>(rng: &mut R) -> Mat2<N>
{ Mat2::new(rng.gen(), rng.gen(), rng.gen(), rng.gen()) } { Mat2::new(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
} }
impl<N: Copy> Flatten<N> for Mat2<N> impl<N: Copy> Flatten<N> for Mat2<N>
{ {
#[inline(always)] #[inline]
fn flat_size() -> uint fn flat_size() -> uint
{ 4 } { 4 }
#[inline(always)] #[inline]
fn from_flattened(l: &[N], off: uint) -> Mat2<N> fn from_flattened(l: &[N], off: uint) -> Mat2<N>
{ Mat2::new(copy l[off], copy l[off + 1], copy l[off + 2], copy l[off + 3]) } { Mat2::new(copy l[off], copy l[off + 1], copy l[off + 2], copy l[off + 3]) }
#[inline(always)] #[inline]
fn flatten(&self) -> ~[N] fn flatten(&self) -> ~[N]
{ ~[ copy self.m11, copy self.m12, copy self.m21, copy self.m22 ] } { ~[ copy self.m11, copy self.m12, copy self.m21, copy self.m22 ] }
#[inline(always)] #[inline]
fn flatten_to(&self, l: &mut [N], off: uint) fn flatten_to(&self, l: &mut [N], off: uint)
{ {
l[off] = copy self.m11; l[off] = copy self.m11;

View File

@ -21,28 +21,28 @@ pub struct Vec2<N>
impl<N> Vec2<N> impl<N> Vec2<N>
{ {
#[inline(always)] #[inline]
pub fn new(x: N, y: N) -> Vec2<N> pub fn new(x: N, y: N) -> Vec2<N>
{ Vec2 {x: x, y: y} } { Vec2 {x: x, y: y} }
} }
impl<N> Dim for Vec2<N> impl<N> Dim for Vec2<N>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ 2 } { 2 }
} }
impl<N: Add<N,N>> Add<Vec2<N>, Vec2<N>> for Vec2<N> impl<N: Add<N,N>> Add<Vec2<N>, Vec2<N>> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn add(&self, other: &Vec2<N>) -> Vec2<N> fn add(&self, other: &Vec2<N>) -> Vec2<N>
{ Vec2::new(self.x + other.x, self.y + other.y) } { Vec2::new(self.x + other.x, self.y + other.y) }
} }
impl<N: Sub<N,N>> Sub<Vec2<N>, Vec2<N>> for Vec2<N> impl<N: Sub<N,N>> Sub<Vec2<N>, Vec2<N>> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn sub(&self, other: &Vec2<N>) -> Vec2<N> fn sub(&self, other: &Vec2<N>) -> Vec2<N>
{ Vec2::new(self.x - other.x, self.y - other.y) } { Vec2::new(self.x - other.x, self.y - other.y) }
} }
@ -50,11 +50,11 @@ impl<N: Sub<N,N>> Sub<Vec2<N>, Vec2<N>> for Vec2<N>
impl<N: Mul<N, N>> impl<N: Mul<N, N>>
ScalarMul<N> for Vec2<N> ScalarMul<N> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn scalar_mul(&self, s: &N) -> Vec2<N> fn scalar_mul(&self, s: &N) -> Vec2<N>
{ Vec2 { x: self.x * *s, y: self.y * *s } } { Vec2 { x: self.x * *s, y: self.y * *s } }
#[inline(always)] #[inline]
fn scalar_mul_inplace(&mut self, s: &N) fn scalar_mul_inplace(&mut self, s: &N)
{ {
self.x = self.x * *s; self.x = self.x * *s;
@ -66,11 +66,11 @@ ScalarMul<N> for Vec2<N>
impl<N: Div<N, N>> impl<N: Div<N, N>>
ScalarDiv<N> for Vec2<N> ScalarDiv<N> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn scalar_div(&self, s: &N) -> Vec2<N> fn scalar_div(&self, s: &N) -> Vec2<N>
{ Vec2 { x: self.x / *s, y: self.y / *s } } { Vec2 { x: self.x / *s, y: self.y / *s } }
#[inline(always)] #[inline]
fn scalar_div_inplace(&mut self, s: &N) fn scalar_div_inplace(&mut self, s: &N)
{ {
self.x = self.x / *s; self.x = self.x / *s;
@ -81,11 +81,11 @@ ScalarDiv<N> for Vec2<N>
impl<N: Add<N, N>> impl<N: Add<N, N>>
ScalarAdd<N> for Vec2<N> ScalarAdd<N> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn scalar_add(&self, s: &N) -> Vec2<N> fn scalar_add(&self, s: &N) -> Vec2<N>
{ Vec2 { x: self.x + *s, y: self.y + *s } } { Vec2 { x: self.x + *s, y: self.y + *s } }
#[inline(always)] #[inline]
fn scalar_add_inplace(&mut self, s: &N) fn scalar_add_inplace(&mut self, s: &N)
{ {
self.x = self.x + *s; self.x = self.x + *s;
@ -96,11 +96,11 @@ ScalarAdd<N> for Vec2<N>
impl<N: Sub<N, N>> impl<N: Sub<N, N>>
ScalarSub<N> for Vec2<N> ScalarSub<N> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn scalar_sub(&self, s: &N) -> Vec2<N> fn scalar_sub(&self, s: &N) -> Vec2<N>
{ Vec2 { x: self.x - *s, y: self.y - *s } } { Vec2 { x: self.x - *s, y: self.y - *s } }
#[inline(always)] #[inline]
fn scalar_sub_inplace(&mut self, s: &N) fn scalar_sub_inplace(&mut self, s: &N)
{ {
self.x = self.x - *s; self.x = self.x - *s;
@ -110,32 +110,32 @@ ScalarSub<N> for Vec2<N>
impl<N: Copy + Add<N, N>> Translation<Vec2<N>> for Vec2<N> impl<N: Copy + Add<N, N>> Translation<Vec2<N>> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn translation(&self) -> Vec2<N> fn translation(&self) -> Vec2<N>
{ copy *self } { copy *self }
#[inline(always)] #[inline]
fn translate(&mut self, t: &Vec2<N>) fn translate(&mut self, t: &Vec2<N>)
{ *self = *self + *t; } { *self = *self + *t; }
} }
impl<N: Add<N, N>> Translatable<Vec2<N>, Vec2<N>> for Vec2<N> impl<N: Add<N, N>> Translatable<Vec2<N>, Vec2<N>> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn translated(&self, t: &Vec2<N>) -> Vec2<N> fn translated(&self, t: &Vec2<N>) -> Vec2<N>
{ self + *t } { self + *t }
} }
impl<N: Mul<N, N> + Add<N, N>> Dot<N> for Vec2<N> impl<N: Mul<N, N> + Add<N, N>> Dot<N> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn dot(&self, other : &Vec2<N>) -> N fn dot(&self, other : &Vec2<N>) -> N
{ self.x * other.x + self.y * other.y } { self.x * other.x + self.y * other.y }
} }
impl<N: Mul<N, N> + Add<N, N> + Sub<N, N>> SubDot<N> for Vec2<N> impl<N: Mul<N, N> + Add<N, N> + Sub<N, N>> SubDot<N> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn sub_dot(&self, a: &Vec2<N>, b: &Vec2<N>) -> N fn sub_dot(&self, a: &Vec2<N>, b: &Vec2<N>) -> N
{ (self.x - a.x) * b.x + (self.y - a.y) * b.y } { (self.x - a.x) * b.x + (self.y - a.y) * b.y }
} }
@ -143,15 +143,15 @@ impl<N: Mul<N, N> + Add<N, N> + Sub<N, N>> SubDot<N> for Vec2<N>
impl<N: Mul<N, N> + Add<N, N> + Div<N, N> + Algebraic> impl<N: Mul<N, N> + Add<N, N> + Div<N, N> + Algebraic>
Norm<N> for Vec2<N> Norm<N> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn sqnorm(&self) -> N fn sqnorm(&self) -> N
{ self.dot(self) } { self.dot(self) }
#[inline(always)] #[inline]
fn norm(&self) -> N fn norm(&self) -> N
{ self.sqnorm().sqrt() } { self.sqnorm().sqrt() }
#[inline(always)] #[inline]
fn normalized(&self) -> Vec2<N> fn normalized(&self) -> Vec2<N>
{ {
let l = self.norm(); let l = self.norm();
@ -159,7 +159,7 @@ Norm<N> for Vec2<N>
Vec2::new(self.x / l, self.y / l) Vec2::new(self.x / l, self.y / l)
} }
#[inline(always)] #[inline]
fn normalize(&mut self) -> N fn normalize(&mut self) -> N
{ {
let l = self.norm(); let l = self.norm();
@ -173,32 +173,32 @@ Norm<N> for Vec2<N>
impl<N: Mul<N, N> + Sub<N, N>> Cross<Vec1<N>> for Vec2<N> impl<N: Mul<N, N> + Sub<N, N>> Cross<Vec1<N>> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn cross(&self, other : &Vec2<N>) -> Vec1<N> fn cross(&self, other : &Vec2<N>) -> Vec1<N>
{ Vec1::new(self.x * other.y - self.y * other.x) } { Vec1::new(self.x * other.y - self.y * other.x) }
} }
impl<N: Neg<N>> Neg<Vec2<N>> for Vec2<N> impl<N: Neg<N>> Neg<Vec2<N>> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn neg(&self) -> Vec2<N> fn neg(&self) -> Vec2<N>
{ Vec2::new(-self.x, -self.y) } { Vec2::new(-self.x, -self.y) }
} }
impl<N: Zero> Zero for Vec2<N> impl<N: Zero> Zero for Vec2<N>
{ {
#[inline(always)] #[inline]
fn zero() -> Vec2<N> fn zero() -> Vec2<N>
{ Vec2::new(Zero::zero(), Zero::zero()) } { Vec2::new(Zero::zero(), Zero::zero()) }
#[inline(always)] #[inline]
fn is_zero(&self) -> bool fn is_zero(&self) -> bool
{ self.x.is_zero() && self.y.is_zero() } { self.x.is_zero() && self.y.is_zero() }
} }
impl<N: Copy + One + Zero + Neg<N>> Basis for Vec2<N> impl<N: Copy + One + Zero + Neg<N>> Basis for Vec2<N>
{ {
#[inline(always)] #[inline]
fn canonical_basis() -> ~[Vec2<N>] fn canonical_basis() -> ~[Vec2<N>]
{ {
// FIXME: this should be static // FIXME: this should be static
@ -206,22 +206,22 @@ impl<N: Copy + One + Zero + Neg<N>> Basis for Vec2<N>
Vec2::new(Zero::zero(), One::one()) ] Vec2::new(Zero::zero(), One::one()) ]
} }
#[inline(always)] #[inline]
fn orthogonal_subspace_basis(&self) -> ~[Vec2<N>] fn orthogonal_subspace_basis(&self) -> ~[Vec2<N>]
{ ~[ Vec2::new(-self.y, copy self.x) ] } { ~[ Vec2::new(-self.y, copy self.x) ] }
} }
impl<N:ApproxEq<N>> ApproxEq<N> for Vec2<N> impl<N:ApproxEq<N>> ApproxEq<N> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &Vec2<N>) -> bool fn approx_eq(&self, other: &Vec2<N>) -> bool
{ self.x.approx_eq(&other.x) && self.y.approx_eq(&other.y) } { self.x.approx_eq(&other.x) && self.y.approx_eq(&other.y) }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &Vec2<N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &Vec2<N>, epsilon: &N) -> bool
{ {
self.x.approx_eq_eps(&other.x, epsilon) && self.x.approx_eq_eps(&other.x, epsilon) &&
@ -231,26 +231,26 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Vec2<N>
impl<N:Rand> Rand for Vec2<N> impl<N:Rand> Rand for Vec2<N>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Vec2<N> fn rand<R: Rng>(rng: &mut R) -> Vec2<N>
{ Vec2::new(rng.gen(), rng.gen()) } { Vec2::new(rng.gen(), rng.gen()) }
} }
impl<N: Copy> Flatten<N> for Vec2<N> impl<N: Copy> Flatten<N> for Vec2<N>
{ {
#[inline(always)] #[inline]
fn flat_size() -> uint fn flat_size() -> uint
{ 2 } { 2 }
#[inline(always)] #[inline]
fn from_flattened(l: &[N], off: uint) -> Vec2<N> fn from_flattened(l: &[N], off: uint) -> Vec2<N>
{ Vec2::new(copy l[off], copy l[off + 1]) } { Vec2::new(copy l[off], copy l[off + 1]) }
#[inline(always)] #[inline]
fn flatten(&self) -> ~[N] fn flatten(&self) -> ~[N]
{ ~[ copy self.x, copy self.y ] } { ~[ copy self.x, copy self.y ] }
#[inline(always)] #[inline]
fn flatten_to(&self, l: &mut [N], off: uint) fn flatten_to(&self, l: &mut [N], off: uint)
{ {
l[off] = copy self.x; l[off] = copy self.x;
@ -260,11 +260,11 @@ impl<N: Copy> Flatten<N> for Vec2<N>
impl<N: Bounded> Bounded for Vec2<N> impl<N: Bounded> Bounded for Vec2<N>
{ {
#[inline(always)] #[inline]
fn max_value() -> Vec2<N> fn max_value() -> Vec2<N>
{ Vec2::new(Bounded::max_value(), Bounded::max_value()) } { Vec2::new(Bounded::max_value(), Bounded::max_value()) }
#[inline(always)] #[inline]
fn min_value() -> Vec2<N> fn min_value() -> Vec2<N>
{ Vec2::new(Bounded::min_value(), Bounded::min_value()) } { Vec2::new(Bounded::min_value(), Bounded::min_value()) }
} }

View File

@ -19,7 +19,7 @@ pub struct Mat3<N>
impl<N> Mat3<N> impl<N> Mat3<N>
{ {
#[inline(always)] #[inline]
pub fn new(m11: N, m12: N, m13: N, pub fn new(m11: N, m12: N, m13: N,
m21: N, m22: N, m23: N, m21: N, m22: N, m23: N,
m31: N, m32: N, m33: N) -> Mat3<N> m31: N, m32: N, m33: N) -> Mat3<N>
@ -35,14 +35,14 @@ impl<N> Mat3<N>
impl<N> Dim for Mat3<N> impl<N> Dim for Mat3<N>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ 3 } { 3 }
} }
impl<N: Copy + One + Zero> One for Mat3<N> impl<N: Copy + One + Zero> One for Mat3<N>
{ {
#[inline(always)] #[inline]
fn one() -> Mat3<N> fn one() -> Mat3<N>
{ {
let (_0, _1) = (Zero::zero(), One::one()); let (_0, _1) = (Zero::zero(), One::one());
@ -54,7 +54,7 @@ impl<N: Copy + One + Zero> One for Mat3<N>
impl<N: Copy + Zero> Zero for Mat3<N> impl<N: Copy + Zero> Zero for Mat3<N>
{ {
#[inline(always)] #[inline]
fn zero() -> Mat3<N> fn zero() -> Mat3<N>
{ {
let _0 = Zero::zero(); let _0 = Zero::zero();
@ -63,7 +63,7 @@ impl<N: Copy + Zero> Zero for Mat3<N>
copy _0, copy _0, _0) copy _0, copy _0, _0)
} }
#[inline(always)] #[inline]
fn is_zero(&self) -> bool fn is_zero(&self) -> bool
{ {
self.m11.is_zero() && self.m12.is_zero() && self.m13.is_zero() && self.m11.is_zero() && self.m12.is_zero() && self.m13.is_zero() &&
@ -74,7 +74,7 @@ impl<N: Copy + Zero> Zero for Mat3<N>
impl<N: Mul<N, N> + Add<N, N>> Mul<Mat3<N>, Mat3<N>> for Mat3<N> impl<N: Mul<N, N> + Add<N, N>> Mul<Mat3<N>, Mat3<N>> for Mat3<N>
{ {
#[inline(always)] #[inline]
fn mul(&self, other: &Mat3<N>) -> Mat3<N> fn mul(&self, other: &Mat3<N>) -> Mat3<N>
{ {
Mat3::new( Mat3::new(
@ -95,7 +95,7 @@ impl<N: Mul<N, N> + Add<N, N>> Mul<Mat3<N>, Mat3<N>> for Mat3<N>
impl<N: Add<N, N> + Mul<N, N>> RMul<Vec3<N>> for Mat3<N> impl<N: Add<N, N> + Mul<N, N>> RMul<Vec3<N>> for Mat3<N>
{ {
#[inline(always)] #[inline]
fn rmul(&self, other: &Vec3<N>) -> Vec3<N> fn rmul(&self, other: &Vec3<N>) -> Vec3<N>
{ {
Vec3::new( Vec3::new(
@ -108,7 +108,7 @@ impl<N: Add<N, N> + Mul<N, N>> RMul<Vec3<N>> for Mat3<N>
impl<N: Add<N, N> + Mul<N, N>> LMul<Vec3<N>> for Mat3<N> impl<N: Add<N, N> + Mul<N, N>> LMul<Vec3<N>> for Mat3<N>
{ {
#[inline(always)] #[inline]
fn lmul(&self, other: &Vec3<N>) -> Vec3<N> fn lmul(&self, other: &Vec3<N>) -> Vec3<N>
{ {
Vec3::new( Vec3::new(
@ -122,7 +122,7 @@ impl<N: Add<N, N> + Mul<N, N>> LMul<Vec3<N>> for Mat3<N>
impl<N:Copy + Mul<N, N> + Div<N, N> + Sub<N, N> + Add<N, N> + Neg<N> + Zero> impl<N:Copy + Mul<N, N> + Div<N, N> + Sub<N, N> + Add<N, N> + Neg<N> + Zero>
Inv for Mat3<N> Inv for Mat3<N>
{ {
#[inline(always)] #[inline]
fn inverse(&self) -> Mat3<N> fn inverse(&self) -> Mat3<N>
{ {
let mut res = copy *self; let mut res = copy *self;
@ -132,7 +132,7 @@ Inv for Mat3<N>
res res
} }
#[inline(always)] #[inline]
fn invert(&mut self) fn invert(&mut self)
{ {
let minor_m22_m33 = self.m22 * self.m33 - self.m32 * self.m23; let minor_m22_m33 = self.m22 * self.m33 - self.m32 * self.m23;
@ -163,7 +163,7 @@ Inv for Mat3<N>
impl<N:Copy> Transpose for Mat3<N> impl<N:Copy> Transpose for Mat3<N>
{ {
#[inline(always)] #[inline]
fn transposed(&self) -> Mat3<N> fn transposed(&self) -> Mat3<N>
{ {
Mat3::new(copy self.m11, copy self.m21, copy self.m31, Mat3::new(copy self.m11, copy self.m21, copy self.m31,
@ -171,7 +171,7 @@ impl<N:Copy> Transpose for Mat3<N>
copy self.m13, copy self.m23, copy self.m33) copy self.m13, copy self.m23, copy self.m33)
} }
#[inline(always)] #[inline]
fn transpose(&mut self) fn transpose(&mut self)
{ {
swap(&mut self.m12, &mut self.m21); swap(&mut self.m12, &mut self.m21);
@ -182,11 +182,11 @@ impl<N:Copy> Transpose for Mat3<N>
impl<N:ApproxEq<N>> ApproxEq<N> for Mat3<N> impl<N:ApproxEq<N>> ApproxEq<N> for Mat3<N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &Mat3<N>) -> bool fn approx_eq(&self, other: &Mat3<N>) -> bool
{ {
self.m11.approx_eq(&other.m11) && self.m11.approx_eq(&other.m11) &&
@ -202,7 +202,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Mat3<N>
self.m33.approx_eq(&other.m33) self.m33.approx_eq(&other.m33)
} }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &Mat3<N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &Mat3<N>, epsilon: &N) -> bool
{ {
self.m11.approx_eq_eps(&other.m11, epsilon) && self.m11.approx_eq_eps(&other.m11, epsilon) &&
@ -221,7 +221,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Mat3<N>
impl<N: Rand> Rand for Mat3<N> impl<N: Rand> Rand for Mat3<N>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Mat3<N> fn rand<R: Rng>(rng: &mut R) -> Mat3<N>
{ {
Mat3::new(rng.gen(), rng.gen(), rng.gen(), Mat3::new(rng.gen(), rng.gen(), rng.gen(),
@ -232,17 +232,17 @@ impl<N: Rand> Rand for Mat3<N>
impl<N: Copy> Flatten<N> for Mat3<N> impl<N: Copy> Flatten<N> for Mat3<N>
{ {
#[inline(always)] #[inline]
fn flat_size() -> uint fn flat_size() -> uint
{ 9 } { 9 }
#[inline(always)] #[inline]
fn from_flattened(l: &[N], off: uint) -> Mat3<N> fn from_flattened(l: &[N], off: uint) -> Mat3<N>
{ Mat3::new(copy l[off + 0], copy l[off + 1], copy l[off + 2], { Mat3::new(copy l[off + 0], copy l[off + 1], copy l[off + 2],
copy l[off + 3], copy l[off + 4], copy l[off + 5], copy l[off + 3], copy l[off + 4], copy l[off + 5],
copy l[off + 6], copy l[off + 7], copy l[off + 8]) } copy l[off + 6], copy l[off + 7], copy l[off + 8]) }
#[inline(always)] #[inline]
fn flatten(&self) -> ~[N] fn flatten(&self) -> ~[N]
{ {
~[ ~[
@ -252,7 +252,7 @@ impl<N: Copy> Flatten<N> for Mat3<N>
] ]
} }
#[inline(always)] #[inline]
fn flatten_to(&self, l: &mut [N], off: uint) fn flatten_to(&self, l: &mut [N], off: uint)
{ {
l[off + 0] = copy self.m11; l[off + 0] = copy self.m11;

View File

@ -21,28 +21,28 @@ pub struct Vec3<N>
impl<N> Vec3<N> impl<N> Vec3<N>
{ {
#[inline(always)] #[inline]
pub fn new(x: N, y: N, z: N) -> Vec3<N> pub fn new(x: N, y: N, z: N) -> Vec3<N>
{ Vec3 {x: x, y: y, z: z} } { Vec3 {x: x, y: y, z: z} }
} }
impl<N> Dim for Vec3<N> impl<N> Dim for Vec3<N>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ 3 } { 3 }
} }
impl<N: Add<N,N>> Add<Vec3<N>, Vec3<N>> for Vec3<N> impl<N: Add<N,N>> Add<Vec3<N>, Vec3<N>> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn add(&self, other: &Vec3<N>) -> Vec3<N> fn add(&self, other: &Vec3<N>) -> Vec3<N>
{ Vec3::new(self.x + other.x, self.y + other.y, self.z + other.z) } { Vec3::new(self.x + other.x, self.y + other.y, self.z + other.z) }
} }
impl<N: Sub<N,N>> Sub<Vec3<N>, Vec3<N>> for Vec3<N> impl<N: Sub<N,N>> Sub<Vec3<N>, Vec3<N>> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn sub(&self, other: &Vec3<N>) -> Vec3<N> fn sub(&self, other: &Vec3<N>) -> Vec3<N>
{ Vec3::new(self.x - other.x, self.y - other.y, self.z - other.z) } { Vec3::new(self.x - other.x, self.y - other.y, self.z - other.z) }
} }
@ -50,11 +50,11 @@ impl<N: Sub<N,N>> Sub<Vec3<N>, Vec3<N>> for Vec3<N>
impl<N: Mul<N, N>> impl<N: Mul<N, N>>
ScalarMul<N> for Vec3<N> ScalarMul<N> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn scalar_mul(&self, s: &N) -> Vec3<N> fn scalar_mul(&self, s: &N) -> Vec3<N>
{ Vec3 { x: self.x * *s, y: self.y * *s, z: self.z * *s } } { Vec3 { x: self.x * *s, y: self.y * *s, z: self.z * *s } }
#[inline(always)] #[inline]
fn scalar_mul_inplace(&mut self, s: &N) fn scalar_mul_inplace(&mut self, s: &N)
{ {
self.x = self.x * *s; self.x = self.x * *s;
@ -67,11 +67,11 @@ ScalarMul<N> for Vec3<N>
impl<N: Div<N, N>> impl<N: Div<N, N>>
ScalarDiv<N> for Vec3<N> ScalarDiv<N> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn scalar_div(&self, s: &N) -> Vec3<N> fn scalar_div(&self, s: &N) -> Vec3<N>
{ Vec3 { x: self.x / *s, y: self.y / *s, z: self.z / *s } } { Vec3 { x: self.x / *s, y: self.y / *s, z: self.z / *s } }
#[inline(always)] #[inline]
fn scalar_div_inplace(&mut self, s: &N) fn scalar_div_inplace(&mut self, s: &N)
{ {
self.x = self.x / *s; self.x = self.x / *s;
@ -83,11 +83,11 @@ ScalarDiv<N> for Vec3<N>
impl<N: Add<N, N>> impl<N: Add<N, N>>
ScalarAdd<N> for Vec3<N> ScalarAdd<N> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn scalar_add(&self, s: &N) -> Vec3<N> fn scalar_add(&self, s: &N) -> Vec3<N>
{ Vec3 { x: self.x + *s, y: self.y + *s, z: self.z + *s } } { Vec3 { x: self.x + *s, y: self.y + *s, z: self.z + *s } }
#[inline(always)] #[inline]
fn scalar_add_inplace(&mut self, s: &N) fn scalar_add_inplace(&mut self, s: &N)
{ {
self.x = self.x + *s; self.x = self.x + *s;
@ -99,11 +99,11 @@ ScalarAdd<N> for Vec3<N>
impl<N: Sub<N, N>> impl<N: Sub<N, N>>
ScalarSub<N> for Vec3<N> ScalarSub<N> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn scalar_sub(&self, s: &N) -> Vec3<N> fn scalar_sub(&self, s: &N) -> Vec3<N>
{ Vec3 { x: self.x - *s, y: self.y - *s, z: self.z - *s } } { Vec3 { x: self.x - *s, y: self.y - *s, z: self.z - *s } }
#[inline(always)] #[inline]
fn scalar_sub_inplace(&mut self, s: &N) fn scalar_sub_inplace(&mut self, s: &N)
{ {
self.x = self.x - *s; self.x = self.x - *s;
@ -114,18 +114,18 @@ ScalarSub<N> for Vec3<N>
impl<N: Copy + Add<N, N>> Translation<Vec3<N>> for Vec3<N> impl<N: Copy + Add<N, N>> Translation<Vec3<N>> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn translation(&self) -> Vec3<N> fn translation(&self) -> Vec3<N>
{ copy *self } { copy *self }
#[inline(always)] #[inline]
fn translate(&mut self, t: &Vec3<N>) fn translate(&mut self, t: &Vec3<N>)
{ *self = *self + *t; } { *self = *self + *t; }
} }
impl<N: Add<N, N>> Translatable<Vec3<N>, Vec3<N>> for Vec3<N> impl<N: Add<N, N>> Translatable<Vec3<N>, Vec3<N>> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn translated(&self, t: &Vec3<N>) -> Vec3<N> fn translated(&self, t: &Vec3<N>) -> Vec3<N>
{ self + *t } { self + *t }
} }
@ -134,21 +134,21 @@ impl<N: Add<N, N>> Translatable<Vec3<N>, Vec3<N>> for Vec3<N>
impl<N: Neg<N>> Neg<Vec3<N>> for Vec3<N> impl<N: Neg<N>> Neg<Vec3<N>> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn neg(&self) -> Vec3<N> fn neg(&self) -> Vec3<N>
{ Vec3::new(-self.x, -self.y, -self.z) } { Vec3::new(-self.x, -self.y, -self.z) }
} }
impl<N: Mul<N, N> + Add<N, N>> Dot<N> for Vec3<N> impl<N: Mul<N, N> + Add<N, N>> Dot<N> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn dot(&self, other : &Vec3<N>) -> N fn dot(&self, other : &Vec3<N>) -> N
{ self.x * other.x + self.y * other.y + self.z * other.z } { self.x * other.x + self.y * other.y + self.z * other.z }
} }
impl<N: Mul<N, N> + Add<N, N> + Sub<N, N>> SubDot<N> for Vec3<N> impl<N: Mul<N, N> + Add<N, N> + Sub<N, N>> SubDot<N> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn sub_dot(&self, a: &Vec3<N>, b: &Vec3<N>) -> N fn sub_dot(&self, a: &Vec3<N>, b: &Vec3<N>) -> N
{ (self.x - a.x) * b.x + (self.y - a.y) * b.y + (self.z - a.z) * b.z } { (self.x - a.x) * b.x + (self.y - a.y) * b.y + (self.z - a.z) * b.z }
} }
@ -156,15 +156,15 @@ impl<N: Mul<N, N> + Add<N, N> + Sub<N, N>> SubDot<N> for Vec3<N>
impl<N: Mul<N, N> + Add<N, N> + Div<N, N> + Algebraic> impl<N: Mul<N, N> + Add<N, N> + Div<N, N> + Algebraic>
Norm<N> for Vec3<N> Norm<N> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn sqnorm(&self) -> N fn sqnorm(&self) -> N
{ self.dot(self) } { self.dot(self) }
#[inline(always)] #[inline]
fn norm(&self) -> N fn norm(&self) -> N
{ self.sqnorm().sqrt() } { self.sqnorm().sqrt() }
#[inline(always)] #[inline]
fn normalized(&self) -> Vec3<N> fn normalized(&self) -> Vec3<N>
{ {
let l = self.norm(); let l = self.norm();
@ -172,7 +172,7 @@ Norm<N> for Vec3<N>
Vec3::new(self.x / l, self.y / l, self.z / l) Vec3::new(self.x / l, self.y / l, self.z / l)
} }
#[inline(always)] #[inline]
fn normalize(&mut self) -> N fn normalize(&mut self) -> N
{ {
let l = self.norm(); let l = self.norm();
@ -187,7 +187,7 @@ Norm<N> for Vec3<N>
impl<N: Mul<N, N> + Sub<N, N>> Cross<Vec3<N>> for Vec3<N> impl<N: Mul<N, N> + Sub<N, N>> Cross<Vec3<N>> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn cross(&self, other : &Vec3<N>) -> Vec3<N> fn cross(&self, other : &Vec3<N>) -> Vec3<N>
{ {
Vec3::new( Vec3::new(
@ -200,11 +200,11 @@ impl<N: Mul<N, N> + Sub<N, N>> Cross<Vec3<N>> for Vec3<N>
impl<N: Zero> Zero for Vec3<N> impl<N: Zero> Zero for Vec3<N>
{ {
#[inline(always)] #[inline]
fn zero() -> Vec3<N> fn zero() -> Vec3<N>
{ Vec3::new(Zero::zero(), Zero::zero(), Zero::zero()) } { Vec3::new(Zero::zero(), Zero::zero(), Zero::zero()) }
#[inline(always)] #[inline]
fn is_zero(&self) -> bool fn is_zero(&self) -> bool
{ self.x.is_zero() && self.y.is_zero() && self.z.is_zero() } { self.x.is_zero() && self.y.is_zero() && self.z.is_zero() }
} }
@ -213,7 +213,7 @@ impl<N: Copy + One + Zero + Neg<N> + Ord + Mul<N, N> + Sub<N, N> + Add<N, N> +
Div<N, N> + Algebraic> Div<N, N> + Algebraic>
Basis for Vec3<N> Basis for Vec3<N>
{ {
#[inline(always)] #[inline]
fn canonical_basis() -> ~[Vec3<N>] fn canonical_basis() -> ~[Vec3<N>]
{ {
// FIXME: this should be static // FIXME: this should be static
@ -222,7 +222,7 @@ Basis for Vec3<N>
Vec3::new(Zero::zero(), Zero::zero(), One::one()) ] Vec3::new(Zero::zero(), Zero::zero(), One::one()) ]
} }
#[inline(always)] #[inline]
fn orthogonal_subspace_basis(&self) -> ~[Vec3<N>] fn orthogonal_subspace_basis(&self) -> ~[Vec3<N>]
{ {
let a = let a =
@ -237,11 +237,11 @@ Basis for Vec3<N>
impl<N:ApproxEq<N>> ApproxEq<N> for Vec3<N> impl<N:ApproxEq<N>> ApproxEq<N> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &Vec3<N>) -> bool fn approx_eq(&self, other: &Vec3<N>) -> bool
{ {
self.x.approx_eq(&other.x) && self.x.approx_eq(&other.x) &&
@ -249,7 +249,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Vec3<N>
self.z.approx_eq(&other.z) self.z.approx_eq(&other.z)
} }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &Vec3<N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &Vec3<N>, epsilon: &N) -> bool
{ {
self.x.approx_eq_eps(&other.x, epsilon) && self.x.approx_eq_eps(&other.x, epsilon) &&
@ -260,26 +260,26 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Vec3<N>
impl<N: Rand> Rand for Vec3<N> impl<N: Rand> Rand for Vec3<N>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Vec3<N> fn rand<R: Rng>(rng: &mut R) -> Vec3<N>
{ Vec3::new(rng.gen(), rng.gen(), rng.gen()) } { Vec3::new(rng.gen(), rng.gen(), rng.gen()) }
} }
impl<N: Copy> Flatten<N> for Vec3<N> impl<N: Copy> Flatten<N> for Vec3<N>
{ {
#[inline(always)] #[inline]
fn flat_size() -> uint fn flat_size() -> uint
{ 3 } { 3 }
#[inline(always)] #[inline]
fn from_flattened(l: &[N], off: uint) -> Vec3<N> fn from_flattened(l: &[N], off: uint) -> Vec3<N>
{ Vec3::new(copy l[off], copy l[off + 1], copy l[off + 2]) } { Vec3::new(copy l[off], copy l[off + 1], copy l[off + 2]) }
#[inline(always)] #[inline]
fn flatten(&self) -> ~[N] fn flatten(&self) -> ~[N]
{ ~[ copy self.x, copy self.y, copy self.z ] } { ~[ copy self.x, copy self.y, copy self.z ] }
#[inline(always)] #[inline]
fn flatten_to(&self, l: &mut [N], off: uint) fn flatten_to(&self, l: &mut [N], off: uint)
{ {
l[off] = copy self.x; l[off] = copy self.x;
@ -290,11 +290,11 @@ impl<N: Copy> Flatten<N> for Vec3<N>
impl<N: Bounded> Bounded for Vec3<N> impl<N: Bounded> Bounded for Vec3<N>
{ {
#[inline(always)] #[inline]
fn max_value() -> Vec3<N> fn max_value() -> Vec3<N>
{ Vec3::new(Bounded::max_value(), Bounded::max_value(), Bounded::max_value()) } { Vec3::new(Bounded::max_value(), Bounded::max_value(), Bounded::max_value()) }
#[inline(always)] #[inline]
fn min_value() -> Vec3<N> fn min_value() -> Vec3<N>
{ Vec3::new(Bounded::min_value(), Bounded::min_value(), Bounded::min_value()) } { Vec3::new(Bounded::min_value(), Bounded::min_value(), Bounded::min_value()) }
} }

View File

@ -16,15 +16,15 @@ pub struct DMat<N>
mij: ~[N] mij: ~[N]
} }
#[inline(always)] #[inline]
pub fn zero_mat_with_dim<N: Zero + Copy>(dim: uint) -> DMat<N> pub fn zero_mat_with_dim<N: Zero + Copy>(dim: uint) -> DMat<N>
{ DMat { dim: dim, mij: from_elem(dim * dim, Zero::zero()) } } { DMat { dim: dim, mij: from_elem(dim * dim, Zero::zero()) } }
#[inline(always)] #[inline]
pub fn is_zero_mat<N: Zero>(mat: &DMat<N>) -> bool pub fn is_zero_mat<N: Zero>(mat: &DMat<N>) -> bool
{ mat.mij.iter().all(|e| e.is_zero()) } { mat.mij.iter().all(|e| e.is_zero()) }
#[inline(always)] #[inline]
pub fn one_mat_with_dim<N: Copy + One + Zero>(dim: uint) -> DMat<N> pub fn one_mat_with_dim<N: Copy + One + Zero>(dim: uint) -> DMat<N>
{ {
let mut res = zero_mat_with_dim(dim); let mut res = zero_mat_with_dim(dim);
@ -38,11 +38,11 @@ pub fn one_mat_with_dim<N: Copy + One + Zero>(dim: uint) -> DMat<N>
impl<N: Copy> DMat<N> impl<N: Copy> DMat<N>
{ {
#[inline(always)] #[inline]
pub fn offset(&self, i: uint, j: uint) -> uint pub fn offset(&self, i: uint, j: uint) -> uint
{ i * self.dim + j } { i * self.dim + j }
#[inline(always)] #[inline]
pub fn set(&mut self, i: uint, j: uint, t: &N) pub fn set(&mut self, i: uint, j: uint, t: &N)
{ {
assert!(i < self.dim); assert!(i < self.dim);
@ -50,7 +50,7 @@ impl<N: Copy> DMat<N>
self.mij[self.offset(i, j)] = copy *t self.mij[self.offset(i, j)] = copy *t
} }
#[inline(always)] #[inline]
pub fn at(&self, i: uint, j: uint) -> N pub fn at(&self, i: uint, j: uint) -> N
{ {
assert!(i < self.dim); assert!(i < self.dim);
@ -61,7 +61,7 @@ impl<N: Copy> DMat<N>
impl<N: Copy> Index<(uint, uint), N> for DMat<N> impl<N: Copy> Index<(uint, uint), N> for DMat<N>
{ {
#[inline(always)] #[inline]
fn index(&self, &(i, j): &(uint, uint)) -> N fn index(&self, &(i, j): &(uint, uint)) -> N
{ self.at(i, j) } { self.at(i, j) }
} }
@ -136,7 +136,7 @@ LMul<DVec<N>> for DMat<N>
impl<N: Clone + Copy + Eq + DivisionRing> impl<N: Clone + Copy + Eq + DivisionRing>
Inv for DMat<N> Inv for DMat<N>
{ {
#[inline(always)] #[inline]
fn inverse(&self) -> DMat<N> fn inverse(&self) -> DMat<N>
{ {
let mut res : DMat<N> = self.clone(); let mut res : DMat<N> = self.clone();
@ -225,7 +225,7 @@ Inv for DMat<N>
impl<N:Copy> Transpose for DMat<N> impl<N:Copy> Transpose for DMat<N>
{ {
#[inline(always)] #[inline]
fn transposed(&self) -> DMat<N> fn transposed(&self) -> DMat<N>
{ {
let mut res = copy *self; let mut res = copy *self;
@ -254,11 +254,11 @@ impl<N:Copy> Transpose for DMat<N>
impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N> impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &DMat<N>) -> bool fn approx_eq(&self, other: &DMat<N>) -> bool
{ {
let mut zip = self.mij.iter().zip(other.mij.iter()); let mut zip = self.mij.iter().zip(other.mij.iter());
@ -266,7 +266,7 @@ impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N>
do zip.all |(a, b)| { a.approx_eq(b) } do zip.all |(a, b)| { a.approx_eq(b) }
} }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &DMat<N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &DMat<N>, epsilon: &N) -> bool
{ {
let mut zip = self.mij.iter().zip(other.mij.iter()); let mut zip = self.mij.iter().zip(other.mij.iter());

View File

@ -17,11 +17,11 @@ pub struct DVec<N>
at: ~[N] at: ~[N]
} }
#[inline(always)] #[inline]
pub fn zero_vec_with_dim<N: Zero + Copy>(dim: uint) -> DVec<N> pub fn zero_vec_with_dim<N: Zero + Copy>(dim: uint) -> DVec<N>
{ DVec { at: from_elem(dim, Zero::zero::<N>()) } } { DVec { at: from_elem(dim, Zero::zero::<N>()) } }
#[inline(always)] #[inline]
pub fn is_zero_vec<N: Zero>(vec: &DVec<N>) -> bool pub fn is_zero_vec<N: Zero>(vec: &DVec<N>) -> bool
{ vec.at.iter().all(|e| e.is_zero()) } { vec.at.iter().all(|e| e.is_zero()) }
@ -79,7 +79,7 @@ impl<N: Copy + DivisionRing + Algebraic + Clone + ApproxEq<N>> DVec<N>
impl<N: Copy + Add<N,N>> Add<DVec<N>, DVec<N>> for DVec<N> impl<N: Copy + Add<N,N>> Add<DVec<N>, DVec<N>> for DVec<N>
{ {
#[inline(always)] #[inline]
fn add(&self, other: &DVec<N>) -> DVec<N> fn add(&self, other: &DVec<N>) -> DVec<N>
{ {
assert!(self.at.len() == other.at.len()); assert!(self.at.len() == other.at.len());
@ -89,7 +89,7 @@ impl<N: Copy + Add<N,N>> Add<DVec<N>, DVec<N>> for DVec<N>
impl<N: Copy + Sub<N,N>> Sub<DVec<N>, DVec<N>> for DVec<N> impl<N: Copy + Sub<N,N>> Sub<DVec<N>, DVec<N>> for DVec<N>
{ {
#[inline(always)] #[inline]
fn sub(&self, other: &DVec<N>) -> DVec<N> fn sub(&self, other: &DVec<N>) -> DVec<N>
{ {
assert!(self.at.len() == other.at.len()); assert!(self.at.len() == other.at.len());
@ -99,7 +99,7 @@ impl<N: Copy + Sub<N,N>> Sub<DVec<N>, DVec<N>> for DVec<N>
impl<N: Neg<N>> Neg<DVec<N>> for DVec<N> impl<N: Neg<N>> Neg<DVec<N>> for DVec<N>
{ {
#[inline(always)] #[inline]
fn neg(&self) -> DVec<N> fn neg(&self) -> DVec<N>
{ DVec { at: map(self.at, |a| -a) } } { DVec { at: map(self.at, |a| -a) } }
} }
@ -107,7 +107,7 @@ impl<N: Neg<N>> Neg<DVec<N>> for DVec<N>
impl<N: Ring> impl<N: Ring>
Dot<N> for DVec<N> Dot<N> for DVec<N>
{ {
#[inline(always)] #[inline]
fn dot(&self, other: &DVec<N>) -> N fn dot(&self, other: &DVec<N>) -> N
{ {
assert!(self.at.len() == other.at.len()); assert!(self.at.len() == other.at.len());
@ -123,7 +123,7 @@ Dot<N> for DVec<N>
impl<N: Ring> SubDot<N> for DVec<N> impl<N: Ring> SubDot<N> for DVec<N>
{ {
#[inline(always)] #[inline]
fn sub_dot(&self, a: &DVec<N>, b: &DVec<N>) -> N fn sub_dot(&self, a: &DVec<N>, b: &DVec<N>) -> N
{ {
let mut res = Zero::zero::<N>(); let mut res = Zero::zero::<N>();
@ -138,11 +138,11 @@ impl<N: Ring> SubDot<N> for DVec<N>
impl<N: Mul<N, N>> impl<N: Mul<N, N>>
ScalarMul<N> for DVec<N> ScalarMul<N> for DVec<N>
{ {
#[inline(always)] #[inline]
fn scalar_mul(&self, s: &N) -> DVec<N> fn scalar_mul(&self, s: &N) -> DVec<N>
{ DVec { at: map(self.at, |a| a * *s) } } { DVec { at: map(self.at, |a| a * *s) } }
#[inline(always)] #[inline]
fn scalar_mul_inplace(&mut self, s: &N) fn scalar_mul_inplace(&mut self, s: &N)
{ {
for iterate(0u, self.at.len()) |i| for iterate(0u, self.at.len()) |i|
@ -154,11 +154,11 @@ ScalarMul<N> for DVec<N>
impl<N: Div<N, N>> impl<N: Div<N, N>>
ScalarDiv<N> for DVec<N> ScalarDiv<N> for DVec<N>
{ {
#[inline(always)] #[inline]
fn scalar_div(&self, s: &N) -> DVec<N> fn scalar_div(&self, s: &N) -> DVec<N>
{ DVec { at: map(self.at, |a| a / *s) } } { DVec { at: map(self.at, |a| a / *s) } }
#[inline(always)] #[inline]
fn scalar_div_inplace(&mut self, s: &N) fn scalar_div_inplace(&mut self, s: &N)
{ {
for iterate(0u, self.at.len()) |i| for iterate(0u, self.at.len()) |i|
@ -169,11 +169,11 @@ ScalarDiv<N> for DVec<N>
impl<N: Add<N, N>> impl<N: Add<N, N>>
ScalarAdd<N> for DVec<N> ScalarAdd<N> for DVec<N>
{ {
#[inline(always)] #[inline]
fn scalar_add(&self, s: &N) -> DVec<N> fn scalar_add(&self, s: &N) -> DVec<N>
{ DVec { at: map(self.at, |a| a + *s) } } { DVec { at: map(self.at, |a| a + *s) } }
#[inline(always)] #[inline]
fn scalar_add_inplace(&mut self, s: &N) fn scalar_add_inplace(&mut self, s: &N)
{ {
for iterate(0u, self.at.len()) |i| for iterate(0u, self.at.len()) |i|
@ -184,11 +184,11 @@ ScalarAdd<N> for DVec<N>
impl<N: Sub<N, N>> impl<N: Sub<N, N>>
ScalarSub<N> for DVec<N> ScalarSub<N> for DVec<N>
{ {
#[inline(always)] #[inline]
fn scalar_sub(&self, s: &N) -> DVec<N> fn scalar_sub(&self, s: &N) -> DVec<N>
{ DVec { at: map(self.at, |a| a - *s) } } { DVec { at: map(self.at, |a| a - *s) } }
#[inline(always)] #[inline]
fn scalar_sub_inplace(&mut self, s: &N) fn scalar_sub_inplace(&mut self, s: &N)
{ {
for iterate(0u, self.at.len()) |i| for iterate(0u, self.at.len()) |i|
@ -198,18 +198,18 @@ ScalarSub<N> for DVec<N>
impl<N: Clone + Copy + Add<N, N>> Translation<DVec<N>> for DVec<N> impl<N: Clone + Copy + Add<N, N>> Translation<DVec<N>> for DVec<N>
{ {
#[inline(always)] #[inline]
fn translation(&self) -> DVec<N> fn translation(&self) -> DVec<N>
{ self.clone() } { self.clone() }
#[inline(always)] #[inline]
fn translate(&mut self, t: &DVec<N>) fn translate(&mut self, t: &DVec<N>)
{ *self = *self + *t; } { *self = *self + *t; }
} }
impl<N: Add<N, N> + Copy> Translatable<DVec<N>, DVec<N>> for DVec<N> impl<N: Add<N, N> + Copy> Translatable<DVec<N>, DVec<N>> for DVec<N>
{ {
#[inline(always)] #[inline]
fn translated(&self, t: &DVec<N>) -> DVec<N> fn translated(&self, t: &DVec<N>) -> DVec<N>
{ self + *t } { self + *t }
} }
@ -217,15 +217,15 @@ impl<N: Add<N, N> + Copy> Translatable<DVec<N>, DVec<N>> for DVec<N>
impl<N: Copy + DivisionRing + Algebraic + Clone> impl<N: Copy + DivisionRing + Algebraic + Clone>
Norm<N> for DVec<N> Norm<N> for DVec<N>
{ {
#[inline(always)] #[inline]
fn sqnorm(&self) -> N fn sqnorm(&self) -> N
{ self.dot(self) } { self.dot(self) }
#[inline(always)] #[inline]
fn norm(&self) -> N fn norm(&self) -> N
{ self.sqnorm().sqrt() } { self.sqnorm().sqrt() }
#[inline(always)] #[inline]
fn normalized(&self) -> DVec<N> fn normalized(&self) -> DVec<N>
{ {
let mut res : DVec<N> = self.clone(); let mut res : DVec<N> = self.clone();
@ -235,7 +235,7 @@ Norm<N> for DVec<N>
res res
} }
#[inline(always)] #[inline]
fn normalize(&mut self) -> N fn normalize(&mut self) -> N
{ {
let l = self.norm(); let l = self.norm();
@ -249,11 +249,11 @@ Norm<N> for DVec<N>
impl<N: ApproxEq<N>> ApproxEq<N> for DVec<N> impl<N: ApproxEq<N>> ApproxEq<N> for DVec<N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &DVec<N>) -> bool fn approx_eq(&self, other: &DVec<N>) -> bool
{ {
let mut zip = self.at.iter().zip(other.at.iter()); let mut zip = self.at.iter().zip(other.at.iter());
@ -261,7 +261,7 @@ impl<N: ApproxEq<N>> ApproxEq<N> for DVec<N>
do zip.all |(a, b)| { a.approx_eq(b) } do zip.all |(a, b)| { a.approx_eq(b) }
} }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &DVec<N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &DVec<N>, epsilon: &N) -> bool
{ {
let mut zip = self.at.iter().zip(other.at.iter()); let mut zip = self.at.iter().zip(other.at.iter());

View File

@ -21,43 +21,43 @@ pub struct NMat<D, N>
impl<D: Dim, N: Copy> NMat<D, N> impl<D: Dim, N: Copy> NMat<D, N>
{ {
#[inline(always)] #[inline]
fn offset(i: uint, j: uint) -> uint fn offset(i: uint, j: uint) -> uint
{ i * Dim::dim::<D>() + j } { i * Dim::dim::<D>() + j }
#[inline(always)] #[inline]
fn set(&mut self, i: uint, j: uint, t: &N) fn set(&mut self, i: uint, j: uint, t: &N)
{ self.mij.set(i, j, t) } { self.mij.set(i, j, t) }
} }
impl<D: Dim, N> Dim for NMat<D, N> impl<D: Dim, N> Dim for NMat<D, N>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ Dim::dim::<D>() } { Dim::dim::<D>() }
} }
impl<D: Dim, N: Copy> Index<(uint, uint), N> for NMat<D, N> impl<D: Dim, N: Copy> Index<(uint, uint), N> for NMat<D, N>
{ {
#[inline(always)] #[inline]
fn index(&self, &idx: &(uint, uint)) -> N fn index(&self, &idx: &(uint, uint)) -> N
{ self.mij[idx] } { self.mij[idx] }
} }
impl<D: Dim, N: Copy + One + Zero> One for NMat<D, N> impl<D: Dim, N: Copy + One + Zero> One for NMat<D, N>
{ {
#[inline(always)] #[inline]
fn one() -> NMat<D, N> fn one() -> NMat<D, N>
{ NMat { mij: one_mat_with_dim(Dim::dim::<D>()) } } { NMat { mij: one_mat_with_dim(Dim::dim::<D>()) } }
} }
impl<D: Dim, N: Copy + Zero> Zero for NMat<D, N> impl<D: Dim, N: Copy + Zero> Zero for NMat<D, N>
{ {
#[inline(always)] #[inline]
fn zero() -> NMat<D, N> fn zero() -> NMat<D, N>
{ NMat { mij: zero_mat_with_dim(Dim::dim::<D>()) } } { NMat { mij: zero_mat_with_dim(Dim::dim::<D>()) } }
#[inline(always)] #[inline]
fn is_zero(&self) -> bool fn is_zero(&self) -> bool
{ is_zero_mat(&self.mij) } { is_zero_mat(&self.mij) }
} }
@ -126,18 +126,18 @@ LMul<NVec<D, N>> for NMat<D, N>
impl<D: Dim, N: Clone + Copy + Eq + DivisionRing> impl<D: Dim, N: Clone + Copy + Eq + DivisionRing>
Inv for NMat<D, N> Inv for NMat<D, N>
{ {
#[inline(always)] #[inline]
fn inverse(&self) -> NMat<D, N> fn inverse(&self) -> NMat<D, N>
{ NMat { mij: self.mij.inverse() } } { NMat { mij: self.mij.inverse() } }
#[inline(always)] #[inline]
fn invert(&mut self) fn invert(&mut self)
{ self.mij.invert() } { self.mij.invert() }
} }
impl<D: Dim, N:Copy> Transpose for NMat<D, N> impl<D: Dim, N:Copy> Transpose for NMat<D, N>
{ {
#[inline(always)] #[inline]
fn transposed(&self) -> NMat<D, N> fn transposed(&self) -> NMat<D, N>
{ {
let mut res = copy *self; let mut res = copy *self;
@ -147,22 +147,22 @@ impl<D: Dim, N:Copy> Transpose for NMat<D, N>
res res
} }
#[inline(always)] #[inline]
fn transpose(&mut self) fn transpose(&mut self)
{ self.mij.transpose() } { self.mij.transpose() }
} }
impl<D, N: ApproxEq<N>> ApproxEq<N> for NMat<D, N> impl<D, N: ApproxEq<N>> ApproxEq<N> for NMat<D, N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &NMat<D, N>) -> bool fn approx_eq(&self, other: &NMat<D, N>) -> bool
{ self.mij.approx_eq(&other.mij) } { self.mij.approx_eq(&other.mij) }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &NMat<D, N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &NMat<D, N>, epsilon: &N) -> bool
{ self.mij.approx_eq_eps(&other.mij, epsilon) } { self.mij.approx_eq_eps(&other.mij, epsilon) }
} }
@ -186,11 +186,11 @@ impl<D: Dim, N: Rand + Zero + Copy> Rand for NMat<D, N>
impl<D: Dim, N: Zero + Copy> Flatten<N> for NMat<D, N> impl<D: Dim, N: Zero + Copy> Flatten<N> for NMat<D, N>
{ {
#[inline(always)] #[inline]
fn flat_size() -> uint fn flat_size() -> uint
{ Dim::dim::<D>() * Dim::dim::<D>() } { Dim::dim::<D>() * Dim::dim::<D>() }
#[inline(always)] #[inline]
fn from_flattened(l: &[N], off: uint) -> NMat<D, N> fn from_flattened(l: &[N], off: uint) -> NMat<D, N>
{ {
let dim = Dim::dim::<D>(); let dim = Dim::dim::<D>();
@ -202,7 +202,7 @@ impl<D: Dim, N: Zero + Copy> Flatten<N> for NMat<D, N>
res res
} }
#[inline(always)] #[inline]
fn flatten(&self) -> ~[N] fn flatten(&self) -> ~[N]
{ {
let dim = Dim::dim::<D>(); let dim = Dim::dim::<D>();
@ -214,7 +214,7 @@ impl<D: Dim, N: Zero + Copy> Flatten<N> for NMat<D, N>
res res
} }
#[inline(always)] #[inline]
fn flatten_to(&self, l: &mut [N], off: uint) fn flatten_to(&self, l: &mut [N], off: uint)
{ {
let dim = Dim::dim::<D>(); let dim = Dim::dim::<D>();

View File

@ -26,35 +26,35 @@ pub struct NVec<D, N>
impl<D: Dim, N> Dim for NVec<D, N> impl<D: Dim, N> Dim for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn dim() -> uint fn dim() -> uint
{ Dim::dim::<D>() } { Dim::dim::<D>() }
} }
impl<D, N: Clone> Clone for NVec<D, N> impl<D, N: Clone> Clone for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn clone(&self) -> NVec<D, N> fn clone(&self) -> NVec<D, N>
{ NVec{ at: self.at.clone() } } { NVec{ at: self.at.clone() } }
} }
impl<D, N: Copy + Add<N,N>> Add<NVec<D, N>, NVec<D, N>> for NVec<D, N> impl<D, N: Copy + Add<N,N>> Add<NVec<D, N>, NVec<D, N>> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn add(&self, other: &NVec<D, N>) -> NVec<D, N> fn add(&self, other: &NVec<D, N>) -> NVec<D, N>
{ NVec { at: self.at + other.at } } { NVec { at: self.at + other.at } }
} }
impl<D, N: Copy + Sub<N,N>> Sub<NVec<D, N>, NVec<D, N>> for NVec<D, N> impl<D, N: Copy + Sub<N,N>> Sub<NVec<D, N>, NVec<D, N>> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn sub(&self, other: &NVec<D, N>) -> NVec<D, N> fn sub(&self, other: &NVec<D, N>) -> NVec<D, N>
{ NVec { at: self.at - other.at } } { NVec { at: self.at - other.at } }
} }
impl<D, N: Neg<N>> Neg<NVec<D, N>> for NVec<D, N> impl<D, N: Neg<N>> Neg<NVec<D, N>> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn neg(&self) -> NVec<D, N> fn neg(&self) -> NVec<D, N>
{ NVec { at: -self.at } } { NVec { at: -self.at } }
} }
@ -62,14 +62,14 @@ impl<D, N: Neg<N>> Neg<NVec<D, N>> for NVec<D, N>
impl<D: Dim, N: Ring> impl<D: Dim, N: Ring>
Dot<N> for NVec<D, N> Dot<N> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn dot(&self, other: &NVec<D, N>) -> N fn dot(&self, other: &NVec<D, N>) -> N
{ self.at.dot(&other.at) } { self.at.dot(&other.at) }
} }
impl<D: Dim, N: Ring> SubDot<N> for NVec<D, N> impl<D: Dim, N: Ring> SubDot<N> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn sub_dot(&self, a: &NVec<D, N>, b: &NVec<D, N>) -> N fn sub_dot(&self, a: &NVec<D, N>, b: &NVec<D, N>) -> N
{ self.at.sub_dot(&a.at, &b.at) } { self.at.sub_dot(&a.at, &b.at) }
} }
@ -77,11 +77,11 @@ impl<D: Dim, N: Ring> SubDot<N> for NVec<D, N>
impl<D: Dim, N: Mul<N, N>> impl<D: Dim, N: Mul<N, N>>
ScalarMul<N> for NVec<D, N> ScalarMul<N> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn scalar_mul(&self, s: &N) -> NVec<D, N> fn scalar_mul(&self, s: &N) -> NVec<D, N>
{ NVec { at: self.at.scalar_mul(s) } } { NVec { at: self.at.scalar_mul(s) } }
#[inline(always)] #[inline]
fn scalar_mul_inplace(&mut self, s: &N) fn scalar_mul_inplace(&mut self, s: &N)
{ self.at.scalar_mul_inplace(s) } { self.at.scalar_mul_inplace(s) }
} }
@ -90,11 +90,11 @@ ScalarMul<N> for NVec<D, N>
impl<D: Dim, N: Div<N, N>> impl<D: Dim, N: Div<N, N>>
ScalarDiv<N> for NVec<D, N> ScalarDiv<N> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn scalar_div(&self, s: &N) -> NVec<D, N> fn scalar_div(&self, s: &N) -> NVec<D, N>
{ NVec { at: self.at.scalar_div(s) } } { NVec { at: self.at.scalar_div(s) } }
#[inline(always)] #[inline]
fn scalar_div_inplace(&mut self, s: &N) fn scalar_div_inplace(&mut self, s: &N)
{ self.at.scalar_div_inplace(s) } { self.at.scalar_div_inplace(s) }
} }
@ -102,11 +102,11 @@ ScalarDiv<N> for NVec<D, N>
impl<D: Dim, N: Add<N, N>> impl<D: Dim, N: Add<N, N>>
ScalarAdd<N> for NVec<D, N> ScalarAdd<N> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn scalar_add(&self, s: &N) -> NVec<D, N> fn scalar_add(&self, s: &N) -> NVec<D, N>
{ NVec { at: self.at.scalar_add(s) } } { NVec { at: self.at.scalar_add(s) } }
#[inline(always)] #[inline]
fn scalar_add_inplace(&mut self, s: &N) fn scalar_add_inplace(&mut self, s: &N)
{ self.at.scalar_add_inplace(s) } { self.at.scalar_add_inplace(s) }
} }
@ -114,29 +114,29 @@ ScalarAdd<N> for NVec<D, N>
impl<D: Dim, N: Sub<N, N>> impl<D: Dim, N: Sub<N, N>>
ScalarSub<N> for NVec<D, N> ScalarSub<N> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn scalar_sub(&self, s: &N) -> NVec<D, N> fn scalar_sub(&self, s: &N) -> NVec<D, N>
{ NVec { at: self.at.scalar_sub(s) } } { NVec { at: self.at.scalar_sub(s) } }
#[inline(always)] #[inline]
fn scalar_sub_inplace(&mut self, s: &N) fn scalar_sub_inplace(&mut self, s: &N)
{ self.at.scalar_sub_inplace(s) } { self.at.scalar_sub_inplace(s) }
} }
impl<D: Dim, N: Clone + Copy + Add<N, N>> Translation<NVec<D, N>> for NVec<D, N> impl<D: Dim, N: Clone + Copy + Add<N, N>> Translation<NVec<D, N>> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn translation(&self) -> NVec<D, N> fn translation(&self) -> NVec<D, N>
{ self.clone() } { self.clone() }
#[inline(always)] #[inline]
fn translate(&mut self, t: &NVec<D, N>) fn translate(&mut self, t: &NVec<D, N>)
{ *self = *self + *t; } { *self = *self + *t; }
} }
impl<D: Dim, N: Add<N, N> + Copy> Translatable<NVec<D, N>, NVec<D, N>> for NVec<D, N> impl<D: Dim, N: Add<N, N> + Copy> Translatable<NVec<D, N>, NVec<D, N>> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn translated(&self, t: &NVec<D, N>) -> NVec<D, N> fn translated(&self, t: &NVec<D, N>) -> NVec<D, N>
{ self + *t } { self + *t }
} }
@ -144,15 +144,15 @@ impl<D: Dim, N: Add<N, N> + Copy> Translatable<NVec<D, N>, NVec<D, N>> for NVec<
impl<D: Dim, N: Copy + DivisionRing + Algebraic + Clone> impl<D: Dim, N: Copy + DivisionRing + Algebraic + Clone>
Norm<N> for NVec<D, N> Norm<N> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn sqnorm(&self) -> N fn sqnorm(&self) -> N
{ self.at.sqnorm() } { self.at.sqnorm() }
#[inline(always)] #[inline]
fn norm(&self) -> N fn norm(&self) -> N
{ self.at.norm() } { self.at.norm() }
#[inline(always)] #[inline]
fn normalized(&self) -> NVec<D, N> fn normalized(&self) -> NVec<D, N>
{ {
let mut res : NVec<D, N> = self.clone(); let mut res : NVec<D, N> = self.clone();
@ -162,7 +162,7 @@ Norm<N> for NVec<D, N>
res res
} }
#[inline(always)] #[inline]
fn normalize(&mut self) -> N fn normalize(&mut self) -> N
{ self.at.normalize() } { self.at.normalize() }
} }
@ -171,11 +171,11 @@ impl<D: Dim,
N: Copy + DivisionRing + Algebraic + Clone + ApproxEq<N>> N: Copy + DivisionRing + Algebraic + Clone + ApproxEq<N>>
Basis for NVec<D, N> Basis for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn canonical_basis() -> ~[NVec<D, N>] fn canonical_basis() -> ~[NVec<D, N>]
{ map(DVec::canonical_basis_with_dim(Dim::dim::<D>()), |&e| NVec { at: e }) } { map(DVec::canonical_basis_with_dim(Dim::dim::<D>()), |&e| NVec { at: e }) }
#[inline(always)] #[inline]
fn orthogonal_subspace_basis(&self) -> ~[NVec<D, N>] fn orthogonal_subspace_basis(&self) -> ~[NVec<D, N>]
{ map(self.at.orthogonal_subspace_basis(), |&e| NVec { at: e }) } { map(self.at.orthogonal_subspace_basis(), |&e| NVec { at: e }) }
} }
@ -190,33 +190,33 @@ Basis for NVec<D, N>
impl<D: Dim, N: Copy + Zero> Zero for NVec<D, N> impl<D: Dim, N: Copy + Zero> Zero for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn zero() -> NVec<D, N> fn zero() -> NVec<D, N>
{ NVec { at: zero_vec_with_dim(Dim::dim::<D>()) } } { NVec { at: zero_vec_with_dim(Dim::dim::<D>()) } }
#[inline(always)] #[inline]
fn is_zero(&self) -> bool fn is_zero(&self) -> bool
{ is_zero_vec(&self.at) } { is_zero_vec(&self.at) }
} }
impl<D, N: ApproxEq<N>> ApproxEq<N> for NVec<D, N> impl<D, N: ApproxEq<N>> ApproxEq<N> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn approx_epsilon() -> N fn approx_epsilon() -> N
{ ApproxEq::approx_epsilon::<N, N>() } { ApproxEq::approx_epsilon::<N, N>() }
#[inline(always)] #[inline]
fn approx_eq(&self, other: &NVec<D, N>) -> bool fn approx_eq(&self, other: &NVec<D, N>) -> bool
{ self.at.approx_eq(&other.at) } { self.at.approx_eq(&other.at) }
#[inline(always)] #[inline]
fn approx_eq_eps(&self, other: &NVec<D, N>, epsilon: &N) -> bool fn approx_eq_eps(&self, other: &NVec<D, N>, epsilon: &N) -> bool
{ self.at.approx_eq_eps(&other.at, epsilon) } { self.at.approx_eq_eps(&other.at, epsilon) }
} }
impl<D: Dim, N: Rand + Zero + Copy> Rand for NVec<D, N> impl<D: Dim, N: Rand + Zero + Copy> Rand for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn rand<R: Rng>(rng: &mut R) -> NVec<D, N> fn rand<R: Rng>(rng: &mut R) -> NVec<D, N>
{ {
let dim = Dim::dim::<D>(); let dim = Dim::dim::<D>();
@ -231,11 +231,11 @@ impl<D: Dim, N: Rand + Zero + Copy> Rand for NVec<D, N>
impl<D: Dim, N: Zero + Copy> Flatten<N> for NVec<D, N> impl<D: Dim, N: Zero + Copy> Flatten<N> for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn flat_size() -> uint fn flat_size() -> uint
{ Dim::dim::<D>() } { Dim::dim::<D>() }
#[inline(always)] #[inline]
fn from_flattened(l: &[N], off: uint) -> NVec<D, N> fn from_flattened(l: &[N], off: uint) -> NVec<D, N>
{ {
let dim = Dim::dim::<D>(); let dim = Dim::dim::<D>();
@ -247,7 +247,7 @@ impl<D: Dim, N: Zero + Copy> Flatten<N> for NVec<D, N>
res res
} }
#[inline(always)] #[inline]
fn flatten(&self) -> ~[N] fn flatten(&self) -> ~[N]
{ {
let dim = Dim::dim::<D>(); let dim = Dim::dim::<D>();
@ -259,7 +259,7 @@ impl<D: Dim, N: Zero + Copy> Flatten<N> for NVec<D, N>
res res
} }
#[inline(always)] #[inline]
fn flatten_to(&self, l: &mut [N], off: uint) fn flatten_to(&self, l: &mut [N], off: uint)
{ {
let dim = Dim::dim::<D>(); let dim = Dim::dim::<D>();
@ -271,11 +271,11 @@ impl<D: Dim, N: Zero + Copy> Flatten<N> for NVec<D, N>
impl<D: Dim, N: Bounded + Zero + Add<N, N> + Copy> Bounded for NVec<D, N> impl<D: Dim, N: Bounded + Zero + Add<N, N> + Copy> Bounded for NVec<D, N>
{ {
#[inline(always)] #[inline]
fn max_value() -> NVec<D, N> fn max_value() -> NVec<D, N>
{ Zero::zero::<NVec<D, N>>().scalar_add(&Bounded::max_value()) } { Zero::zero::<NVec<D, N>>().scalar_add(&Bounded::max_value()) }
#[inline(always)] #[inline]
fn min_value() -> NVec<D, N> fn min_value() -> NVec<D, N>
{ Zero::zero::<NVec<D, N>>().scalar_add(&Bounded::min_value()) } { Zero::zero::<NVec<D, N>>().scalar_add(&Bounded::min_value()) }
} }

View File

@ -26,7 +26,7 @@ pub trait Rotatable<V, Res: Rotation<V>>
* - `ammount`: the rotation to apply. * - `ammount`: the rotation to apply.
* - `point`: the center of rotation. * - `point`: the center of rotation.
*/ */
#[inline(always)] #[inline]
pub fn rotate_wrt_point<M: Translatable<LV, M2>, pub fn rotate_wrt_point<M: Translatable<LV, M2>,
M2: Rotation<AV> + Translation<LV>, M2: Rotation<AV> + Translation<LV>,
LV: Neg<LV>, LV: Neg<LV>,