diff --git a/README.md b/README.md index c9882d44..22aa58ee 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,7 @@ usable for graphics too. ## Compilation You will need the last rust compiler from the master branch. -I pull the compiler and fix my code almost every days. If you encounter -problems, make sure you have the last version. +If you encounter problems, make sure you have the last version before creating an issue. git clone git://github.com/sebcrozet/nalgebra.git cd nalgebra diff --git a/src/vec.rs b/src/vec.rs index 52946527..f3160a83 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -40,6 +40,7 @@ pub struct Vec1 } new_impl!(Vec1, x) +vec_axis_impl!(Vec1, x) vec_cast_impl!(Vec1, x) indexable_impl!(Vec1, 1) new_repeat_impl!(Vec1, val, x) @@ -77,6 +78,7 @@ pub struct Vec2 } new_impl!(Vec2, x, y) +vec_axis_impl!(Vec2, x, y) vec_cast_impl!(Vec2, x, y) indexable_impl!(Vec2, 2) new_repeat_impl!(Vec2, val, x, y) @@ -118,6 +120,7 @@ pub struct Vec3 new_impl!(Vec3, x, y, z) +vec_axis_impl!(Vec3, x, y, z) vec_cast_impl!(Vec3, x, y, z) indexable_impl!(Vec3, 3) new_repeat_impl!(Vec3, val, x, y, z) @@ -159,6 +162,7 @@ pub struct Vec4 } new_impl!(Vec4, x, y, z, w) +vec_axis_impl!(Vec4, x, y, z, w) vec_cast_impl!(Vec4, x, y, z, w) indexable_impl!(Vec4, 4) new_repeat_impl!(Vec4, val, x, y, z, w) @@ -202,6 +206,7 @@ pub struct Vec5 } new_impl!(Vec5, x, y, z, w, a) +vec_axis_impl!(Vec5, x, y, z, w, a) vec_cast_impl!(Vec5, x, y, z, w, a) indexable_impl!(Vec5, 5) new_repeat_impl!(Vec5, val, x, y, z, w, a) @@ -247,6 +252,7 @@ pub struct Vec6 } new_impl!(Vec6, x, y, z, w, a, b) +vec_axis_impl!(Vec6, x, y, z, w, a, b) vec_cast_impl!(Vec6, x, y, z, w, a, b) indexable_impl!(Vec6, 6) new_repeat_impl!(Vec6, val, x, y, z, w, a, b) diff --git a/src/vec_macros.rs b/src/vec_macros.rs index 754c07e8..8ec7712b 100644 --- a/src/vec_macros.rs +++ b/src/vec_macros.rs @@ -16,6 +16,38 @@ macro_rules! new_impl( } ) ) + +macro_rules! vec_axis_impl( + ($t: ident, $comp0: ident $(,$compN: ident)*) => ( + impl $t + { + /// Create a unit vector with its `$comp0` component equal to 1.0. + #[inline] + pub fn $comp0() -> $t + { + let mut res: $t = Zero::zero(); + + res.$comp0 = One::one(); + + res + } + + $( + /// Create a unit vector with its `$compN` component equal to 1.0. + #[inline] + pub fn $compN() -> $t + { + let mut res: $t = Zero::zero(); + + res.$compN = One::one(); + + res + } + )* + } + ) +) + macro_rules! vec_cast_impl( ($t: ident, $comp0: ident $(,$compN: ident)*) => ( impl VecCast<$t> for $t