diff --git a/doc/rust.css b/doc/rust.css index 35581a8d..ed9ea446 100644 --- a/doc/rust.css +++ b/doc/rust.css @@ -12,41 +12,38 @@ body { } h1 { - font-size: 20pt; - margin-top: 2em; + font-size: 24pt; + margin-top: 1.6em; padding-left: 0.4em; line-height: 1.6em; background-color:#FFF2CE; border-radius: 0.2em; - border: 1px solid rgba(0, 0, 0, 0.15); } h2 { - font-size: 15pt; - margin-top: 2em; - padding-left: 0.4em; + font-size: 16pt; + margin-top: 1.6em; + padding: 0.2em 0.5em; background-color:#FFF2CE; border-radius: 0.4em; - border: 1px solid rgba(0, 0, 0, 0.15); } h2 code { color: #097334; - font-size: 15pt; + font-size: 16pt; } h3 { - font-size: 13pt; + font-size: 14pt; color: black; background-color:#D9E7FF; border-radius: 0.4em; - border: 1px solid rgba(0, 0, 0, 0.15); - padding: 0 0.4em 0 0.4em; + padding: 0.2em 0.5em; } h3 code { color: #541800; - font-size: 13pt; + font-size: 14pt; font-style: italic; } diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index 31740467..f60fe0f3 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -22,7 +22,7 @@ impl Rotmat { #[inline(always)] fn submat(&self) -> M - { self.submat } + { copy self.submat } } pub fn rotmat2>(angle: N) -> Rotmat> @@ -31,7 +31,7 @@ pub fn rotmat2>(angle: N) -> Rotmat> let sia = angle.sin(); Rotmat - { submat: Mat2::new(coa, -sia, sia, coa) } + { submat: Mat2::new(copy coa, -sia, copy sia, copy coa) } } pub fn rotmat3 + One + Sub + Add + @@ -39,9 +39,9 @@ pub fn rotmat3 + One + Sub + Add + (axis: &Vec3, angle: N) -> Rotmat> { let _1 = One::one::(); - let ux = axis.x; - let uy = axis.y; - let uz = axis.z; + let ux = copy axis.x; + let uy = copy axis.y; + let uz = copy axis.z; let sqx = ux * ux; let sqy = uy * uy; let sqz = uz * uz; @@ -74,7 +74,7 @@ Rotation> for Rotmat> #[inline(always)] fn rotated(&self, rot: &Vec1) -> Rotmat> - { rotmat2(rot.x) * *self } + { rotmat2(copy rot.x) * *self } #[inline(always)] fn rotate(&mut self, rot: &Vec1) @@ -153,7 +153,7 @@ impl DeltaTransform for Rotmat { #[inline(always)] fn delta_transform(&self) -> M - { self.submat } + { copy self.submat } } impl + Copy, V: Copy> DeltaTransformVector for Rotmat diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index 9411c147..7c24b801 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -20,7 +20,7 @@ impl Transform { #[inline(always)] pub fn new(mat: &M, trans: &V) -> Transform - { Transform { submat: *mat, subtrans: *trans } } + { Transform { submat: copy *mat, subtrans: copy *trans } } } impl Dim for Transform @@ -118,7 +118,7 @@ impl DeltaTransform for Transform { #[inline(always)] fn delta_transform(&self) -> M - { self.submat } + { copy self.submat } } impl + Copy, V> DeltaTransformVector for Transform @@ -141,7 +141,7 @@ Inv for Transform #[inline(always)] fn inverse(&self) -> Transform { - let mut res = *self; + let mut res = copy *self; res.invert(); diff --git a/src/dim1/mat1.rs b/src/dim1/mat1.rs index 0cb53412..84216825 100644 --- a/src/dim1/mat1.rs +++ b/src/dim1/mat1.rs @@ -74,7 +74,7 @@ Inv for Mat1 #[inline(always)] fn inverse(&self) -> Mat1 { - let mut res : Mat1 = *self; + let mut res : Mat1 = copy *self; res.invert(); @@ -94,7 +94,7 @@ impl Transpose for Mat1 { #[inline(always)] fn transposed(&self) -> Mat1 - { *self } + { copy *self } #[inline(always)] fn transpose(&mut self) @@ -131,13 +131,13 @@ impl Flatten for Mat1 #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Mat1 - { Mat1::new(l[off]) } + { Mat1::new(copy l[off]) } #[inline(always)] fn flatten(&self) -> ~[N] - { ~[ self.m11 ] } + { ~[ copy self.m11 ] } #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) - { l[off] = self.m11 } + { l[off] = copy self.m11 } } diff --git a/src/dim1/vec1.rs b/src/dim1/vec1.rs index 1e451586..bb1db436 100644 --- a/src/dim1/vec1.rs +++ b/src/dim1/vec1.rs @@ -51,7 +51,7 @@ ScalarMul for Vec1 #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) - { self.x *= *s; } + { self.x = self.x * copy *s; } } @@ -64,7 +64,7 @@ ScalarDiv for Vec1 #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) - { self.x /= *s; } + { self.x = self.x / copy *s; } } impl> @@ -76,7 +76,7 @@ ScalarAdd for Vec1 #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) - { self.x += *s; } + { self.x = self.x + copy *s; } } impl> @@ -88,14 +88,14 @@ ScalarSub for Vec1 #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) - { self.x -= *s; } + { self.x = self.x - copy *s; } } impl> Translation> for Vec1 { #[inline(always)] fn translation(&self) -> Vec1 - { *self } + { copy *self } #[inline(always)] fn translated(&self, t: &Vec1) -> Vec1 @@ -103,7 +103,7 @@ impl> Translation> for Vec1 #[inline(always)] fn translate(&mut self, t: &Vec1) - { *self += *t } + { *self = *self + copy *t } } impl> Dot for Vec1 @@ -140,7 +140,7 @@ Norm for Vec1 { let l = self.norm(); - self.x /= l; + self.x = self.x / copy l; l } @@ -208,15 +208,15 @@ impl Flatten for Vec1 #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Vec1 - { Vec1::new(l[off]) } + { Vec1::new(copy l[off]) } #[inline(always)] fn flatten(&self) -> ~[N] - { ~[ self.x ] } + { ~[ copy self.x ] } #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) - { l[off] = self.x } + { l[off] = copy self.x } } impl Bounded for Vec1 diff --git a/src/dim2/mat2.rs b/src/dim2/mat2.rs index 719e4593..bf8516de 100644 --- a/src/dim2/mat2.rs +++ b/src/dim2/mat2.rs @@ -42,8 +42,8 @@ impl One for Mat2 fn one() -> Mat2 { let (_0, _1) = (Zero::zero(), One::one()); - return Mat2::new(_1, _0, - _0, _1) + return Mat2::new(copy _1, copy _0, + copy _0, copy _1) } } @@ -53,8 +53,8 @@ impl Zero for Mat2 fn zero() -> Mat2 { let _0 = Zero::zero(); - return Mat2::new(_0, _0, - _0, _0) + return Mat2::new(copy _0, copy _0, + copy _0, copy _0) } #[inline(always)] @@ -109,7 +109,7 @@ Inv for Mat2 #[inline(always)] fn inverse(&self) -> Mat2 { - let mut res : Mat2 = *self; + let mut res : Mat2 = copy *self; res.invert(); @@ -133,8 +133,8 @@ impl Transpose for Mat2 #[inline(always)] fn transposed(&self) -> Mat2 { - Mat2::new(self.m11, self.m21, - self.m12, self.m22) + Mat2::new(copy self.m11, copy self.m21, + copy self.m12, copy self.m22) } #[inline(always)] @@ -184,18 +184,18 @@ impl Flatten for Mat2 #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Mat2 - { Mat2::new(l[off], l[off + 1], l[off + 2], l[off + 3]) } + { Mat2::new(copy l[off], copy l[off + 1], copy l[off + 2], copy l[off + 3]) } #[inline(always)] fn flatten(&self) -> ~[N] - { ~[ self.m11, self.m12, self.m21, self.m22 ] } + { ~[ copy self.m11, copy self.m12, copy self.m21, copy self.m22 ] } #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { - l[off] = self.m11; - l[off + 1] = self.m12; - l[off + 2] = self.m21; - l[off + 3] = self.m22; + l[off] = copy self.m11; + l[off + 1] = copy self.m12; + l[off + 2] = copy self.m21; + l[off + 3] = copy self.m22; } } diff --git a/src/dim2/vec2.rs b/src/dim2/vec2.rs index ff230448..e339b020 100644 --- a/src/dim2/vec2.rs +++ b/src/dim2/vec2.rs @@ -57,8 +57,8 @@ ScalarMul for Vec2 #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) { - self.x *= *s; - self.y *= *s; + self.x = self.x * copy *s; + self.y = self.y * copy *s; } } @@ -73,8 +73,8 @@ ScalarDiv for Vec2 #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) { - self.x /= *s; - self.y /= *s; + self.x = self.x / copy *s; + self.y = self.y / copy *s; } } @@ -88,8 +88,8 @@ ScalarAdd for Vec2 #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) { - self.x += *s; - self.y += *s; + self.x = self.x + copy *s; + self.y = self.y + copy *s; } } @@ -103,8 +103,8 @@ ScalarSub for Vec2 #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) { - self.x -= *s; - self.y -= *s; + self.x = self.x - copy *s; + self.y = self.y - copy *s; } } @@ -112,7 +112,7 @@ impl> Translation> for Vec2 { #[inline(always)] fn translation(&self) -> Vec2 - { *self } + { copy *self } #[inline(always)] fn translated(&self, t: &Vec2) -> Vec2 @@ -120,7 +120,7 @@ impl> Translation> for Vec2 #[inline(always)] fn translate(&mut self, t: &Vec2) - { *self += *t; } + { *self = *self + copy *t; } } impl + Add> Dot for Vec2 @@ -161,10 +161,10 @@ Norm for Vec2 { let l = self.norm(); - self.x /= l; - self.y /= l; + self.x = self.x / copy l; + self.y = self.y / copy l; - l + copy l } } @@ -188,7 +188,7 @@ impl Zero for Vec2 fn zero() -> Vec2 { let _0 = Zero::zero(); - Vec2::new(_0, _0) + Vec2::new(copy _0, copy _0) } #[inline(always)] @@ -208,7 +208,7 @@ impl> Basis for Vec2 #[inline(always)] fn orthogonal_subspace_basis(&self) -> ~[Vec2] - { ~[ Vec2::new(-self.y, self.x) ] } + { ~[ Vec2::new(-self.y, copy self.x) ] } } impl> ApproxEq for Vec2 @@ -244,17 +244,17 @@ impl Flatten for Vec2 #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Vec2 - { Vec2::new(l[off], l[off + 1]) } + { Vec2::new(copy l[off], copy l[off + 1]) } #[inline(always)] fn flatten(&self) -> ~[N] - { ~[ self.x, self.y ] } + { ~[ copy self.x, copy self.y ] } #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { - l[off] = self.x; - l[off + 1] = self.y; + l[off] = copy self.x; + l[off + 1] = copy self.y; } } diff --git a/src/dim3/mat3.rs b/src/dim3/mat3.rs index b65e5a79..2df78237 100644 --- a/src/dim3/mat3.rs +++ b/src/dim3/mat3.rs @@ -46,9 +46,9 @@ impl One for Mat3 fn one() -> Mat3 { let (_0, _1) = (Zero::zero(), One::one()); - return Mat3::new(_1, _0, _0, - _0, _1, _0, - _0, _0, _1) + return Mat3::new(copy _1, copy _0, copy _0, + copy _0, copy _1, copy _0, + copy _0, copy _0, copy _1) } } @@ -58,9 +58,9 @@ impl Zero for Mat3 fn zero() -> Mat3 { let _0 = Zero::zero(); - return Mat3::new(_0, _0, _0, - _0, _0, _0, - _0, _0, _0) + return Mat3::new(copy _0, copy _0, copy _0, + copy _0, copy _0, copy _0, + copy _0, copy _0, copy _0) } #[inline(always)] @@ -125,7 +125,7 @@ Inv for Mat3 #[inline(always)] fn inverse(&self) -> Mat3 { - let mut res = *self; + let mut res = copy *self; res.invert(); @@ -166,9 +166,9 @@ impl Transpose for Mat3 #[inline(always)] fn transposed(&self) -> Mat3 { - Mat3::new(self.m11, self.m21, self.m31, - self.m12, self.m22, self.m32, - self.m13, self.m23, self.m33) + Mat3::new(copy self.m11, copy self.m21, copy self.m31, + copy self.m12, copy self.m22, copy self.m32, + copy self.m13, copy self.m23, copy self.m33) } #[inline(always)] @@ -238,31 +238,31 @@ impl Flatten for Mat3 #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Mat3 - { Mat3::new(l[off + 0], l[off + 1], l[off + 2], - l[off + 3], l[off + 4], l[off + 5], - l[off + 6], l[off + 7], l[off + 8]) } + { 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 + 6], copy l[off + 7], copy l[off + 8]) } #[inline(always)] fn flatten(&self) -> ~[N] { ~[ - self.m11, self.m12, self.m13, - self.m21, self.m22, self.m23, - self.m31, self.m32, self.m33 + copy self.m11, copy self.m12, copy self.m13, + copy self.m21, copy self.m22, copy self.m23, + copy self.m31, copy self.m32, copy self.m33 ] } #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { - l[off + 0] = self.m11; - l[off + 1] = self.m12; - l[off + 2] = self.m13; - l[off + 3] = self.m21; - l[off + 4] = self.m22; - l[off + 5] = self.m23; - l[off + 6] = self.m31; - l[off + 7] = self.m32; - l[off + 8] = self.m33; + l[off + 0] = copy self.m11; + l[off + 1] = copy self.m12; + l[off + 2] = copy self.m13; + l[off + 3] = copy self.m21; + l[off + 4] = copy self.m22; + l[off + 5] = copy self.m23; + l[off + 6] = copy self.m31; + l[off + 7] = copy self.m32; + l[off + 8] = copy self.m33; } } diff --git a/src/dim3/vec3.rs b/src/dim3/vec3.rs index 235d9420..7cfa5eab 100644 --- a/src/dim3/vec3.rs +++ b/src/dim3/vec3.rs @@ -57,9 +57,9 @@ ScalarMul for Vec3 #[inline(always)] fn scalar_mul_inplace(&mut self, s: &N) { - self.x *= *s; - self.y *= *s; - self.z *= *s; + self.x = self.x * copy *s; + self.y = self.y * copy *s; + self.z = self.z * copy *s; } } @@ -74,9 +74,9 @@ ScalarDiv for Vec3 #[inline(always)] fn scalar_div_inplace(&mut self, s: &N) { - self.x /= *s; - self.y /= *s; - self.z /= *s; + self.x = self.x / copy *s; + self.y = self.y / copy *s; + self.z = self.z / copy *s; } } @@ -90,9 +90,9 @@ ScalarAdd for Vec3 #[inline(always)] fn scalar_add_inplace(&mut self, s: &N) { - self.x += *s; - self.y += *s; - self.z += *s; + self.x = self.x + copy *s; + self.y = self.y + copy *s; + self.z = self.z + copy *s; } } @@ -106,9 +106,9 @@ ScalarSub for Vec3 #[inline(always)] fn scalar_sub_inplace(&mut self, s: &N) { - self.x -= *s; - self.y -= *s; - self.z -= *s; + self.x = self.x - copy *s; + self.y = self.y - copy *s; + self.z = self.z - copy *s; } } @@ -116,7 +116,7 @@ impl> Translation> for Vec3 { #[inline(always)] fn translation(&self) -> Vec3 - { *self } + { copy *self } #[inline(always)] fn translated(&self, t: &Vec3) -> Vec3 @@ -124,7 +124,7 @@ impl> Translation> for Vec3 #[inline(always)] fn translate(&mut self, t: &Vec3) - { *self += *t; } + { *self = *self + copy *t; } } @@ -174,9 +174,9 @@ Norm for Vec3 { let l = self.norm(); - self.x /= l; - self.y /= l; - self.z /= l; + self.x = self.x / copy l; + self.y = self.y / copy l; + self.z = self.z / copy l; l } @@ -201,7 +201,7 @@ impl Zero for Vec3 fn zero() -> Vec3 { let _0 = Zero::zero(); - Vec3::new(_0, _0, _0) + Vec3::new(copy _0, copy _0, copy _0) } #[inline(always)] @@ -226,12 +226,12 @@ Basis for Vec3 fn orthogonal_subspace_basis(&self) -> ~[Vec3] { let a = - if (abs(self.x) > abs(self.y)) - { Vec3::new(self.z, Zero::zero(), -self.x).normalized() } + if (abs(copy self.x) > abs(copy self.y)) + { Vec3::new(copy self.z, Zero::zero(), -copy self.x).normalized() } else - { Vec3::new(Zero::zero(), -self.z, self.y).normalized() }; + { Vec3::new(Zero::zero(), -self.z, copy self.y).normalized() }; - ~[ a, a.cross(self) ] + ~[ a.cross(self), a ] } } @@ -273,18 +273,18 @@ impl Flatten for Vec3 #[inline(always)] fn from_flattened(l: &[N], off: uint) -> Vec3 - { Vec3::new(l[off], l[off + 1], l[off + 2]) } + { Vec3::new(copy l[off], copy l[off + 1], copy l[off + 2]) } #[inline(always)] fn flatten(&self) -> ~[N] - { ~[ self.x, self.y, self.z ] } + { ~[ copy self.x, copy self.y, copy self.z ] } #[inline(always)] fn flatten_to(&self, l: &mut [N], off: uint) { - l[off] = self.x; - l[off + 1] = self.y; - l[off + 2] = self.z; + l[off] = copy self.x; + l[off + 1] = copy self.y; + l[off + 2] = copy self.z; } } diff --git a/src/ndim/dmat.rs b/src/ndim/dmat.rs index 9e951b2b..45d213ef 100644 --- a/src/ndim/dmat.rs +++ b/src/ndim/dmat.rs @@ -47,7 +47,7 @@ impl DMat { assert!(i < self.dim); assert!(j < self.dim); - self.mij[self.offset(i, j)] = *t + self.mij[self.offset(i, j)] = copy *t } #[inline(always)] @@ -55,7 +55,7 @@ impl DMat { assert!(i < self.dim); assert!(j < self.dim); - self.mij[self.offset(i, j)] + copy self.mij[self.offset(i, j)] } } @@ -83,7 +83,7 @@ Mul, DMat> for DMat let mut acc = Zero::zero::(); for iterate(0u, dim) |k| - { acc += self.at(i, k) * other.at(k, j); } + { acc = acc + self.at(i, k) * other.at(k, j); } res.set(i, j, &acc); } @@ -166,7 +166,7 @@ Inv for DMat if (self.at(n0, k) != _0T) { break; } - n0 += 1; + n0 = n0 + 1; } assert!(n0 != dim); // non inversible matrix diff --git a/src/ndim/dvec.rs b/src/ndim/dvec.rs index df439bea..af348472 100644 --- a/src/ndim/dvec.rs +++ b/src/ndim/dvec.rs @@ -62,10 +62,10 @@ impl> DVec let mut elt = basis_element.clone(); - elt -= self.scalar_mul(&basis_element.dot(self)); + elt = elt - self.scalar_mul(&basis_element.dot(self)); for res.each |v| - { elt -= v.scalar_mul(&elt.dot(v)) }; + { elt = elt - v.scalar_mul(&elt.dot(v)) }; if (!elt.sqnorm().approx_eq(&Zero::zero())) { res.push(elt.normalized()); } @@ -115,7 +115,7 @@ Dot for DVec let mut res = Zero::zero::(); for iterate(0u, self.at.len()) |i| - { res += self.at[i] * other.at[i]; } + { res = res + self.at[i] * other.at[i]; } res } @@ -129,7 +129,7 @@ impl SubDot for DVec let mut res = Zero::zero::(); for iterate(0u, self.at.len()) |i| - { res += (self.at[i] - a.at[i]) * b.at[i]; } + { res = res + (self.at[i] - a.at[i]) * b.at[i]; } res } @@ -146,7 +146,7 @@ ScalarMul for DVec fn scalar_mul_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| - { self.at[i] *= *s; } + { self.at[i] = self.at[i] * copy *s; } } } @@ -162,7 +162,7 @@ ScalarDiv for DVec fn scalar_div_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| - { self.at[i] /= *s; } + { self.at[i] = self.at[i] / copy *s; } } } @@ -177,7 +177,7 @@ ScalarAdd for DVec fn scalar_add_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| - { self.at[i] += *s; } + { self.at[i] = self.at[i] + copy *s; } } } @@ -192,7 +192,7 @@ ScalarSub for DVec fn scalar_sub_inplace(&mut self, s: &N) { for iterate(0u, self.at.len()) |i| - { self.at[i] -= *s; } + { self.at[i] = self.at[i] - copy *s; } } } @@ -238,7 +238,7 @@ Norm for DVec let l = self.norm(); for iterate(0u, self.at.len()) |i| - { self.at[i] /= l; } + { self.at[i] = self.at[i] / copy l; } l } diff --git a/src/ndim/nmat.rs b/src/ndim/nmat.rs index ac13ab80..1fcf5bb5 100644 --- a/src/ndim/nmat.rs +++ b/src/ndim/nmat.rs @@ -77,7 +77,7 @@ Mul, NMat> for NMat let mut acc: N = Zero::zero(); for iterate(0u, dim) |k| - { acc += self[(i, k)] * other[(k, j)]; } + { acc = acc + self[(i, k)] * other[(k, j)]; } res.set(i, j, &acc); } @@ -197,7 +197,7 @@ impl Flatten for NMat let mut res = Zero::zero::>(); for iterate(0u, dim * dim) |i| - { res.mij.mij[i] = l[off + i] } + { res.mij.mij[i] = copy l[off + i] } res } @@ -209,7 +209,7 @@ impl Flatten for NMat let mut res = ~[]; for iterate(0u, dim * dim) |i| - { res.push(self.mij.mij[i]) } + { res.push(copy self.mij.mij[i]) } res } @@ -220,6 +220,6 @@ impl Flatten for NMat let dim = Dim::dim::(); for iterate(0u, dim * dim) |i| - { l[off + i] = self.mij.mij[i] } + { l[off + i] = copy self.mij.mij[i] } } } diff --git a/src/ndim/nvec.rs b/src/ndim/nvec.rs index c8cd5497..ab46b936 100644 --- a/src/ndim/nvec.rs +++ b/src/ndim/nvec.rs @@ -239,7 +239,7 @@ impl Flatten for NVec let mut res = Zero::zero::>(); for iterate(0u, dim) |i| - { res.at.at[i] = l[off + i] } + { res.at.at[i] = copy l[off + i] } res } @@ -251,7 +251,7 @@ impl Flatten for NVec let mut res = ~[]; for iterate(0u, dim) |i| - { res.push(self.at.at[i]) } + { res.push(copy self.at.at[i]) } res } @@ -262,7 +262,7 @@ impl Flatten for NVec let dim = Dim::dim::(); for iterate(0u, dim) |i| - { l[off + i] = self.at.at[i] } + { l[off + i] = copy self.at.at[i] } } } diff --git a/src/tests/vec.rs b/src/tests/vec.rs index 97464422..f6300733 100644 --- a/src/tests/vec.rs +++ b/src/tests/vec.rs @@ -28,6 +28,8 @@ use traits::dot::Dot; use traits::norm::Norm; #[test] use traits::flatten::Flatten; +#[test] +use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}; macro_rules! test_commut_dot_impl( ($t: ty) => ( @@ -41,6 +43,30 @@ macro_rules! test_commut_dot_impl( ); ) +macro_rules! test_scalar_op_impl( + ($t: ty, $n: ty) => ( + for 10000.times + { + let v1 : $t = random(); + let n : $n = random(); + + assert!(v1.scalar_mul(&n).scalar_div(&n).approx_eq(&v1)); + assert!(v1.scalar_div(&n).scalar_mul(&n).approx_eq(&v1)); + assert!(v1.scalar_sub(&n).scalar_add(&n).approx_eq(&v1)); + assert!(v1.scalar_add(&n).scalar_sub(&n).approx_eq(&v1)); + + let mut v1 : $t = random(); + let v0 : $t = copy v1; + let n : $n = random(); + + v1.scalar_mul_inplace(&n); + v1.scalar_div_inplace(&n); + + assert!(v1.approx_eq(&v0)); + } + ); +) + macro_rules! test_basis_impl( ($t: ty) => ( for 10000.times @@ -62,9 +88,9 @@ macro_rules! test_subspace_basis_impl( ($t: ty) => ( for 10000.times { - let v : Vec3 = random(); - let v1 = v.normalized(); - let subbasis = v1.orthogonal_subspace_basis(); + let v : $t = random(); + let v1 = v.normalized(); + let subbasis = v1.orthogonal_subspace_basis(); // check vectors are orthogonal to v1 assert!(subbasis.all(|e| v1.dot(e).approx_eq(&Zero::zero()))); @@ -111,7 +137,7 @@ fn test_cross_vec3() #[test] fn test_commut_dot_nvec() { test_commut_dot_impl!(NVec); } - + #[test] fn test_commut_dot_vec3() { test_commut_dot_impl!(Vec3); } @@ -171,3 +197,19 @@ fn test_flatten_vec3() #[test] fn test_flatten_nvec() { test_flatten_impl!(NVec, f64); } + +#[test] +fn test_scalar_op_vec1() +{ test_scalar_op_impl!(Vec1, f64); } + +#[test] +fn test_scalar_op_vec2() +{ test_scalar_op_impl!(Vec2, f64); } + +#[test] +fn test_scalar_op_vec3() +{ test_scalar_op_impl!(Vec3, f64); } + +#[test] +fn test_scalar_op_nvec() +{ test_scalar_op_impl!(NVec, f64); }