Add `to_pnt` and `to_vec` methods.
This commit is contained in:
parent
924d8269d8
commit
7e9bb98823
|
@ -59,7 +59,7 @@ at_fast_impl!(Pnt1, 1)
|
|||
new_repeat_impl!(Pnt1, val, x)
|
||||
dim_impl!(Pnt1, 1)
|
||||
container_impl!(Pnt1)
|
||||
pnt_as_vec_impl!(Pnt1, Vec1)
|
||||
pnt_as_vec_impl!(Pnt1, Vec1, x)
|
||||
pnt_sub_impl!(Pnt1, Vec1, Pnt1SubRhs)
|
||||
neg_impl!(Pnt1, x)
|
||||
pnt_add_vec_impl!(Pnt1, Vec1, Pnt1AddRhs, x)
|
||||
|
@ -150,7 +150,7 @@ at_fast_impl!(Pnt2, 2)
|
|||
new_repeat_impl!(Pnt2, val, x, y)
|
||||
dim_impl!(Pnt2, 2)
|
||||
container_impl!(Pnt2)
|
||||
pnt_as_vec_impl!(Pnt2, Vec2)
|
||||
pnt_as_vec_impl!(Pnt2, Vec2, x, y)
|
||||
pnt_sub_impl!(Pnt2, Vec2, Pnt2SubRhs)
|
||||
neg_impl!(Pnt2, x, y)
|
||||
pnt_add_vec_impl!(Pnt2, Vec2, Pnt2AddRhs, x, y)
|
||||
|
@ -243,7 +243,7 @@ at_fast_impl!(Pnt3, 3)
|
|||
new_repeat_impl!(Pnt3, val, x, y, z)
|
||||
dim_impl!(Pnt3, 3)
|
||||
container_impl!(Pnt3)
|
||||
pnt_as_vec_impl!(Pnt3, Vec3)
|
||||
pnt_as_vec_impl!(Pnt3, Vec3, x, y, z)
|
||||
pnt_sub_impl!(Pnt3, Vec3, Pnt3SubRhs)
|
||||
neg_impl!(Pnt3, x, y, z)
|
||||
pnt_add_vec_impl!(Pnt3, Vec3, Pnt3AddRhs, x, y, z)
|
||||
|
@ -338,7 +338,7 @@ at_fast_impl!(Pnt4, 4)
|
|||
new_repeat_impl!(Pnt4, val, x, y, z, w)
|
||||
dim_impl!(Pnt4, 4)
|
||||
container_impl!(Pnt4)
|
||||
pnt_as_vec_impl!(Pnt4, Vec4)
|
||||
pnt_as_vec_impl!(Pnt4, Vec4, x, y, z, w)
|
||||
pnt_sub_impl!(Pnt4, Vec4, Pnt4SubRhs)
|
||||
neg_impl!(Pnt4, x, y, z, w)
|
||||
pnt_add_vec_impl!(Pnt4, Vec4, Pnt4AddRhs, x, y, z, w)
|
||||
|
@ -435,7 +435,7 @@ at_fast_impl!(Pnt5, 5)
|
|||
new_repeat_impl!(Pnt5, val, x, y, z, w, a)
|
||||
dim_impl!(Pnt5, 5)
|
||||
container_impl!(Pnt5)
|
||||
pnt_as_vec_impl!(Pnt5, Vec5)
|
||||
pnt_as_vec_impl!(Pnt5, Vec5, x, y, z, w, a)
|
||||
pnt_sub_impl!(Pnt5, Vec5, Pnt5SubRhs)
|
||||
neg_impl!(Pnt5, x, y, z, w, a)
|
||||
pnt_add_vec_impl!(Pnt5, Vec5, Pnt5AddRhs, x, y, z, w, a)
|
||||
|
@ -534,7 +534,7 @@ at_fast_impl!(Pnt6, 6)
|
|||
new_repeat_impl!(Pnt6, val, x, y, z, w, a, b)
|
||||
dim_impl!(Pnt6, 6)
|
||||
container_impl!(Pnt6)
|
||||
pnt_as_vec_impl!(Pnt6, Vec6)
|
||||
pnt_as_vec_impl!(Pnt6, Vec6, x, y, z, w, a, b)
|
||||
pnt_sub_impl!(Pnt6, Vec6, Pnt6SubRhs)
|
||||
neg_impl!(Pnt6, x, y, z, w, a, b)
|
||||
pnt_add_vec_impl!(Pnt6, Vec6, Pnt6AddRhs, x, y, z, w, a, b)
|
||||
|
|
|
@ -53,8 +53,16 @@ macro_rules! pnt_sub_vec_impl(
|
|||
)
|
||||
|
||||
macro_rules! pnt_as_vec_impl(
|
||||
($t: ident, $tv: ident) => (
|
||||
($t: ident, $tv: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||
impl<N> $t<N> {
|
||||
#[inline]
|
||||
pub fn to_vec(self) -> $tv<N> {
|
||||
$tv::new(
|
||||
self.$comp0
|
||||
$(, self.$compN)*
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_vec<'a>(&'a self) -> &'a $tv<N> {
|
||||
unsafe {
|
||||
|
@ -64,6 +72,11 @@ macro_rules! pnt_as_vec_impl(
|
|||
}
|
||||
|
||||
impl<N> PntAsVec<$tv<N>> for $t<N> {
|
||||
#[inline]
|
||||
fn to_vec(self) -> $tv<N> {
|
||||
self.to_vec()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn as_vec<'a>(&'a self) -> &'a $tv<N> {
|
||||
self.as_vec()
|
||||
|
|
|
@ -129,7 +129,7 @@ translate_impl!(Vec1, Pnt1)
|
|||
rotate_impl!(Vec1)
|
||||
rotate_impl!(Pnt1)
|
||||
transform_impl!(Vec1, Pnt1)
|
||||
vec_as_pnt_impl!(Vec1, Pnt1)
|
||||
vec_as_pnt_impl!(Vec1, Pnt1, x)
|
||||
|
||||
/// Vector of dimension 2.
|
||||
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Zero, Show)]
|
||||
|
@ -230,7 +230,7 @@ translate_impl!(Vec2, Pnt2)
|
|||
rotate_impl!(Vec2)
|
||||
rotate_impl!(Pnt2)
|
||||
transform_impl!(Vec2, Pnt2)
|
||||
vec_as_pnt_impl!(Vec2, Pnt2)
|
||||
vec_as_pnt_impl!(Vec2, Pnt2, x, y)
|
||||
|
||||
/// Vector of dimension 3.
|
||||
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Zero, Show)]
|
||||
|
@ -336,7 +336,7 @@ translate_impl!(Vec3, Pnt3)
|
|||
rotate_impl!(Vec3)
|
||||
rotate_impl!(Pnt3)
|
||||
transform_impl!(Vec3, Pnt3)
|
||||
vec_as_pnt_impl!(Vec3, Pnt3)
|
||||
vec_as_pnt_impl!(Vec3, Pnt3, x, y, z)
|
||||
|
||||
|
||||
/// Vector of dimension 4.
|
||||
|
@ -442,7 +442,7 @@ translate_impl!(Vec4, Pnt4)
|
|||
rotate_impl!(Vec4)
|
||||
rotate_impl!(Pnt4)
|
||||
transform_impl!(Vec4, Pnt4)
|
||||
vec_as_pnt_impl!(Vec4, Pnt4)
|
||||
vec_as_pnt_impl!(Vec4, Pnt4, x, y, z, w)
|
||||
|
||||
/// Vector of dimension 5.
|
||||
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Zero, Show)]
|
||||
|
@ -549,7 +549,7 @@ translate_impl!(Vec5, Pnt5)
|
|||
rotate_impl!(Vec5)
|
||||
rotate_impl!(Pnt5)
|
||||
transform_impl!(Vec5, Pnt5)
|
||||
vec_as_pnt_impl!(Vec5, Pnt5)
|
||||
vec_as_pnt_impl!(Vec5, Pnt5, x, y, z, w, a)
|
||||
|
||||
/// Vector of dimension 6.
|
||||
#[deriving(Eq, PartialEq, Encodable, Decodable, Clone, Hash, Rand, Zero, Show)]
|
||||
|
@ -656,4 +656,4 @@ translate_impl!(Vec6, Pnt6)
|
|||
rotate_impl!(Vec6)
|
||||
rotate_impl!(Pnt6)
|
||||
transform_impl!(Vec6, Pnt6)
|
||||
vec_as_pnt_impl!(Vec6, Pnt6)
|
||||
vec_as_pnt_impl!(Vec6, Pnt6, x, y, z, w, a, b)
|
||||
|
|
|
@ -682,8 +682,16 @@ macro_rules! transform_impl(
|
|||
)
|
||||
|
||||
macro_rules! vec_as_pnt_impl(
|
||||
($tv: ident, $t: ident) => (
|
||||
($tv: ident, $t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||
impl<N> $tv<N> {
|
||||
#[inline]
|
||||
pub fn to_pnt(self) -> $t<N> {
|
||||
$t::new(
|
||||
self.$comp0
|
||||
$(, self.$compN)*
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_pnt<'a>(&'a self) -> &'a $t<N> {
|
||||
unsafe {
|
||||
|
@ -693,6 +701,11 @@ macro_rules! vec_as_pnt_impl(
|
|||
}
|
||||
|
||||
impl<N> VecAsPnt<$t<N>> for $tv<N> {
|
||||
#[inline]
|
||||
fn to_pnt(self) -> $t<N> {
|
||||
self.to_pnt()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn as_pnt<'a>(&'a self) -> &'a $t<N> {
|
||||
self.as_pnt()
|
||||
|
|
|
@ -147,6 +147,9 @@ pub trait IterableMut<N> {
|
|||
*/
|
||||
/// Trait that relates a point of an affine space to a vector of the associated vector space.
|
||||
pub trait VecAsPnt<P> {
|
||||
/// Converts this point to its associated vector.
|
||||
fn to_pnt(self) -> P;
|
||||
|
||||
/// Converts a reference to this point to a reference to its associated vector.
|
||||
fn as_pnt<'a>(&'a self) -> &'a P;
|
||||
}
|
||||
|
@ -187,6 +190,9 @@ impl<N: Float, V: FloatVec<N> + VecExt<N> + Basis> FloatVecExt<N> for V { }
|
|||
*/
|
||||
/// Trait that relates a point of an affine space to a vector of the associated vector space.
|
||||
pub trait PntAsVec<V> {
|
||||
/// Converts this point to its associated vector.
|
||||
fn to_vec(self) -> V;
|
||||
|
||||
/// Converts a reference to this point to a reference to its associated vector.
|
||||
fn as_vec<'a>(&'a self) -> &'a V;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue