Use Clone instead of Copy.

This commit is contained in:
Sébastien Crozet 2013-07-05 22:54:42 +00:00
parent 6f081b70b8
commit 831f561441
5 changed files with 31 additions and 2 deletions

View File

@ -15,7 +15,7 @@ use vec::Vec1;
use mat::{Mat2, Mat3};
use vec::Vec3;
#[deriving(Eq, ToStr)]
#[deriving(Eq, ToStr, Clone)]
pub struct Rotmat<M>
{ priv submat: M }

View File

@ -11,7 +11,7 @@ use traits::rlmul::{RMul, LMul};
use traits::homogeneous::{ToHomogeneous, FromHomogeneous};
use traits::column::Column;
#[deriving(Eq, ToStr)]
#[deriving(Eq, ToStr, Clone)]
pub struct Transform<M, V>
{
priv submat : M,

View File

@ -25,6 +25,7 @@ pub struct Vec1<N>
{ at: [N, ..1] }
clone_impl!(Vec1)
deep_clone_impl!(Vec1)
new_impl!(Vec1, 1)
new_repeat_impl!(Vec1, elem, [elem])
indexable_impl!(Vec1)
@ -60,6 +61,7 @@ pub struct Vec2<N>
{ at: [N, ..2] }
clone_impl!(Vec2)
deep_clone_impl!(Vec2)
new_impl!(Vec2, 2)
new_repeat_impl!(Vec2, elem, [elem | elem])
indexable_impl!(Vec2)
@ -95,6 +97,7 @@ pub struct Vec3<N>
{ at: [N, ..3] }
clone_impl!(Vec3)
deep_clone_impl!(Vec3)
new_impl!(Vec3, 3)
new_repeat_impl!(Vec3, elem, [elem | elem | elem])
indexable_impl!(Vec3)
@ -130,6 +133,7 @@ pub struct Vec4<N>
{ at: [N, ..4] }
clone_impl!(Vec4)
deep_clone_impl!(Vec4)
new_impl!(Vec4, 4)
new_repeat_impl!(Vec4, elem, [elem | elem | elem | elem])
indexable_impl!(Vec4)
@ -165,6 +169,7 @@ pub struct Vec5<N>
{ at: [N, ..5] }
clone_impl!(Vec5)
deep_clone_impl!(Vec5)
new_impl!(Vec5, 5)
new_repeat_impl!(Vec5, elem, [elem | elem | elem | elem | elem])
indexable_impl!(Vec5)
@ -200,6 +205,7 @@ pub struct Vec6<N>
{ at: [N, ..6] }
clone_impl!(Vec6)
deep_clone_impl!(Vec6)
new_impl!(Vec6, 6)
new_repeat_impl!(Vec6, elem, [elem | elem | elem | elem | elem | elem])
indexable_impl!(Vec6)

View File

@ -14,6 +14,21 @@ macro_rules! clone_impl(
)
)
macro_rules! deep_clone_impl(
($t:ident) => (
// FIXME: use 'DeepClone' alone. For the moment, we need 'Copy' because the automatic
// implementation of DeepClone for [t, ..n] is badly typed.
// XXX: this does not do a real deep clone
impl<N: DeepClone + Copy> DeepClone for $t<N>
{
fn deep_clone(&self) -> $t<N>
{
$t { at: copy self.at }
}
}
)
)
macro_rules! new_impl(
($t: ident, $dim: expr) => (
impl<N> $t<N>

View File

@ -109,3 +109,11 @@ impl UniformSphereSample for Vec2<f64>
{ f(sample) }
}
}
impl UniformSphereSample for Vec3<f64>
{
pub fn sample(_: &fn(&'static Vec3<f64>))
{
fail!("UniformSphereSample for Vec3<f64> is not yet implemented.")
}
}