From 831f5614418505aa218efaafa970a8bad09f5455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Fri, 5 Jul 2013 22:54:42 +0000 Subject: [PATCH] Use Clone instead of Copy. --- src/adaptors/rotmat.rs | 2 +- src/adaptors/transform.rs | 2 +- src/vec.rs | 6 ++++++ src/vec_impl.rs | 15 +++++++++++++++ src/vec_spec.rs | 8 ++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index 540cf78c..cdad3c03 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -15,7 +15,7 @@ use vec::Vec1; use mat::{Mat2, Mat3}; use vec::Vec3; -#[deriving(Eq, ToStr)] +#[deriving(Eq, ToStr, Clone)] pub struct Rotmat { priv submat: M } diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index d3fd3857..a56092f3 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -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 { priv submat : M, diff --git a/src/vec.rs b/src/vec.rs index 3bb6d9ed..237e6664 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -25,6 +25,7 @@ pub struct Vec1 { 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 { 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 { 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 { 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 { 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 { 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) diff --git a/src/vec_impl.rs b/src/vec_impl.rs index a2e99e7d..95bb27d8 100644 --- a/src/vec_impl.rs +++ b/src/vec_impl.rs @@ -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 DeepClone for $t + { + fn deep_clone(&self) -> $t + { + $t { at: copy self.at } + } + } + ) +) + macro_rules! new_impl( ($t: ident, $dim: expr) => ( impl $t diff --git a/src/vec_spec.rs b/src/vec_spec.rs index dabcc548..bfa64bdd 100644 --- a/src/vec_spec.rs +++ b/src/vec_spec.rs @@ -109,3 +109,11 @@ impl UniformSphereSample for Vec2 { f(sample) } } } + +impl UniformSphereSample for Vec3 +{ + pub fn sample(_: &fn(&'static Vec3)) + { + fail!("UniformSphereSample for Vec3 is not yet implemented.") + } +}