From ffbcf4882a47285179fb61a26d77ef1a78609146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Wed, 26 Jun 2013 20:56:30 +0000 Subject: [PATCH] Removed a lot of Copy + made Rotation and Translation more flexible. --- src/adaptors/rotmat.rs | 25 +++++--------- src/adaptors/transform.rs | 27 ++++++++------- src/dim1/mat1.rs | 16 ++++----- src/dim1/vec1.rs | 44 ++++++++++++------------ src/dim2/mat2.rs | 18 +++++----- src/dim2/vec2.rs | 61 ++++++++++++++++----------------- src/dim3/mat3.rs | 22 ++++++------ src/dim3/vec3.rs | 69 ++++++++++++++++++-------------------- src/ndim/dvec.rs | 26 +++++++------- src/ndim/nvec.rs | 16 ++++----- src/traits/rotation.rs | 15 ++++++--- src/traits/translation.rs | 6 ++-- src/traits/vector_space.rs | 3 +- 13 files changed, 170 insertions(+), 178 deletions(-) diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index f60fe0f3..e6708def 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -14,16 +14,7 @@ use dim3::vec3::{Vec3}; #[deriving(Eq, ToStr)] pub struct Rotmat -{ - priv submat: M -} - -impl Rotmat -{ - #[inline(always)] - fn submat(&self) -> M - { copy self.submat } -} +{ priv submat: M } pub fn rotmat2>(angle: N) -> Rotmat> { @@ -66,7 +57,7 @@ pub fn rotmat3 + One + Sub + Add + } impl + Trigonometric + Neg + Mul + Add + Copy> -Rotation> for Rotmat> +Rotation, Rotmat>> for Rotmat> { #[inline(always)] fn rotation(&self) -> Vec1 @@ -83,7 +74,7 @@ Rotation> for Rotmat> impl + Trigonometric + Neg + Mul + Add + Copy + One + Sub> -Rotation<(Vec3, N)> for Rotmat> +Rotation<(Vec3, N), Rotmat>> for Rotmat> { #[inline(always)] fn rotation(&self) -> (Vec3, N) @@ -121,14 +112,14 @@ impl Dim for Rotmat { Dim::dim::() } } -impl One for Rotmat +impl One for Rotmat { #[inline(always)] fn one() -> Rotmat { Rotmat { submat: One::one() } } } -impl> Mul, Rotmat> for Rotmat +impl> Mul, Rotmat> for Rotmat { #[inline(always)] fn mul(&self, other: &Rotmat) -> Rotmat @@ -156,14 +147,14 @@ impl DeltaTransform for Rotmat { copy self.submat } } -impl + Copy, V: Copy> DeltaTransformVector for Rotmat +impl, V> DeltaTransformVector for Rotmat { #[inline(always)] fn delta_transform_vector(&self, v: &V) -> V { self.submat.rmul(v) } } -impl Inv for Rotmat +impl Inv for Rotmat { #[inline(always)] fn invert(&mut self) @@ -174,7 +165,7 @@ impl Inv for Rotmat { self.transposed() } } -impl +impl Transpose for Rotmat { #[inline(always)] diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index dedc37ab..0ae2e6bf 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -16,7 +16,7 @@ pub struct Transform priv subtrans : V } -impl Transform +impl Transform { #[inline(always)] pub fn new(mat: M, trans: V) -> Transform @@ -30,14 +30,14 @@ impl Dim for Transform { Dim::dim::() } } -impl One for Transform +impl One for Transform { #[inline(always)] fn one() -> Transform { Transform { submat: One::one(), subtrans: Zero::zero() } } } -impl Zero for Transform +impl Zero for Transform { #[inline(always)] fn zero() -> Transform @@ -48,7 +48,7 @@ impl Zero for Transform { self.submat.is_zero() && self.subtrans.is_zero() } } -impl + Mul, V:Copy + Add> +impl + Mul, V: Add> Mul, Transform> for Transform { #[inline(always)] @@ -73,14 +73,14 @@ impl, V: Add> LMul for Transform { self.submat.lmul(other) + self.subtrans } } -impl> Translation for Transform +impl, Res> Translation> for Transform { #[inline(always)] fn translation(&self) -> V { self.subtrans.translation() } #[inline(always)] - fn translated(&self, t: &V) -> Transform + fn translated(&self, t: &V) -> Transform { Transform::new(copy self.submat, self.subtrans.translated(t)) } #[inline(always)] @@ -88,15 +88,18 @@ impl> Translation for Transform { self.subtrans.translate(t) } } -impl + Copy + RMul + One, V: Copy, AV> -Rotation for Transform +impl + One, + Res: RMul, + V, + AV> +Rotation> for Transform { #[inline(always)] fn rotation(&self) -> AV { self.submat.rotation() } #[inline(always)] - fn rotated(&self, rot: &AV) -> Transform + fn rotated(&self, rot: &AV) -> Transform { // FIXME: this does not seem opitmal let delta = One::one::().rotated(rot); @@ -121,14 +124,14 @@ impl DeltaTransform for Transform { copy self.submat } } -impl + Copy, V> DeltaTransformVector for Transform +impl, V> DeltaTransformVector for Transform { #[inline(always)] fn delta_transform_vector(&self, v: &V) -> V { self.submat.rmul(v) } } -impl, V:Copy + Neg> +impl, V: Copy + Neg> Inv for Transform { #[inline(always)] @@ -171,7 +174,7 @@ ApproxEq for Transform } } -impl Rand for Transform +impl Rand for Transform { #[inline(always)] fn rand(rng: &mut R) -> Transform diff --git a/src/dim1/mat1.rs b/src/dim1/mat1.rs index 84216825..8068fae0 100644 --- a/src/dim1/mat1.rs +++ b/src/dim1/mat1.rs @@ -12,7 +12,7 @@ use dim1::vec1::Vec1; pub struct Mat1 { m11: N } -impl Mat1 +impl Mat1 { #[inline(always)] pub fn new(m11: N) -> Mat1 @@ -29,14 +29,14 @@ impl Dim for Mat1 { 1 } } -impl One for Mat1 +impl One for Mat1 { #[inline(always)] fn one() -> Mat1 { return Mat1::new(One::one()) } } -impl Zero for Mat1 +impl Zero for Mat1 { #[inline(always)] fn zero() -> Mat1 @@ -47,21 +47,21 @@ impl Zero for Mat1 { self.m11.is_zero() } } -impl + Add> Mul, Mat1> for Mat1 +impl + Add> Mul, Mat1> for Mat1 { #[inline(always)] fn mul(&self, other: &Mat1) -> Mat1 { Mat1::new(self.m11 * other.m11) } } -impl + Mul> RMul> for Mat1 +impl + Mul> RMul> for Mat1 { #[inline(always)] fn rmul(&self, other: &Vec1) -> Vec1 { Vec1::new(self.m11 * other.x) } } -impl + Mul> LMul> for Mat1 +impl + Mul> LMul> for Mat1 { #[inline(always)] fn lmul(&self, other: &Vec1) -> Vec1 @@ -90,7 +90,7 @@ Inv for Mat1 } } -impl Transpose for Mat1 +impl Transpose for Mat1 { #[inline(always)] fn transposed(&self) -> Mat1 @@ -116,7 +116,7 @@ impl> ApproxEq for Mat1 { self.m11.approx_eq_eps(&other.m11, epsilon) } } -impl Rand for Mat1 +impl Rand for Mat1 { #[inline(always)] fn rand(rng: &mut R) -> Mat1 diff --git a/src/dim1/vec1.rs b/src/dim1/vec1.rs index bb1db436..919768ab 100644 --- a/src/dim1/vec1.rs +++ b/src/dim1/vec1.rs @@ -14,7 +14,7 @@ use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; pub struct Vec1 { x : N } -impl Vec1 +impl Vec1 { #[inline(always)] pub fn new(x: N) -> Vec1 @@ -28,21 +28,21 @@ impl Dim for Vec1 { 1 } } -impl> Add, Vec1> for Vec1 +impl> Add, Vec1> for Vec1 { #[inline(always)] fn add(&self, other: &Vec1) -> Vec1 { Vec1::new(self.x + other.x) } } -impl> Sub, Vec1> for Vec1 +impl> Sub, Vec1> for Vec1 { #[inline(always)] fn sub(&self, other: &Vec1) -> Vec1 { Vec1::new(self.x - other.x) } } -impl> +impl> ScalarMul for Vec1 { #[inline(always)] @@ -51,11 +51,11 @@ ScalarMul for Vec1 #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) - { self.x = self.x * copy *s; } + { self.x = self.x * *s; } } -impl> +impl> ScalarDiv for Vec1 { #[inline(always)] @@ -64,10 +64,10 @@ ScalarDiv for Vec1 #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) - { self.x = self.x / copy *s; } + { self.x = self.x / *s; } } -impl> +impl> ScalarAdd for Vec1 { #[inline(always)] @@ -76,10 +76,10 @@ ScalarAdd for Vec1 #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) - { self.x = self.x + copy *s; } + { self.x = self.x + *s; } } -impl> +impl> ScalarSub for Vec1 { #[inline(always)] @@ -88,10 +88,10 @@ ScalarSub for Vec1 #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) - { self.x = self.x - copy *s; } + { self.x = self.x - *s; } } -impl> Translation> for Vec1 +impl> Translation, Vec1> for Vec1 { #[inline(always)] fn translation(&self) -> Vec1 @@ -103,24 +103,24 @@ impl> Translation> for Vec1 #[inline(always)] fn translate(&mut self, t: &Vec1) - { *self = *self + copy *t } + { *self = *self + *t } } -impl> Dot for Vec1 +impl> Dot for Vec1 { #[inline(always)] fn dot(&self, other : &Vec1) -> N { self.x * other.x } } -impl + Sub> SubDot for Vec1 +impl + Sub> SubDot for Vec1 { #[inline(always)] fn sub_dot(&self, a: &Vec1, b: &Vec1) -> N { (self.x - a.x) * b.x } } -impl + Add + Div + Algebraic> +impl + Add + Div + Algebraic> Norm for Vec1 { #[inline(always)] @@ -140,20 +140,20 @@ Norm for Vec1 { let l = self.norm(); - self.x = self.x / copy l; + self.x = self.x / l; l } } -impl> Neg> for Vec1 +impl> Neg> for Vec1 { #[inline(always)] fn neg(&self) -> Vec1 { Vec1::new(-self.x) } } -impl Zero for Vec1 +impl Zero for Vec1 { #[inline(always)] fn zero() -> Vec1 @@ -167,7 +167,7 @@ impl Zero for Vec1 { self.x.is_zero() } } -impl Basis for Vec1 +impl Basis for Vec1 { #[inline(always)] fn canonical_basis() -> ~[Vec1] @@ -193,7 +193,7 @@ impl> ApproxEq for Vec1 { self.x.approx_eq_eps(&other.x, epsilon) } } -impl Rand for Vec1 +impl Rand for Vec1 { #[inline(always)] fn rand(rng: &mut R) -> Vec1 @@ -219,7 +219,7 @@ impl Flatten for Vec1 { l[off] = copy self.x } } -impl Bounded for Vec1 +impl Bounded for Vec1 { #[inline(always)] fn max_value() -> Vec1 diff --git a/src/dim2/mat2.rs b/src/dim2/mat2.rs index bf8516de..4fa77af6 100644 --- a/src/dim2/mat2.rs +++ b/src/dim2/mat2.rs @@ -16,7 +16,7 @@ pub struct Mat2 m21: N, m22: N } -impl Mat2 +impl Mat2 { #[inline(always)] pub fn new(m11: N, m12: N, m21: N, m22: N) -> Mat2 @@ -36,14 +36,14 @@ impl Dim for Mat2 { 2 } } -impl One for Mat2 +impl One for Mat2 { #[inline(always)] fn one() -> Mat2 { let (_0, _1) = (Zero::zero(), One::one()); return Mat2::new(copy _1, copy _0, - copy _0, copy _1) + _0, _1) } } @@ -54,7 +54,7 @@ impl Zero for Mat2 { let _0 = Zero::zero(); return Mat2::new(copy _0, copy _0, - copy _0, copy _0) + copy _0, _0) } #[inline(always)] @@ -65,7 +65,7 @@ impl Zero for Mat2 } } -impl + Add> Mul, Mat2> for Mat2 +impl + Add> Mul, Mat2> for Mat2 { #[inline(always)] fn mul(&self, other: &Mat2) -> Mat2 @@ -79,7 +79,7 @@ impl + Add> Mul, Mat2> for Mat2 } } -impl + Mul> RMul> for Mat2 +impl + Mul> RMul> for Mat2 { #[inline(always)] fn rmul(&self, other: &Vec2) -> Vec2 @@ -91,7 +91,7 @@ impl + Mul> RMul> for Mat2 } } -impl + Mul> LMul> for Mat2 +impl + Mul> LMul> for Mat2 { #[inline(always)] fn lmul(&self, other: &Vec2) -> Vec2 @@ -128,7 +128,7 @@ Inv for Mat2 } } -impl Transpose for Mat2 +impl Transpose for Mat2 { #[inline(always)] fn transposed(&self) -> Mat2 @@ -169,7 +169,7 @@ impl> ApproxEq for Mat2 } } -impl Rand for Mat2 +impl Rand for Mat2 { #[inline(always)] fn rand(rng: &mut R) -> Mat2 diff --git a/src/dim2/vec2.rs b/src/dim2/vec2.rs index e339b020..bfa7cbcb 100644 --- a/src/dim2/vec2.rs +++ b/src/dim2/vec2.rs @@ -19,7 +19,7 @@ pub struct Vec2 y : N } -impl Vec2 +impl Vec2 { #[inline(always)] pub fn new(x: N, y: N) -> Vec2 @@ -33,21 +33,21 @@ impl Dim for Vec2 { 2 } } -impl> Add, Vec2> for Vec2 +impl> Add, Vec2> for Vec2 { #[inline(always)] fn add(&self, other: &Vec2) -> Vec2 { Vec2::new(self.x + other.x, self.y + other.y) } } -impl> Sub, Vec2> for Vec2 +impl> Sub, Vec2> for Vec2 { #[inline(always)] fn sub(&self, other: &Vec2) -> Vec2 { Vec2::new(self.x - other.x, self.y - other.y) } } -impl> +impl> ScalarMul for Vec2 { #[inline(always)] @@ -57,13 +57,13 @@ ScalarMul for Vec2 #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) { - self.x = self.x * copy *s; - self.y = self.y * copy *s; + self.x = self.x * *s; + self.y = self.y * *s; } } -impl> +impl> ScalarDiv for Vec2 { #[inline(always)] @@ -73,12 +73,12 @@ ScalarDiv for Vec2 #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) { - self.x = self.x / copy *s; - self.y = self.y / copy *s; + self.x = self.x / *s; + self.y = self.y / *s; } } -impl> +impl> ScalarAdd for Vec2 { #[inline(always)] @@ -88,12 +88,12 @@ ScalarAdd for Vec2 #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) { - self.x = self.x + copy *s; - self.y = self.y + copy *s; + self.x = self.x + *s; + self.y = self.y + *s; } } -impl> +impl> ScalarSub for Vec2 { #[inline(always)] @@ -103,12 +103,12 @@ ScalarSub for Vec2 #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) { - self.x = self.x - copy *s; - self.y = self.y - copy *s; + self.x = self.x - *s; + self.y = self.y - *s; } } -impl> Translation> for Vec2 +impl> Translation, Vec2> for Vec2 { #[inline(always)] fn translation(&self) -> Vec2 @@ -120,24 +120,24 @@ impl> Translation> for Vec2 #[inline(always)] fn translate(&mut self, t: &Vec2) - { *self = *self + copy *t; } + { *self = *self + *t; } } -impl + Add> Dot for Vec2 +impl + Add> Dot for Vec2 { #[inline(always)] fn dot(&self, other : &Vec2) -> N { self.x * other.x + self.y * other.y } } -impl + Add + Sub> SubDot for Vec2 +impl + Add + Sub> SubDot for Vec2 { #[inline(always)] fn sub_dot(&self, a: &Vec2, b: &Vec2) -> N { (self.x - a.x) * b.x + (self.y - a.y) * b.y } } -impl + Add + Div + Algebraic> +impl + Add + Div + Algebraic> Norm for Vec2 { #[inline(always)] @@ -161,35 +161,32 @@ Norm for Vec2 { let l = self.norm(); - self.x = self.x / copy l; - self.y = self.y / copy l; + self.x = self.x / l; + self.y = self.y / l; - copy l + l } } -impl + Sub> Cross> for Vec2 +impl + Sub> Cross> for Vec2 { #[inline(always)] fn cross(&self, other : &Vec2) -> Vec1 { Vec1::new(self.x * other.y - self.y * other.x) } } -impl> Neg> for Vec2 +impl> Neg> for Vec2 { #[inline(always)] fn neg(&self) -> Vec2 { Vec2::new(-self.x, -self.y) } } -impl Zero for Vec2 +impl Zero for Vec2 { #[inline(always)] fn zero() -> Vec2 - { - let _0 = Zero::zero(); - Vec2::new(copy _0, copy _0) - } + { Vec2::new(Zero::zero(), Zero::zero()) } #[inline(always)] fn is_zero(&self) -> bool @@ -229,7 +226,7 @@ impl> ApproxEq for Vec2 } } -impl Rand for Vec2 +impl Rand for Vec2 { #[inline(always)] fn rand(rng: &mut R) -> Vec2 @@ -258,7 +255,7 @@ impl Flatten for Vec2 } } -impl Bounded for Vec2 +impl Bounded for Vec2 { #[inline(always)] fn max_value() -> Vec2 diff --git a/src/dim3/mat3.rs b/src/dim3/mat3.rs index 2df78237..87bea4b1 100644 --- a/src/dim3/mat3.rs +++ b/src/dim3/mat3.rs @@ -17,7 +17,7 @@ pub struct Mat3 m31: N, m32: N, m33: N } -impl Mat3 +impl Mat3 { #[inline(always)] pub fn new(m11: N, m12: N, m13: N, @@ -27,8 +27,8 @@ impl Mat3 Mat3 { m11: m11, m12: m12, m13: m13, - m21: m21, m22: m22, m23: m23, - m31: m31, m32: m32, m33: m33 + m21: m21, m22: m22, m23: m23, + m31: m31, m32: m32, m33: m33 } } } @@ -40,7 +40,7 @@ impl Dim for Mat3 { 3 } } -impl One for Mat3 +impl One for Mat3 { #[inline(always)] fn one() -> Mat3 @@ -48,11 +48,11 @@ impl One for Mat3 let (_0, _1) = (Zero::zero(), One::one()); return Mat3::new(copy _1, copy _0, copy _0, copy _0, copy _1, copy _0, - copy _0, copy _0, copy _1) + copy _0, _0, _1) } } -impl Zero for Mat3 +impl Zero for Mat3 { #[inline(always)] fn zero() -> Mat3 @@ -60,7 +60,7 @@ impl Zero for Mat3 let _0 = Zero::zero(); 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, _0) } #[inline(always)] @@ -72,7 +72,7 @@ impl Zero for Mat3 } } -impl + Add> Mul, Mat3> for Mat3 +impl + Add> Mul, Mat3> for Mat3 { #[inline(always)] fn mul(&self, other: &Mat3) -> Mat3 @@ -93,7 +93,7 @@ impl + Add> Mul, Mat3> for Mat3 } } -impl + Mul> RMul> for Mat3 +impl + Mul> RMul> for Mat3 { #[inline(always)] fn rmul(&self, other: &Vec3) -> Vec3 @@ -106,7 +106,7 @@ impl + Mul> RMul> for Mat3 } } -impl + Mul> LMul> for Mat3 +impl + Mul> LMul> for Mat3 { #[inline(always)] fn lmul(&self, other: &Vec3) -> Vec3 @@ -219,7 +219,7 @@ impl> ApproxEq for Mat3 } } -impl Rand for Mat3 +impl Rand for Mat3 { #[inline(always)] fn rand(rng: &mut R) -> Mat3 diff --git a/src/dim3/vec3.rs b/src/dim3/vec3.rs index ea70ef9b..1955d0e4 100644 --- a/src/dim3/vec3.rs +++ b/src/dim3/vec3.rs @@ -19,7 +19,7 @@ pub struct Vec3 z : N } -impl Vec3 +impl Vec3 { #[inline(always)] pub fn new(x: N, y: N, z: N) -> Vec3 @@ -33,21 +33,21 @@ impl Dim for Vec3 { 3 } } -impl> Add, Vec3> for Vec3 +impl> Add, Vec3> for Vec3 { #[inline(always)] fn add(&self, other: &Vec3) -> Vec3 { Vec3::new(self.x + other.x, self.y + other.y, self.z + other.z) } } -impl> Sub, Vec3> for Vec3 +impl> Sub, Vec3> for Vec3 { #[inline(always)] fn sub(&self, other: &Vec3) -> Vec3 { Vec3::new(self.x - other.x, self.y - other.y, self.z - other.z) } } -impl> +impl> ScalarMul for Vec3 { #[inline(always)] @@ -57,14 +57,14 @@ ScalarMul for Vec3 #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) { - self.x = self.x * copy *s; - self.y = self.y * copy *s; - self.z = self.z * copy *s; + self.x = self.x * *s; + self.y = self.y * *s; + self.z = self.z * *s; } } -impl> +impl> ScalarDiv for Vec3 { #[inline(always)] @@ -74,13 +74,13 @@ ScalarDiv for Vec3 #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) { - self.x = self.x / copy *s; - self.y = self.y / copy *s; - self.z = self.z / copy *s; + self.x = self.x / *s; + self.y = self.y / *s; + self.z = self.z / *s; } } -impl> +impl> ScalarAdd for Vec3 { #[inline(always)] @@ -90,13 +90,13 @@ ScalarAdd for Vec3 #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) { - self.x = self.x + copy *s; - self.y = self.y + copy *s; - self.z = self.z + copy *s; + self.x = self.x + *s; + self.y = self.y + *s; + self.z = self.z + *s; } } -impl> +impl> ScalarSub for Vec3 { #[inline(always)] @@ -106,13 +106,13 @@ ScalarSub for Vec3 #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) { - self.x = self.x - copy *s; - self.y = self.y - copy *s; - self.z = self.z - copy *s; + self.x = self.x - *s; + self.y = self.y - *s; + self.z = self.z - *s; } } -impl> Translation> for Vec3 +impl> Translation, Vec3> for Vec3 { #[inline(always)] fn translation(&self) -> Vec3 @@ -124,33 +124,33 @@ impl> Translation> for Vec3 #[inline(always)] fn translate(&mut self, t: &Vec3) - { *self = *self + copy *t; } + { *self = *self + *t; } } -impl> Neg> for Vec3 +impl> Neg> for Vec3 { #[inline(always)] fn neg(&self) -> Vec3 { Vec3::new(-self.x, -self.y, -self.z) } } -impl + Add> Dot for Vec3 +impl + Add> Dot for Vec3 { #[inline(always)] fn dot(&self, other : &Vec3) -> N { self.x * other.x + self.y * other.y + self.z * other.z } } -impl + Add + Sub> SubDot for Vec3 +impl + Add + Sub> SubDot for Vec3 { #[inline(always)] fn sub_dot(&self, a: &Vec3, b: &Vec3) -> N { (self.x - a.x) * b.x + (self.y - a.y) * b.y + (self.z - a.z) * b.z } } -impl + Add + Div + Algebraic> +impl + Add + Div + Algebraic> Norm for Vec3 { #[inline(always)] @@ -174,15 +174,15 @@ Norm for Vec3 { let l = self.norm(); - self.x = self.x / copy l; - self.y = self.y / copy l; - self.z = self.z / copy l; + self.x = self.x / l; + self.y = self.y / l; + self.z = self.z / l; l } } -impl + Sub> Cross> for Vec3 +impl + Sub> Cross> for Vec3 { #[inline(always)] fn cross(&self, other : &Vec3) -> Vec3 @@ -195,14 +195,11 @@ impl + Sub> Cross> for Vec3 } } -impl Zero for Vec3 +impl Zero for Vec3 { #[inline(always)] fn zero() -> Vec3 - { - let _0 = Zero::zero(); - Vec3::new(copy _0, copy _0, copy _0) - } + { Vec3::new(Zero::zero(), Zero::zero(), Zero::zero()) } #[inline(always)] fn is_zero(&self) -> bool @@ -258,7 +255,7 @@ impl> ApproxEq for Vec3 } } -impl Rand for Vec3 +impl Rand for Vec3 { #[inline(always)] fn rand(rng: &mut R) -> Vec3 @@ -288,7 +285,7 @@ impl Flatten for Vec3 } } -impl Bounded for Vec3 +impl Bounded for Vec3 { #[inline(always)] fn max_value() -> Vec3 diff --git a/src/ndim/dvec.rs b/src/ndim/dvec.rs index ea1168b4..fdd51baf 100644 --- a/src/ndim/dvec.rs +++ b/src/ndim/dvec.rs @@ -97,14 +97,14 @@ impl> Sub, DVec> for DVec } } -impl> Neg> for DVec +impl> Neg> for DVec { #[inline(always)] fn neg(&self) -> DVec { DVec { at: map(self.at, |a| -a) } } } -impl +impl Dot for DVec { #[inline(always)] @@ -121,7 +121,7 @@ Dot for DVec } } -impl SubDot for DVec +impl SubDot for DVec { #[inline(always)] fn sub_dot(&self, a: &DVec, b: &DVec) -> N @@ -135,7 +135,7 @@ impl SubDot for DVec } } -impl> +impl> ScalarMul for DVec { #[inline(always)] @@ -146,12 +146,12 @@ ScalarMul for DVec fn scalar_mul_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| - { self.at[i] = self.at[i] * copy *s; } + { self.at[i] = self.at[i] * *s; } } } -impl> +impl> ScalarDiv for DVec { #[inline(always)] @@ -162,11 +162,11 @@ ScalarDiv for DVec fn scalar_div_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| - { self.at[i] = self.at[i] / copy *s; } + { self.at[i] = self.at[i] / *s; } } } -impl> +impl> ScalarAdd for DVec { #[inline(always)] @@ -177,11 +177,11 @@ ScalarAdd for DVec fn scalar_add_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| - { self.at[i] = self.at[i] + copy *s; } + { self.at[i] = self.at[i] + *s; } } } -impl> +impl> ScalarSub for DVec { #[inline(always)] @@ -192,11 +192,11 @@ ScalarSub for DVec fn scalar_sub_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| - { self.at[i] = self.at[i] - copy *s; } + { self.at[i] = self.at[i] - *s; } } } -impl> Translation> for DVec +impl> Translation, DVec> for DVec { #[inline(always)] fn translation(&self) -> DVec @@ -238,7 +238,7 @@ Norm for DVec let l = self.norm(); for iterate(0u, self.at.len()) |i| - { self.at[i] = self.at[i] / copy l; } + { self.at[i] = self.at[i] / l; } l } diff --git a/src/ndim/nvec.rs b/src/ndim/nvec.rs index de0d67ed..fccd6dd9 100644 --- a/src/ndim/nvec.rs +++ b/src/ndim/nvec.rs @@ -52,14 +52,14 @@ impl> Sub, NVec> for NVec { NVec { at: self.at - other.at } } } -impl> Neg> for NVec +impl> Neg> for NVec { #[inline(always)] fn neg(&self) -> NVec { NVec { at: -self.at } } } -impl +impl Dot for NVec { #[inline(always)] @@ -67,14 +67,14 @@ Dot for NVec { self.at.dot(&other.at) } } -impl SubDot for NVec +impl SubDot for NVec { #[inline(always)] fn sub_dot(&self, a: &NVec, b: &NVec) -> N { self.at.sub_dot(&a.at, &b.at) } } -impl> +impl> ScalarMul for NVec { #[inline(always)] @@ -87,7 +87,7 @@ ScalarMul for NVec } -impl> +impl> ScalarDiv for NVec { #[inline(always)] @@ -99,7 +99,7 @@ ScalarDiv for NVec { self.at.scalar_div_inplace(s) } } -impl> +impl> ScalarAdd for NVec { #[inline(always)] @@ -111,7 +111,7 @@ ScalarAdd for NVec { self.at.scalar_add_inplace(s) } } -impl> +impl> ScalarSub for NVec { #[inline(always)] @@ -123,7 +123,7 @@ ScalarSub for NVec { self.at.scalar_sub_inplace(s) } } -impl> Translation> for NVec +impl> Translation, NVec> for NVec { #[inline(always)] fn translation(&self) -> NVec diff --git a/src/traits/rotation.rs b/src/traits/rotation.rs index 060d05ca..ce89bc25 100644 --- a/src/traits/rotation.rs +++ b/src/traits/rotation.rs @@ -3,14 +3,14 @@ use traits::translation::Translation; /// 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 /// and without reflexion. -pub trait Rotation +pub trait Rotation { /// Gets the rotation associated with this object. - fn rotation(&self) -> V; + fn rotation(&self) -> V; /// Appends a rotation from an alternative representation. Such /// 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`. fn rotate(&mut self, &V); @@ -24,8 +24,13 @@ pub trait Rotation * - `point`: the center of rotation. */ #[inline(always)] -pub fn rotate_wrt_point + Translation, LV: Neg, AV> - (m: &M, ammount: &AV, center: &LV) -> M +pub fn rotate_wrt_point, + ResT: Rotation + Translation, + ResT2, + Res, + LV: Neg, + AV> + (m: &M, ammount: &AV, center: &LV) -> ResT { let mut res = m.translated(&-center); diff --git a/src/traits/translation.rs b/src/traits/translation.rs index 58fd7cdd..ead1bdfb 100644 --- a/src/traits/translation.rs +++ b/src/traits/translation.rs @@ -1,13 +1,13 @@ /// Trait of object which represent a translation, and to wich new translation /// can be appended. -pub trait Translation +pub trait Translation { /// Gets the translation associated with this object. - fn translation(&self) -> V; + fn translation(&self) -> V; /// Appends a translation from an alternative representation. Such /// 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`. fn translate(&mut self, &V); diff --git a/src/traits/vector_space.rs b/src/traits/vector_space.rs index 0442d12f..50aa4a1f 100644 --- a/src/traits/vector_space.rs +++ b/src/traits/vector_space.rs @@ -11,6 +11,5 @@ pub trait VectorSpace ScalarMul + ScalarDiv { } -impl + Add + Neg + Zero + - ScalarMul + ScalarDiv, +impl + Add + Neg + Zero + ScalarMul + ScalarDiv, N: DivisionRing> VectorSpace for V;