Removed a lot of Copy + made Rotation and Translation more flexible.
This commit is contained in:
parent
edc5bb616d
commit
ffbcf4882a
|
@ -14,16 +14,7 @@ use dim3::vec3::{Vec3};
|
||||||
|
|
||||||
#[deriving(Eq, ToStr)]
|
#[deriving(Eq, ToStr)]
|
||||||
pub struct Rotmat<M>
|
pub struct Rotmat<M>
|
||||||
{
|
{ priv submat: M }
|
||||||
priv submat: M
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M: Copy> Rotmat<M>
|
|
||||||
{
|
|
||||||
#[inline(always)]
|
|
||||||
fn submat(&self) -> M
|
|
||||||
{ copy self.submat }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn rotmat2<N: Copy + Trigonometric + Neg<N>>(angle: N) -> Rotmat<Mat2<N>>
|
pub fn rotmat2<N: Copy + Trigonometric + Neg<N>>(angle: N) -> Rotmat<Mat2<N>>
|
||||||
{
|
{
|
||||||
|
@ -66,7 +57,7 @@ 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>, Rotmat<Mat2<N>>> for Rotmat<Mat2<N>>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rotation(&self) -> Vec1<N>
|
fn rotation(&self) -> Vec1<N>
|
||||||
|
@ -83,7 +74,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 +
|
||||||
One + Sub<N, N>>
|
One + Sub<N, N>>
|
||||||
Rotation<(Vec3<N>, N)> for Rotmat<Mat3<N>>
|
Rotation<(Vec3<N>, N), Rotmat<Mat3<N>>> for Rotmat<Mat3<N>>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rotation(&self) -> (Vec3<N>, N)
|
fn rotation(&self) -> (Vec3<N>, N)
|
||||||
|
@ -121,14 +112,14 @@ impl<M: Dim> Dim for Rotmat<M>
|
||||||
{ Dim::dim::<M>() }
|
{ Dim::dim::<M>() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Copy + One + Zero> One for Rotmat<M>
|
impl<M: One + Zero> One for Rotmat<M>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn one() -> Rotmat<M>
|
fn one() -> Rotmat<M>
|
||||||
{ Rotmat { submat: One::one() } }
|
{ Rotmat { submat: One::one() } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Copy + 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(always)]
|
||||||
fn mul(&self, other: &Rotmat<M>) -> Rotmat<M>
|
fn mul(&self, other: &Rotmat<M>) -> Rotmat<M>
|
||||||
|
@ -156,14 +147,14 @@ impl<M: Copy> DeltaTransform<M> for Rotmat<M>
|
||||||
{ copy self.submat }
|
{ copy self.submat }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: RMul<V> + Copy, V: Copy> DeltaTransformVector<V> for Rotmat<M>
|
impl<M: RMul<V>, V> DeltaTransformVector<V> for Rotmat<M>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
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: Copy + Transpose> Inv for Rotmat<M>
|
impl<M: Transpose> Inv for Rotmat<M>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn invert(&mut self)
|
fn invert(&mut self)
|
||||||
|
@ -174,7 +165,7 @@ impl<M: Copy + Transpose> Inv for Rotmat<M>
|
||||||
{ self.transposed() }
|
{ self.transposed() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Copy + Transpose>
|
impl<M: Transpose>
|
||||||
Transpose for Rotmat<M>
|
Transpose for Rotmat<M>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub struct Transform<M, V>
|
||||||
priv subtrans : V
|
priv subtrans : V
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Copy, V: Copy> Transform<M, V>
|
impl<M, V> Transform<M, V>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new(mat: M, trans: V) -> Transform<M, V>
|
pub fn new(mat: M, trans: V) -> Transform<M, V>
|
||||||
|
@ -30,14 +30,14 @@ impl<M:Dim, V> Dim for Transform<M, V>
|
||||||
{ Dim::dim::<M>() }
|
{ Dim::dim::<M>() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M:Copy + One, V:Copy + Zero> One for Transform<M, V>
|
impl<M: One, V: Zero> One for Transform<M, V>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
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:Copy + Zero, V:Copy + Zero> Zero for Transform<M, V>
|
impl<M: Zero, V: Zero> Zero for Transform<M, V>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn zero() -> Transform<M, V>
|
fn zero() -> Transform<M, V>
|
||||||
|
@ -48,7 +48,7 @@ impl<M:Copy + Zero, V:Copy + Zero> Zero for Transform<M, V>
|
||||||
{ self.submat.is_zero() && self.subtrans.is_zero() }
|
{ self.submat.is_zero() && self.subtrans.is_zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M:Copy + RMul<V> + Mul<M, M>, V:Copy + 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(always)]
|
||||||
|
@ -73,14 +73,14 @@ impl<M: LMul<V>, V: Add<V, V>> LMul<V> for Transform<M, V>
|
||||||
{ self.submat.lmul(other) + self.subtrans }
|
{ self.submat.lmul(other) + self.subtrans }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Copy, V: Copy + Translation<V>> Translation<V> for Transform<M, V>
|
impl<M: Copy, V: Translation<V, Res>, Res> Translation<V, Transform<M, Res>> for Transform<M, V>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translation(&self) -> V
|
fn translation(&self) -> V
|
||||||
{ self.subtrans.translation() }
|
{ self.subtrans.translation() }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translated(&self, t: &V) -> Transform<M, V>
|
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)) }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -88,15 +88,18 @@ impl<M: Copy, V: Copy + Translation<V>> Translation<V> for Transform<M, V>
|
||||||
{ self.subtrans.translate(t) }
|
{ self.subtrans.translate(t) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Rotation<AV> + Copy + RMul<V> + One, V: Copy, AV>
|
impl<M: Rotation<AV, Res> + One,
|
||||||
Rotation<AV> for Transform<M, V>
|
Res: RMul<V>,
|
||||||
|
V,
|
||||||
|
AV>
|
||||||
|
Rotation<AV, Transform<Res, V>> for Transform<M, V>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rotation(&self) -> AV
|
fn rotation(&self) -> AV
|
||||||
{ self.submat.rotation() }
|
{ self.submat.rotation() }
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rotated(&self, rot: &AV) -> Transform<M, V>
|
fn rotated(&self, rot: &AV) -> Transform<Res, V>
|
||||||
{
|
{
|
||||||
// FIXME: this does not seem opitmal
|
// FIXME: this does not seem opitmal
|
||||||
let delta = One::one::<M>().rotated(rot);
|
let delta = One::one::<M>().rotated(rot);
|
||||||
|
@ -121,14 +124,14 @@ impl<M: Copy, V> DeltaTransform<M> for Transform<M, V>
|
||||||
{ copy self.submat }
|
{ copy self.submat }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: RMul<V> + Copy, V> DeltaTransformVector<V> for Transform<M, V>
|
impl<M: RMul<V>, V> DeltaTransformVector<V> for Transform<M, V>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
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: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(always)]
|
||||||
|
@ -171,7 +174,7 @@ ApproxEq<N> for Transform<M, V>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Rand + Copy, V: Rand + Copy> Rand for Transform<M, V>
|
impl<M: Rand, V: Rand> Rand for Transform<M, V>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Transform<M, V>
|
fn rand<R: Rng>(rng: &mut R) -> Transform<M, V>
|
||||||
|
|
|
@ -12,7 +12,7 @@ use dim1::vec1::Vec1;
|
||||||
pub struct Mat1<N>
|
pub struct Mat1<N>
|
||||||
{ m11: N }
|
{ m11: N }
|
||||||
|
|
||||||
impl<N: Copy> Mat1<N>
|
impl<N> Mat1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new(m11: N) -> Mat1<N>
|
pub fn new(m11: N) -> Mat1<N>
|
||||||
|
@ -29,14 +29,14 @@ impl<N> Dim for Mat1<N>
|
||||||
{ 1 }
|
{ 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + One> One for Mat1<N>
|
impl<N: One> One for Mat1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn one() -> Mat1<N>
|
fn one() -> Mat1<N>
|
||||||
{ return Mat1::new(One::one()) }
|
{ return Mat1::new(One::one()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + Zero> Zero for Mat1<N>
|
impl<N: Zero> Zero for Mat1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn zero() -> Mat1<N>
|
fn zero() -> Mat1<N>
|
||||||
|
@ -47,21 +47,21 @@ impl<N:Copy + Zero> Zero for Mat1<N>
|
||||||
{ self.m11.is_zero() }
|
{ self.m11.is_zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
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:Copy + 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(always)]
|
||||||
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:Copy + 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(always)]
|
||||||
fn lmul(&self, other: &Vec1<N>) -> Vec1<N>
|
fn lmul(&self, other: &Vec1<N>) -> Vec1<N>
|
||||||
|
@ -90,7 +90,7 @@ Inv for Mat1<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy> Transpose for Mat1<N>
|
impl<N: Copy> Transpose for Mat1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn transposed(&self) -> Mat1<N>
|
fn transposed(&self) -> Mat1<N>
|
||||||
|
@ -116,7 +116,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Mat1<N>
|
||||||
{ self.m11.approx_eq_eps(&other.m11, epsilon) }
|
{ self.m11.approx_eq_eps(&other.m11, epsilon) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Rand + Copy> Rand for Mat1<N>
|
impl<N: Rand > Rand for Mat1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Mat1<N>
|
fn rand<R: Rng>(rng: &mut R) -> Mat1<N>
|
||||||
|
|
|
@ -14,7 +14,7 @@ use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
||||||
pub struct Vec1<N>
|
pub struct Vec1<N>
|
||||||
{ x : N }
|
{ x : N }
|
||||||
|
|
||||||
impl<N: Copy> Vec1<N>
|
impl<N> Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new(x: N) -> Vec1<N>
|
pub fn new(x: N) -> Vec1<N>
|
||||||
|
@ -28,21 +28,21 @@ impl<N> Dim for Vec1<N>
|
||||||
{ 1 }
|
{ 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
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:Copy + 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(always)]
|
||||||
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) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Mul<N, N>>
|
impl<N: Mul<N, N>>
|
||||||
ScalarMul<N> for Vec1<N>
|
ScalarMul<N> for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -51,11 +51,11 @@ ScalarMul<N> for Vec1<N>
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_mul_inplace(&mut self, s: &N)
|
fn scalar_mul_inplace(&mut self, s: &N)
|
||||||
{ self.x = self.x * copy *s; }
|
{ self.x = self.x * *s; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<N: Copy + Div<N, N>>
|
impl<N: Div<N, N>>
|
||||||
ScalarDiv<N> for Vec1<N>
|
ScalarDiv<N> for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -64,10 +64,10 @@ ScalarDiv<N> for Vec1<N>
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_div_inplace(&mut self, s: &N)
|
fn scalar_div_inplace(&mut self, s: &N)
|
||||||
{ self.x = self.x / copy *s; }
|
{ self.x = self.x / *s; }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Add<N, N>>
|
impl<N: Add<N, N>>
|
||||||
ScalarAdd<N> for Vec1<N>
|
ScalarAdd<N> for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -76,10 +76,10 @@ ScalarAdd<N> for Vec1<N>
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_add_inplace(&mut self, s: &N)
|
fn scalar_add_inplace(&mut self, s: &N)
|
||||||
{ self.x = self.x + copy *s; }
|
{ self.x = self.x + *s; }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Sub<N, N>>
|
impl<N: Sub<N, N>>
|
||||||
ScalarSub<N> for Vec1<N>
|
ScalarSub<N> for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -88,10 +88,10 @@ ScalarSub<N> for Vec1<N>
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_sub_inplace(&mut self, s: &N)
|
fn scalar_sub_inplace(&mut self, s: &N)
|
||||||
{ self.x = self.x - copy *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>, Vec1<N>> for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translation(&self) -> Vec1<N>
|
fn translation(&self) -> Vec1<N>
|
||||||
|
@ -103,24 +103,24 @@ impl<N: Copy + Add<N, N>> Translation<Vec1<N>> for Vec1<N>
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translate(&mut self, t: &Vec1<N>)
|
fn translate(&mut self, t: &Vec1<N>)
|
||||||
{ *self = *self + copy *t }
|
{ *self = *self + *t }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + Mul<N, N>> Dot<N> for Vec1<N>
|
impl<N: Mul<N, N>> Dot<N> for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn dot(&self, other : &Vec1<N>) -> N
|
fn dot(&self, other : &Vec1<N>) -> N
|
||||||
{ self.x * other.x }
|
{ self.x * other.x }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
|
@ -140,20 +140,20 @@ Norm<N> for Vec1<N>
|
||||||
{
|
{
|
||||||
let l = self.norm();
|
let l = self.norm();
|
||||||
|
|
||||||
self.x = self.x / copy l;
|
self.x = self.x / l;
|
||||||
|
|
||||||
l
|
l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + Neg<N>> Neg<Vec1<N>> for Vec1<N>
|
impl<N: Neg<N>> Neg<Vec1<N>> for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn neg(&self) -> Vec1<N>
|
fn neg(&self) -> Vec1<N>
|
||||||
{ Vec1::new(-self.x) }
|
{ Vec1::new(-self.x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + Zero> Zero for Vec1<N>
|
impl<N: Zero> Zero for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn zero() -> Vec1<N>
|
fn zero() -> Vec1<N>
|
||||||
|
@ -167,7 +167,7 @@ impl<N:Copy + Zero> Zero for Vec1<N>
|
||||||
{ self.x.is_zero() }
|
{ self.x.is_zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + One> Basis for Vec1<N>
|
impl<N: One> Basis for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn canonical_basis() -> ~[Vec1<N>]
|
fn canonical_basis() -> ~[Vec1<N>]
|
||||||
|
@ -193,7 +193,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Vec1<N>
|
||||||
{ self.x.approx_eq_eps(&other.x, epsilon) }
|
{ self.x.approx_eq_eps(&other.x, epsilon) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Rand + Copy> Rand for Vec1<N>
|
impl<N: Rand> Rand for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Vec1<N>
|
fn rand<R: Rng>(rng: &mut R) -> Vec1<N>
|
||||||
|
@ -219,7 +219,7 @@ impl<N: Copy> Flatten<N> for Vec1<N>
|
||||||
{ l[off] = copy self.x }
|
{ l[off] = copy self.x }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Bounded + Copy> Bounded for Vec1<N>
|
impl<N: Bounded> Bounded for Vec1<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn max_value() -> Vec1<N>
|
fn max_value() -> Vec1<N>
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub struct Mat2<N>
|
||||||
m21: N, m22: N
|
m21: N, m22: N
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy> Mat2<N>
|
impl<N> Mat2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
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>
|
||||||
|
@ -36,14 +36,14 @@ impl<N> Dim for Mat2<N>
|
||||||
{ 2 }
|
{ 2 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + One + Zero> One for Mat2<N>
|
impl<N: Copy + One + Zero> One for Mat2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn one() -> Mat2<N>
|
fn one() -> Mat2<N>
|
||||||
{
|
{
|
||||||
let (_0, _1) = (Zero::zero(), One::one());
|
let (_0, _1) = (Zero::zero(), One::one());
|
||||||
return Mat2::new(copy _1, copy _0,
|
return Mat2::new(copy _1, copy _0,
|
||||||
copy _0, copy _1)
|
_0, _1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ impl<N:Copy + Zero> Zero for Mat2<N>
|
||||||
{
|
{
|
||||||
let _0 = Zero::zero();
|
let _0 = Zero::zero();
|
||||||
return Mat2::new(copy _0, copy _0,
|
return Mat2::new(copy _0, copy _0,
|
||||||
copy _0, copy _0)
|
copy _0, _0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -65,7 +65,7 @@ impl<N:Copy + Zero> Zero for Mat2<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
fn mul(&self, other: &Mat2<N>) -> Mat2<N>
|
fn mul(&self, other: &Mat2<N>) -> Mat2<N>
|
||||||
|
@ -79,7 +79,7 @@ impl<N:Copy + Mul<N, N> + Add<N, N>> Mul<Mat2<N>, Mat2<N>> for Mat2<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
fn rmul(&self, other: &Vec2<N>) -> Vec2<N>
|
fn rmul(&self, other: &Vec2<N>) -> Vec2<N>
|
||||||
|
@ -91,7 +91,7 @@ impl<N:Copy + Add<N, N> + Mul<N, N>> RMul<Vec2<N>> for Mat2<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
fn lmul(&self, other: &Vec2<N>) -> Vec2<N>
|
fn lmul(&self, other: &Vec2<N>) -> Vec2<N>
|
||||||
|
@ -128,7 +128,7 @@ Inv for Mat2<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy> Transpose for Mat2<N>
|
impl<N: Copy> Transpose for Mat2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn transposed(&self) -> Mat2<N>
|
fn transposed(&self) -> Mat2<N>
|
||||||
|
@ -169,7 +169,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Mat2<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Rand + Copy> Rand for Mat2<N>
|
impl<N: Rand> Rand for Mat2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Mat2<N>
|
fn rand<R: Rng>(rng: &mut R) -> Mat2<N>
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub struct Vec2<N>
|
||||||
y : N
|
y : N
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy> Vec2<N>
|
impl<N> Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new(x: N, y: N) -> Vec2<N>
|
pub fn new(x: N, y: N) -> Vec2<N>
|
||||||
|
@ -33,21 +33,21 @@ impl<N> Dim for Vec2<N>
|
||||||
{ 2 }
|
{ 2 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
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:Copy + 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(always)]
|
||||||
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) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Mul<N, N>>
|
impl<N: Mul<N, N>>
|
||||||
ScalarMul<N> for Vec2<N>
|
ScalarMul<N> for Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -57,13 +57,13 @@ ScalarMul<N> for Vec2<N>
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_mul_inplace(&mut self, s: &N)
|
fn scalar_mul_inplace(&mut self, s: &N)
|
||||||
{
|
{
|
||||||
self.x = self.x * copy *s;
|
self.x = self.x * *s;
|
||||||
self.y = self.y * copy *s;
|
self.y = self.y * *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<N: Copy + Div<N, N>>
|
impl<N: Div<N, N>>
|
||||||
ScalarDiv<N> for Vec2<N>
|
ScalarDiv<N> for Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -73,12 +73,12 @@ ScalarDiv<N> for Vec2<N>
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_div_inplace(&mut self, s: &N)
|
fn scalar_div_inplace(&mut self, s: &N)
|
||||||
{
|
{
|
||||||
self.x = self.x / copy *s;
|
self.x = self.x / *s;
|
||||||
self.y = self.y / copy *s;
|
self.y = self.y / *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Add<N, N>>
|
impl<N: Add<N, N>>
|
||||||
ScalarAdd<N> for Vec2<N>
|
ScalarAdd<N> for Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -88,12 +88,12 @@ ScalarAdd<N> for Vec2<N>
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_add_inplace(&mut self, s: &N)
|
fn scalar_add_inplace(&mut self, s: &N)
|
||||||
{
|
{
|
||||||
self.x = self.x + copy *s;
|
self.x = self.x + *s;
|
||||||
self.y = self.y + copy *s;
|
self.y = self.y + *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Sub<N, N>>
|
impl<N: Sub<N, N>>
|
||||||
ScalarSub<N> for Vec2<N>
|
ScalarSub<N> for Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -103,12 +103,12 @@ ScalarSub<N> for Vec2<N>
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_sub_inplace(&mut self, s: &N)
|
fn scalar_sub_inplace(&mut self, s: &N)
|
||||||
{
|
{
|
||||||
self.x = self.x - copy *s;
|
self.x = self.x - *s;
|
||||||
self.y = self.y - copy *s;
|
self.y = self.y - *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Add<N, N>> Translation<Vec2<N>> for Vec2<N>
|
impl<N: Copy + Add<N, N>> Translation<Vec2<N>, Vec2<N>> for Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translation(&self) -> Vec2<N>
|
fn translation(&self) -> Vec2<N>
|
||||||
|
@ -120,24 +120,24 @@ impl<N: Copy + Add<N, N>> Translation<Vec2<N>> for Vec2<N>
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translate(&mut self, t: &Vec2<N>)
|
fn translate(&mut self, t: &Vec2<N>)
|
||||||
{ *self = *self + copy *t; }
|
{ *self = *self + *t; }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
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:Copy + 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(always)]
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
|
@ -161,35 +161,32 @@ Norm<N> for Vec2<N>
|
||||||
{
|
{
|
||||||
let l = self.norm();
|
let l = self.norm();
|
||||||
|
|
||||||
self.x = self.x / copy l;
|
self.x = self.x / l;
|
||||||
self.y = self.y / copy l;
|
self.y = self.y / l;
|
||||||
|
|
||||||
copy l
|
l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
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:Copy + Neg<N>> Neg<Vec2<N>> for Vec2<N>
|
impl<N: Neg<N>> Neg<Vec2<N>> for Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn neg(&self) -> Vec2<N>
|
fn neg(&self) -> Vec2<N>
|
||||||
{ Vec2::new(-self.x, -self.y) }
|
{ Vec2::new(-self.x, -self.y) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + Zero> Zero for Vec2<N>
|
impl<N: Zero> Zero for Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn zero() -> Vec2<N>
|
fn zero() -> Vec2<N>
|
||||||
{
|
{ Vec2::new(Zero::zero(), Zero::zero()) }
|
||||||
let _0 = Zero::zero();
|
|
||||||
Vec2::new(copy _0, copy _0)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn is_zero(&self) -> bool
|
fn is_zero(&self) -> bool
|
||||||
|
@ -229,7 +226,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Vec2<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Rand + Copy> Rand for Vec2<N>
|
impl<N:Rand> Rand for Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Vec2<N>
|
fn rand<R: Rng>(rng: &mut R) -> Vec2<N>
|
||||||
|
@ -258,7 +255,7 @@ impl<N: Copy> Flatten<N> for Vec2<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Bounded + Copy> Bounded for Vec2<N>
|
impl<N: Bounded> Bounded for Vec2<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn max_value() -> Vec2<N>
|
fn max_value() -> Vec2<N>
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub struct Mat3<N>
|
||||||
m31: N, m32: N, m33: N
|
m31: N, m32: N, m33: N
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy> Mat3<N>
|
impl<N> Mat3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new(m11: N, m12: N, m13: N,
|
pub fn new(m11: N, m12: N, m13: N,
|
||||||
|
@ -27,8 +27,8 @@ impl<N: Copy> Mat3<N>
|
||||||
Mat3
|
Mat3
|
||||||
{
|
{
|
||||||
m11: m11, m12: m12, m13: m13,
|
m11: m11, m12: m12, m13: m13,
|
||||||
m21: m21, m22: m22, m23: m23,
|
m21: m21, m22: m22, m23: m23,
|
||||||
m31: m31, m32: m32, m33: m33
|
m31: m31, m32: m32, m33: m33
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ impl<N> Dim for Mat3<N>
|
||||||
{ 3 }
|
{ 3 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + One + Zero> One for Mat3<N>
|
impl<N: Copy + One + Zero> One for Mat3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn one() -> Mat3<N>
|
fn one() -> Mat3<N>
|
||||||
|
@ -48,11 +48,11 @@ impl<N:Copy + One + Zero> One for Mat3<N>
|
||||||
let (_0, _1) = (Zero::zero(), One::one());
|
let (_0, _1) = (Zero::zero(), One::one());
|
||||||
return Mat3::new(copy _1, copy _0, copy _0,
|
return Mat3::new(copy _1, copy _0, copy _0,
|
||||||
copy _0, copy _1, copy _0,
|
copy _0, copy _1, copy _0,
|
||||||
copy _0, copy _0, copy _1)
|
copy _0, _0, _1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + Zero> Zero for Mat3<N>
|
impl<N: Copy + Zero> Zero for Mat3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn zero() -> Mat3<N>
|
fn zero() -> Mat3<N>
|
||||||
|
@ -60,7 +60,7 @@ impl<N:Copy + Zero> Zero for Mat3<N>
|
||||||
let _0 = Zero::zero();
|
let _0 = Zero::zero();
|
||||||
return Mat3::new(copy _0, copy _0, copy _0,
|
return Mat3::new(copy _0, copy _0, copy _0,
|
||||||
copy _0, copy _0, copy _0,
|
copy _0, copy _0, copy _0,
|
||||||
copy _0, copy _0, copy _0)
|
copy _0, copy _0, _0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -72,7 +72,7 @@ impl<N:Copy + Zero> Zero for Mat3<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
fn mul(&self, other: &Mat3<N>) -> Mat3<N>
|
fn mul(&self, other: &Mat3<N>) -> Mat3<N>
|
||||||
|
@ -93,7 +93,7 @@ impl<N:Copy + Mul<N, N> + Add<N, N>> Mul<Mat3<N>, Mat3<N>> for Mat3<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
fn rmul(&self, other: &Vec3<N>) -> Vec3<N>
|
fn rmul(&self, other: &Vec3<N>) -> Vec3<N>
|
||||||
|
@ -106,7 +106,7 @@ impl<N:Copy + Add<N, N> + Mul<N, N>> RMul<Vec3<N>> for Mat3<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
fn lmul(&self, other: &Vec3<N>) -> Vec3<N>
|
fn lmul(&self, other: &Vec3<N>) -> Vec3<N>
|
||||||
|
@ -219,7 +219,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Mat3<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Rand + Copy> Rand for Mat3<N>
|
impl<N: Rand> Rand for Mat3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Mat3<N>
|
fn rand<R: Rng>(rng: &mut R) -> Mat3<N>
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub struct Vec3<N>
|
||||||
z : N
|
z : N
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy> Vec3<N>
|
impl<N> Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new(x: N, y: N, z: N) -> Vec3<N>
|
pub fn new(x: N, y: N, z: N) -> Vec3<N>
|
||||||
|
@ -33,21 +33,21 @@ impl<N> Dim for Vec3<N>
|
||||||
{ 3 }
|
{ 3 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
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:Copy + 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(always)]
|
||||||
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) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Mul<N, N>>
|
impl<N: Mul<N, N>>
|
||||||
ScalarMul<N> for Vec3<N>
|
ScalarMul<N> for Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -57,14 +57,14 @@ ScalarMul<N> for Vec3<N>
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_mul_inplace(&mut self, s: &N)
|
fn scalar_mul_inplace(&mut self, s: &N)
|
||||||
{
|
{
|
||||||
self.x = self.x * copy *s;
|
self.x = self.x * *s;
|
||||||
self.y = self.y * copy *s;
|
self.y = self.y * *s;
|
||||||
self.z = self.z * copy *s;
|
self.z = self.z * *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<N: Copy + Div<N, N>>
|
impl<N: Div<N, N>>
|
||||||
ScalarDiv<N> for Vec3<N>
|
ScalarDiv<N> for Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -74,13 +74,13 @@ ScalarDiv<N> for Vec3<N>
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_div_inplace(&mut self, s: &N)
|
fn scalar_div_inplace(&mut self, s: &N)
|
||||||
{
|
{
|
||||||
self.x = self.x / copy *s;
|
self.x = self.x / *s;
|
||||||
self.y = self.y / copy *s;
|
self.y = self.y / *s;
|
||||||
self.z = self.z / copy *s;
|
self.z = self.z / *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Add<N, N>>
|
impl<N: Add<N, N>>
|
||||||
ScalarAdd<N> for Vec3<N>
|
ScalarAdd<N> for Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -90,13 +90,13 @@ ScalarAdd<N> for Vec3<N>
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_add_inplace(&mut self, s: &N)
|
fn scalar_add_inplace(&mut self, s: &N)
|
||||||
{
|
{
|
||||||
self.x = self.x + copy *s;
|
self.x = self.x + *s;
|
||||||
self.y = self.y + copy *s;
|
self.y = self.y + *s;
|
||||||
self.z = self.z + copy *s;
|
self.z = self.z + *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Sub<N, N>>
|
impl<N: Sub<N, N>>
|
||||||
ScalarSub<N> for Vec3<N>
|
ScalarSub<N> for Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -106,13 +106,13 @@ ScalarSub<N> for Vec3<N>
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn scalar_sub_inplace(&mut self, s: &N)
|
fn scalar_sub_inplace(&mut self, s: &N)
|
||||||
{
|
{
|
||||||
self.x = self.x - copy *s;
|
self.x = self.x - *s;
|
||||||
self.y = self.y - copy *s;
|
self.y = self.y - *s;
|
||||||
self.z = self.z - copy *s;
|
self.z = self.z - *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Add<N, N>> Translation<Vec3<N>> for Vec3<N>
|
impl<N: Copy + Add<N, N>> Translation<Vec3<N>, Vec3<N>> for Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translation(&self) -> Vec3<N>
|
fn translation(&self) -> Vec3<N>
|
||||||
|
@ -124,33 +124,33 @@ impl<N: Copy + Add<N, N>> Translation<Vec3<N>> for Vec3<N>
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translate(&mut self, t: &Vec3<N>)
|
fn translate(&mut self, t: &Vec3<N>)
|
||||||
{ *self = *self + copy *t; }
|
{ *self = *self + *t; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl<N:Copy + Neg<N>> Neg<Vec3<N>> for Vec3<N>
|
impl<N: Neg<N>> Neg<Vec3<N>> for Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
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:Copy + 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(always)]
|
||||||
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:Copy + 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(always)]
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
|
@ -174,15 +174,15 @@ Norm<N> for Vec3<N>
|
||||||
{
|
{
|
||||||
let l = self.norm();
|
let l = self.norm();
|
||||||
|
|
||||||
self.x = self.x / copy l;
|
self.x = self.x / l;
|
||||||
self.y = self.y / copy l;
|
self.y = self.y / l;
|
||||||
self.z = self.z / copy l;
|
self.z = self.z / l;
|
||||||
|
|
||||||
l
|
l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + 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(always)]
|
||||||
fn cross(&self, other : &Vec3<N>) -> Vec3<N>
|
fn cross(&self, other : &Vec3<N>) -> Vec3<N>
|
||||||
|
@ -195,14 +195,11 @@ impl<N:Copy + Mul<N, N> + Sub<N, N>> Cross<Vec3<N>> for Vec3<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + Zero> Zero for Vec3<N>
|
impl<N: Zero> Zero for Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn zero() -> Vec3<N>
|
fn zero() -> Vec3<N>
|
||||||
{
|
{ Vec3::new(Zero::zero(), Zero::zero(), Zero::zero()) }
|
||||||
let _0 = Zero::zero();
|
|
||||||
Vec3::new(copy _0, copy _0, copy _0)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn is_zero(&self) -> bool
|
fn is_zero(&self) -> bool
|
||||||
|
@ -258,7 +255,7 @@ impl<N:ApproxEq<N>> ApproxEq<N> for Vec3<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N:Copy + Rand> Rand for Vec3<N>
|
impl<N: Rand> Rand for Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Vec3<N>
|
fn rand<R: Rng>(rng: &mut R) -> Vec3<N>
|
||||||
|
@ -288,7 +285,7 @@ impl<N: Copy> Flatten<N> for Vec3<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Bounded + Copy> Bounded for Vec3<N>
|
impl<N: Bounded> Bounded for Vec3<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn max_value() -> Vec3<N>
|
fn max_value() -> Vec3<N>
|
||||||
|
|
|
@ -97,14 +97,14 @@ impl<N: Copy + Sub<N,N>> Sub<DVec<N>, DVec<N>> for DVec<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Neg<N>> Neg<DVec<N>> for DVec<N>
|
impl<N: Neg<N>> Neg<DVec<N>> for DVec<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn neg(&self) -> DVec<N>
|
fn neg(&self) -> DVec<N>
|
||||||
{ DVec { at: map(self.at, |a| -a) } }
|
{ DVec { at: map(self.at, |a| -a) } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Ring>
|
impl<N: Ring>
|
||||||
Dot<N> for DVec<N>
|
Dot<N> for DVec<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -121,7 +121,7 @@ Dot<N> for DVec<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Ring> SubDot<N> for DVec<N>
|
impl<N: Ring> SubDot<N> for DVec<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn sub_dot(&self, a: &DVec<N>, b: &DVec<N>) -> N
|
fn sub_dot(&self, a: &DVec<N>, b: &DVec<N>) -> N
|
||||||
|
@ -135,7 +135,7 @@ impl<N: Copy + Ring> SubDot<N> for DVec<N>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Mul<N, N>>
|
impl<N: Mul<N, N>>
|
||||||
ScalarMul<N> for DVec<N>
|
ScalarMul<N> for DVec<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -146,12 +146,12 @@ ScalarMul<N> for DVec<N>
|
||||||
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|
|
||||||
{ self.at[i] = self.at[i] * copy *s; }
|
{ self.at[i] = self.at[i] * *s; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<N: Copy + Div<N, N>>
|
impl<N: Div<N, N>>
|
||||||
ScalarDiv<N> for DVec<N>
|
ScalarDiv<N> for DVec<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -162,11 +162,11 @@ ScalarDiv<N> for DVec<N>
|
||||||
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|
|
||||||
{ self.at[i] = self.at[i] / copy *s; }
|
{ self.at[i] = self.at[i] / *s; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Add<N, N>>
|
impl<N: Add<N, N>>
|
||||||
ScalarAdd<N> for DVec<N>
|
ScalarAdd<N> for DVec<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -177,11 +177,11 @@ ScalarAdd<N> for DVec<N>
|
||||||
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|
|
||||||
{ self.at[i] = self.at[i] + copy *s; }
|
{ self.at[i] = self.at[i] + *s; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Copy + Sub<N, N>>
|
impl<N: Sub<N, N>>
|
||||||
ScalarSub<N> for DVec<N>
|
ScalarSub<N> for DVec<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -192,11 +192,11 @@ ScalarSub<N> for DVec<N>
|
||||||
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|
|
||||||
{ self.at[i] = self.at[i] - copy *s; }
|
{ self.at[i] = self.at[i] - *s; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone + Copy + Add<N, N>> Translation<DVec<N>> for DVec<N>
|
impl<N: Clone + Copy + Add<N, N>> Translation<DVec<N>, DVec<N>> for DVec<N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translation(&self) -> DVec<N>
|
fn translation(&self) -> DVec<N>
|
||||||
|
@ -238,7 +238,7 @@ Norm<N> for DVec<N>
|
||||||
let l = self.norm();
|
let l = self.norm();
|
||||||
|
|
||||||
for iterate(0u, self.at.len()) |i|
|
for iterate(0u, self.at.len()) |i|
|
||||||
{ self.at[i] = self.at[i] / copy l; }
|
{ self.at[i] = self.at[i] / l; }
|
||||||
|
|
||||||
l
|
l
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,14 +52,14 @@ impl<D, N: Copy + Sub<N,N>> Sub<NVec<D, N>, NVec<D, N>> for NVec<D, N>
|
||||||
{ NVec { at: self.at - other.at } }
|
{ NVec { at: self.at - other.at } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D, N: Copy + 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(always)]
|
||||||
fn neg(&self) -> NVec<D, N>
|
fn neg(&self) -> NVec<D, N>
|
||||||
{ NVec { at: -self.at } }
|
{ NVec { at: -self.at } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dim, N: Copy + Ring>
|
impl<D: Dim, N: Ring>
|
||||||
Dot<N> for NVec<D, N>
|
Dot<N> for NVec<D, N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -67,14 +67,14 @@ Dot<N> for NVec<D, N>
|
||||||
{ self.at.dot(&other.at) }
|
{ self.at.dot(&other.at) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dim, N: Copy + Ring> SubDot<N> for NVec<D, N>
|
impl<D: Dim, N: Ring> SubDot<N> for NVec<D, N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
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) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dim, N: Copy + 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(always)]
|
||||||
|
@ -87,7 +87,7 @@ ScalarMul<N> for NVec<D, N>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<D: Dim, N: Copy + 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(always)]
|
||||||
|
@ -99,7 +99,7 @@ ScalarDiv<N> for NVec<D, N>
|
||||||
{ self.at.scalar_div_inplace(s) }
|
{ self.at.scalar_div_inplace(s) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dim, N: Copy + 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(always)]
|
||||||
|
@ -111,7 +111,7 @@ ScalarAdd<N> for NVec<D, N>
|
||||||
{ self.at.scalar_add_inplace(s) }
|
{ self.at.scalar_add_inplace(s) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Dim, N: Copy + 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(always)]
|
||||||
|
@ -123,7 +123,7 @@ ScalarSub<N> for NVec<D, 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>, NVec<D, N>> for NVec<D, N>
|
||||||
{
|
{
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn translation(&self) -> NVec<D, N>
|
fn translation(&self) -> NVec<D, N>
|
||||||
|
|
|
@ -3,14 +3,14 @@ use traits::translation::Translation;
|
||||||
/// Trait of object which represent a rotation, and to wich new rotations can
|
/// Trait of object which represent a rotation, and to wich new rotations can
|
||||||
/// be appended. A rotation is assumed to be an isomitry without translation
|
/// be appended. A rotation is assumed to be an isomitry without translation
|
||||||
/// and without reflexion.
|
/// and without reflexion.
|
||||||
pub trait Rotation<V>
|
pub trait Rotation<V, Res>
|
||||||
{
|
{
|
||||||
/// Gets the rotation associated with this object.
|
/// Gets the rotation associated with this object.
|
||||||
fn rotation(&self) -> V;
|
fn rotation(&self) -> V;
|
||||||
|
|
||||||
/// Appends a rotation from an alternative representation. Such
|
/// Appends a rotation from an alternative representation. Such
|
||||||
/// representation has the same format as the one returned by `rotation`.
|
/// representation has the same format as the one returned by `rotation`.
|
||||||
fn rotated(&self, &V) -> Self;
|
fn rotated(&self, &V) -> Res;
|
||||||
|
|
||||||
/// In-place version of `rotated`.
|
/// In-place version of `rotated`.
|
||||||
fn rotate(&mut self, &V);
|
fn rotate(&mut self, &V);
|
||||||
|
@ -24,8 +24,13 @@ pub trait Rotation<V>
|
||||||
* - `point`: the center of rotation.
|
* - `point`: the center of rotation.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn rotate_wrt_point<M: Rotation<AV> + Translation<LV>, LV: Neg<LV>, AV>
|
pub fn rotate_wrt_point<M: Translation<LV, ResT>,
|
||||||
(m: &M, ammount: &AV, center: &LV) -> M
|
ResT: Rotation<AV, Res> + Translation<LV, ResT2>,
|
||||||
|
ResT2,
|
||||||
|
Res,
|
||||||
|
LV: Neg<LV>,
|
||||||
|
AV>
|
||||||
|
(m: &M, ammount: &AV, center: &LV) -> ResT
|
||||||
{
|
{
|
||||||
let mut res = m.translated(&-center);
|
let mut res = m.translated(&-center);
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
/// Trait of object which represent a translation, and to wich new translation
|
/// Trait of object which represent a translation, and to wich new translation
|
||||||
/// can be appended.
|
/// can be appended.
|
||||||
pub trait Translation<V>
|
pub trait Translation<V, Res>
|
||||||
{
|
{
|
||||||
/// Gets the translation associated with this object.
|
/// Gets the translation associated with this object.
|
||||||
fn translation(&self) -> V;
|
fn translation(&self) -> V;
|
||||||
|
|
||||||
/// Appends a translation from an alternative representation. Such
|
/// Appends a translation from an alternative representation. Such
|
||||||
/// representation has the same format as the one returned by `translation`.
|
/// representation has the same format as the one returned by `translation`.
|
||||||
fn translated(&self, &V) -> Self;
|
fn translated(&self, &V) -> Res;
|
||||||
|
|
||||||
/// In-place version of `translate`.
|
/// In-place version of `translate`.
|
||||||
fn translate(&mut self, &V);
|
fn translate(&mut self, &V);
|
||||||
|
|
|
@ -11,6 +11,5 @@ pub trait VectorSpace<N>
|
||||||
ScalarMul<N> + ScalarDiv<N>
|
ScalarMul<N> + ScalarDiv<N>
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
impl<V: Sub<V, V> + Add<V, V> + Neg<V> + Zero +
|
impl<V: Sub<V, V> + Add<V, V> + Neg<V> + Zero + ScalarMul<N> + ScalarDiv<N>,
|
||||||
ScalarMul<N> + ScalarDiv<N>,
|
|
||||||
N: DivisionRing> VectorSpace<N> for V;
|
N: DivisionRing> VectorSpace<N> for V;
|
||||||
|
|
Loading…
Reference in New Issue