Add pointwise multiplication and division for vectors.
This commit is contained in:
parent
b364920d9b
commit
820790bfa9
14
src/vec.rs
14
src/vec.rs
|
@ -55,6 +55,8 @@ container_impl!(Vec1)
|
||||||
// (specialized) basis_impl!(Vec1, 1)
|
// (specialized) basis_impl!(Vec1, 1)
|
||||||
add_impl!(Vec1, Vec1AddRhs, x)
|
add_impl!(Vec1, Vec1AddRhs, x)
|
||||||
sub_impl!(Vec1, Vec1SubRhs, x)
|
sub_impl!(Vec1, Vec1SubRhs, x)
|
||||||
|
mul_impl!(Vec1, Vec1MulRhs, x)
|
||||||
|
div_impl!(Vec1, Vec1DivRhs, x)
|
||||||
neg_impl!(Vec1, x)
|
neg_impl!(Vec1, x)
|
||||||
dot_impl!(Vec1, x)
|
dot_impl!(Vec1, x)
|
||||||
scalar_mul_impl!(Vec1, f64, Vec1MulRhs, x)
|
scalar_mul_impl!(Vec1, f64, Vec1MulRhs, x)
|
||||||
|
@ -150,6 +152,8 @@ container_impl!(Vec2)
|
||||||
// (specialized) basis_impl!(Vec2, 1)
|
// (specialized) basis_impl!(Vec2, 1)
|
||||||
add_impl!(Vec2, Vec2AddRhs, x, y)
|
add_impl!(Vec2, Vec2AddRhs, x, y)
|
||||||
sub_impl!(Vec2, Vec2SubRhs, x, y)
|
sub_impl!(Vec2, Vec2SubRhs, x, y)
|
||||||
|
mul_impl!(Vec2, Vec2MulRhs, x, y)
|
||||||
|
div_impl!(Vec2, Vec2DivRhs, x, y)
|
||||||
neg_impl!(Vec2, x, y)
|
neg_impl!(Vec2, x, y)
|
||||||
dot_impl!(Vec2, x, y)
|
dot_impl!(Vec2, x, y)
|
||||||
scalar_mul_impl!(Vec2, f64, Vec2MulRhs, x, y)
|
scalar_mul_impl!(Vec2, f64, Vec2MulRhs, x, y)
|
||||||
|
@ -247,6 +251,8 @@ container_impl!(Vec3)
|
||||||
// (specialized) basis_impl!(Vec3, 1)
|
// (specialized) basis_impl!(Vec3, 1)
|
||||||
add_impl!(Vec3, Vec3AddRhs, x, y, z)
|
add_impl!(Vec3, Vec3AddRhs, x, y, z)
|
||||||
sub_impl!(Vec3, Vec3SubRhs, x, y, z)
|
sub_impl!(Vec3, Vec3SubRhs, x, y, z)
|
||||||
|
mul_impl!(Vec3, Vec3MulRhs, x, y, z)
|
||||||
|
div_impl!(Vec3, Vec3DivRhs, x, y, z)
|
||||||
neg_impl!(Vec3, x, y, z)
|
neg_impl!(Vec3, x, y, z)
|
||||||
dot_impl!(Vec3, x, y, z)
|
dot_impl!(Vec3, x, y, z)
|
||||||
scalar_mul_impl!(Vec3, f64, Vec3MulRhs, x, y, z)
|
scalar_mul_impl!(Vec3, f64, Vec3MulRhs, x, y, z)
|
||||||
|
@ -356,6 +362,8 @@ container_impl!(PVec3)
|
||||||
// (specialized) basis_impl!(PVec3, 1)
|
// (specialized) basis_impl!(PVec3, 1)
|
||||||
add_impl!(PVec3, PVec3AddRhs, x, y, z)
|
add_impl!(PVec3, PVec3AddRhs, x, y, z)
|
||||||
sub_impl!(PVec3, PVec3SubRhs, x, y, z)
|
sub_impl!(PVec3, PVec3SubRhs, x, y, z)
|
||||||
|
mul_impl!(PVec3, PVec3MulRhs, x, y, z)
|
||||||
|
div_impl!(PVec3, PVec3DivRhs, x, y, z)
|
||||||
neg_impl!(PVec3, x, y, z)
|
neg_impl!(PVec3, x, y, z)
|
||||||
dot_impl!(PVec3, x, y, z)
|
dot_impl!(PVec3, x, y, z)
|
||||||
scalar_mul_impl!(PVec3, f64, PVec3MulRhs, x, y, z)
|
scalar_mul_impl!(PVec3, f64, PVec3MulRhs, x, y, z)
|
||||||
|
@ -457,6 +465,8 @@ container_impl!(Vec4)
|
||||||
basis_impl!(Vec4, Vec4MulRhs, 4)
|
basis_impl!(Vec4, Vec4MulRhs, 4)
|
||||||
add_impl!(Vec4, Vec4AddRhs, x, y, z, w)
|
add_impl!(Vec4, Vec4AddRhs, x, y, z, w)
|
||||||
sub_impl!(Vec4, Vec4SubRhs, x, y, z, w)
|
sub_impl!(Vec4, Vec4SubRhs, x, y, z, w)
|
||||||
|
mul_impl!(Vec4, Vec4MulRhs, x, y, z, w)
|
||||||
|
div_impl!(Vec4, Vec4DivRhs, x, y, z, w)
|
||||||
neg_impl!(Vec4, x, y, z, w)
|
neg_impl!(Vec4, x, y, z, w)
|
||||||
dot_impl!(Vec4, x, y, z, w)
|
dot_impl!(Vec4, x, y, z, w)
|
||||||
scalar_mul_impl!(Vec4, f64, Vec4MulRhs, x, y, z, w)
|
scalar_mul_impl!(Vec4, f64, Vec4MulRhs, x, y, z, w)
|
||||||
|
@ -558,6 +568,8 @@ container_impl!(Vec5)
|
||||||
basis_impl!(Vec5, Vec5MulRhs, 5)
|
basis_impl!(Vec5, Vec5MulRhs, 5)
|
||||||
add_impl!(Vec5, Vec5AddRhs, x, y, z, w, a)
|
add_impl!(Vec5, Vec5AddRhs, x, y, z, w, a)
|
||||||
sub_impl!(Vec5, Vec5SubRhs, x, y, z, w, a)
|
sub_impl!(Vec5, Vec5SubRhs, x, y, z, w, a)
|
||||||
|
mul_impl!(Vec5, Vec5MulRhs, x, y, z, w, a)
|
||||||
|
div_impl!(Vec5, Vec5DivRhs, x, y, z, w, a)
|
||||||
neg_impl!(Vec5, x, y, z, w, a)
|
neg_impl!(Vec5, x, y, z, w, a)
|
||||||
dot_impl!(Vec5, x, y, z, w, a)
|
dot_impl!(Vec5, x, y, z, w, a)
|
||||||
scalar_mul_impl!(Vec5, f64, Vec5MulRhs, x, y, z, w, a)
|
scalar_mul_impl!(Vec5, f64, Vec5MulRhs, x, y, z, w, a)
|
||||||
|
@ -661,6 +673,8 @@ container_impl!(Vec6)
|
||||||
basis_impl!(Vec6, Vec6MulRhs, 6)
|
basis_impl!(Vec6, Vec6MulRhs, 6)
|
||||||
add_impl!(Vec6, Vec6AddRhs, x, y, z, w, a, b)
|
add_impl!(Vec6, Vec6AddRhs, x, y, z, w, a, b)
|
||||||
sub_impl!(Vec6, Vec6SubRhs, x, y, z, w, a, b)
|
sub_impl!(Vec6, Vec6SubRhs, x, y, z, w, a, b)
|
||||||
|
mul_impl!(Vec6, Vec6MulRhs, x, y, z, w, a, b)
|
||||||
|
div_impl!(Vec6, Vec6DivRhs, x, y, z, w, a, b)
|
||||||
neg_impl!(Vec6, x, y, z, w, a, b)
|
neg_impl!(Vec6, x, y, z, w, a, b)
|
||||||
dot_impl!(Vec6, x, y, z, w, a, b)
|
dot_impl!(Vec6, x, y, z, w, a, b)
|
||||||
scalar_mul_impl!(Vec6, f64, Vec6MulRhs, x, y, z, w, a, b)
|
scalar_mul_impl!(Vec6, f64, Vec6MulRhs, x, y, z, w, a, b)
|
||||||
|
|
|
@ -287,6 +287,28 @@ macro_rules! sub_impl(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
macro_rules! mul_impl(
|
||||||
|
($t: ident, $trhs: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
|
impl<N: Clone + Mul<N, N>> $trhs<N, $t<N>> for $t<N> {
|
||||||
|
#[inline]
|
||||||
|
fn binop(left: &$t<N>, right: &$t<N>) -> $t<N> {
|
||||||
|
$t::new(left.$comp0 * right.$comp0 $(, left.$compN * right.$compN)*)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
macro_rules! div_impl(
|
||||||
|
($t: ident, $trhs: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
|
impl<N: Clone + Div<N, N>> $trhs<N, $t<N>> for $t<N> {
|
||||||
|
#[inline]
|
||||||
|
fn binop(left: &$t<N>, right: &$t<N>) -> $t<N> {
|
||||||
|
$t::new(left.$comp0 / right.$comp0 $(, left.$compN / right.$compN)*)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
macro_rules! neg_impl(
|
macro_rules! neg_impl(
|
||||||
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
impl<N: Clone + Neg<N>> Neg<$t<N>> for $t<N> {
|
impl<N: Clone + Neg<N>> Neg<$t<N>> for $t<N> {
|
||||||
|
|
Loading…
Reference in New Issue