1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use crate::Vec3;
use core::ops::Mul;

/// ```
/// use gfxmath_vec3::Vec3;
/// 
/// let mut a = Vec3::<f32>::new(1.5, 2.5, -2.0);
/// let b = Vec3::<f32>::new(4.0, 2.0,  4.0);
/// let c = Vec3::from(&a * &b);
/// 
/// a.x = 2.0;
/// 
/// assert_eq!( 6.0, c.x);
/// assert_eq!( 5.0, c.y);
/// assert_eq!(-8.0, c.z);
/// 
/// let c = Vec3::from(a * b);
///
/// assert_eq!( 8.0, c.x);
/// assert_eq!( 5.0, c.y);
/// assert_eq!(-8.0, c.z);
/// ```
#[opimps::impl_ops(Mul)]
#[inline]
fn mul<T>(self: Vec3<T>, rhs: Vec3<T>) -> Vec3<T> where T: Mul<Output = T> + Copy {
    let l = self.as_slice();
    let r = rhs.as_slice();
    Vec3::new(
        l[0] * r[0],
        l[1] * r[1],
        l[2] * r[2],
    )
}

/// Scalar multiplication with vector
/// 
/// ```
/// use gfxmath_vec3::Vec3;
/// 
/// let a = Vec3::<f32>::new(0.5, 2.5, -2.5);
/// let b = Vec3::from(a * 2.0);
/// 
/// assert_eq!( 1.0, b.x);
/// assert_eq!( 5.0, b.y);
/// assert_eq!(-5.0, b.z);
/// ```
#[opimps::impl_ops_rprim(Mul)]
fn mul<T>(self: Vec3<T>, rhs: T) -> Vec3<T> where T: Mul<Output = T> + Copy {
    return Vec3::new(self.x * rhs, self.y * rhs, self.z * rhs);
}

/// Scalar multiplication with vector
/// 
/// ```
/// use gfxmath_vec3::Vec3;
/// 
/// let a = Vec3::<f32>::new(0.5, 2.5, -2.5);
/// let b = Vec3::from(2.0 * a);
/// 
/// assert_eq!( 1.0, b.x);
/// assert_eq!( 5.0, b.y);
/// assert_eq!(-5.0, b.z);
/// ```
#[opimps::impl_ops_lprim(Mul)]
fn mul(self: f32, rhs: Vec3<f32>) -> Vec3<f32> {
    return Vec3::new(self * rhs.x, self * rhs.y, self * rhs.z);
}

/// Scalar multiplication with vector
/// 
/// ```
/// use gfxmath_vec3::Vec3;
/// 
/// let a = Vec3::<f64>::new(0.5, 2.5, -2.5);
/// let b = Vec3::from(2.0 * a);
/// 
/// assert_eq!( 1.0, b.x);
/// assert_eq!( 5.0, b.y);
/// assert_eq!(-5.0, b.z);
/// ```
#[opimps::impl_ops_lprim(Mul)]
fn mul(self: f64, rhs: Vec3<f64>) -> Vec3<f64> {
    return Vec3::new(self * rhs.x, self * rhs.y, self * rhs.z);
}

/// Scalar multiplication with vector
/// 
/// ```
/// use gfxmath_vec3::Vec3;
/// 
/// let a = Vec3::<i32>::new(5, 2, -2);
/// let b = Vec3::from(2 * a);
/// 
/// assert_eq!( 10, b.x);
/// assert_eq!( 4, b.y);
/// assert_eq!(-4, b.z);
/// ```
#[opimps::impl_ops_lprim(Mul)]
fn mul(self: i32, rhs: Vec3<i32>) -> Vec3<i32> {
    return Vec3::new(self * rhs.x, self * rhs.y, self * rhs.z);
}

/// Scalar multiplication with vector
/// 
/// ```
/// use gfxmath_vec3::Vec3;
/// 
/// let a = Vec3::<i64>::new(5, 2, -2);
/// let b = Vec3::from(2 * a);
/// 
/// assert_eq!( 10, b.x);
/// assert_eq!( 4, b.y);
/// assert_eq!(-4, b.z);
/// ```
#[opimps::impl_ops_lprim(Mul)]
fn mul(self: i64, rhs: Vec3<i64>) -> Vec3<i64> {
    return Vec3::new(self * rhs.x, self * rhs.y, self * rhs.z);
}
// End of scalar multiplication