forked from M-Labs/nalgebra
Add static methods to build canonical axis.
For exemple use: Vec3::x() to create the vector Vec3::new(1.0, 0.0, 0.0). The same aplies for y, z, w, etc.
This commit is contained in:
parent
e75fe80966
commit
4f3de703b7
@ -10,8 +10,7 @@ usable for graphics too.
|
|||||||
|
|
||||||
## Compilation
|
## Compilation
|
||||||
You will need the last rust compiler from the master branch.
|
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
|
If you encounter problems, make sure you have the last version before creating an issue.
|
||||||
problems, make sure you have the last version.
|
|
||||||
|
|
||||||
git clone git://github.com/sebcrozet/nalgebra.git
|
git clone git://github.com/sebcrozet/nalgebra.git
|
||||||
cd nalgebra
|
cd nalgebra
|
||||||
|
@ -40,6 +40,7 @@ pub struct Vec1<N>
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_impl!(Vec1, x)
|
new_impl!(Vec1, x)
|
||||||
|
vec_axis_impl!(Vec1, x)
|
||||||
vec_cast_impl!(Vec1, x)
|
vec_cast_impl!(Vec1, x)
|
||||||
indexable_impl!(Vec1, 1)
|
indexable_impl!(Vec1, 1)
|
||||||
new_repeat_impl!(Vec1, val, x)
|
new_repeat_impl!(Vec1, val, x)
|
||||||
@ -77,6 +78,7 @@ pub struct Vec2<N>
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_impl!(Vec2, x, y)
|
new_impl!(Vec2, x, y)
|
||||||
|
vec_axis_impl!(Vec2, x, y)
|
||||||
vec_cast_impl!(Vec2, x, y)
|
vec_cast_impl!(Vec2, x, y)
|
||||||
indexable_impl!(Vec2, 2)
|
indexable_impl!(Vec2, 2)
|
||||||
new_repeat_impl!(Vec2, val, x, y)
|
new_repeat_impl!(Vec2, val, x, y)
|
||||||
@ -118,6 +120,7 @@ pub struct Vec3<N>
|
|||||||
|
|
||||||
|
|
||||||
new_impl!(Vec3, x, y, z)
|
new_impl!(Vec3, x, y, z)
|
||||||
|
vec_axis_impl!(Vec3, x, y, z)
|
||||||
vec_cast_impl!(Vec3, x, y, z)
|
vec_cast_impl!(Vec3, x, y, z)
|
||||||
indexable_impl!(Vec3, 3)
|
indexable_impl!(Vec3, 3)
|
||||||
new_repeat_impl!(Vec3, val, x, y, z)
|
new_repeat_impl!(Vec3, val, x, y, z)
|
||||||
@ -159,6 +162,7 @@ pub struct Vec4<N>
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_impl!(Vec4, x, y, z, w)
|
new_impl!(Vec4, x, y, z, w)
|
||||||
|
vec_axis_impl!(Vec4, x, y, z, w)
|
||||||
vec_cast_impl!(Vec4, x, y, z, w)
|
vec_cast_impl!(Vec4, x, y, z, w)
|
||||||
indexable_impl!(Vec4, 4)
|
indexable_impl!(Vec4, 4)
|
||||||
new_repeat_impl!(Vec4, val, x, y, z, w)
|
new_repeat_impl!(Vec4, val, x, y, z, w)
|
||||||
@ -202,6 +206,7 @@ pub struct Vec5<N>
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_impl!(Vec5, x, y, z, w, a)
|
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)
|
vec_cast_impl!(Vec5, x, y, z, w, a)
|
||||||
indexable_impl!(Vec5, 5)
|
indexable_impl!(Vec5, 5)
|
||||||
new_repeat_impl!(Vec5, val, x, y, z, w, a)
|
new_repeat_impl!(Vec5, val, x, y, z, w, a)
|
||||||
@ -247,6 +252,7 @@ pub struct Vec6<N>
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_impl!(Vec6, x, y, z, w, a, b)
|
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)
|
vec_cast_impl!(Vec6, x, y, z, w, a, b)
|
||||||
indexable_impl!(Vec6, 6)
|
indexable_impl!(Vec6, 6)
|
||||||
new_repeat_impl!(Vec6, val, x, y, z, w, a, b)
|
new_repeat_impl!(Vec6, val, x, y, z, w, a, b)
|
||||||
|
@ -16,6 +16,38 @@ macro_rules! new_impl(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
macro_rules! vec_axis_impl(
|
||||||
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
|
impl<N: Zero + One> $t<N>
|
||||||
|
{
|
||||||
|
/// Create a unit vector with its `$comp0` component equal to 1.0.
|
||||||
|
#[inline]
|
||||||
|
pub fn $comp0() -> $t<N>
|
||||||
|
{
|
||||||
|
let mut res: $t<N> = Zero::zero();
|
||||||
|
|
||||||
|
res.$comp0 = One::one();
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
/// Create a unit vector with its `$compN` component equal to 1.0.
|
||||||
|
#[inline]
|
||||||
|
pub fn $compN() -> $t<N>
|
||||||
|
{
|
||||||
|
let mut res: $t<N> = Zero::zero();
|
||||||
|
|
||||||
|
res.$compN = One::one();
|
||||||
|
|
||||||
|
res
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
macro_rules! vec_cast_impl(
|
macro_rules! vec_cast_impl(
|
||||||
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
impl<Nin: NumCast + Clone, Nout: NumCast> VecCast<$t<Nout>> for $t<Nin>
|
impl<Nin: NumCast + Clone, Nout: NumCast> VecCast<$t<Nout>> for $t<Nin>
|
||||||
|
Loading…
Reference in New Issue
Block a user