gfxmath_vec2/impls/mul/
mulassign.rs

1use core::ops::MulAssign;
2use crate::Vec2;
3
4///
5/// ```
6/// use gfxmath_vec2::Vec2;
7/// 
8/// let mut v1 = Vec2::new(1.0, 3.0);
9/// let v2 = Vec2::new(2.0, 5.0);
10/// v1 *= v2;
11/// 
12/// assert_eq!(2.0, v1.x);
13/// assert_eq!(15.0, v1.y);
14/// 
15/// let mut v1 = Vec2::new(9.0, 5.0);
16/// let v2 = Vec2::new(3.5, 2.0);
17/// 
18/// *(&mut v1) *= v2;
19/// 
20/// assert_eq!(31.5, v1.x);
21/// assert_eq!(10.0, v1.y);
22/// ```
23#[opimps::impl_ops_assign(MulAssign)]
24#[inline]
25fn mul_assign<T>(self: Vec2<T>, rhs: Vec2<T>) where T: MulAssign<T> + Copy {
26    self.x *= rhs.x;
27    self.y *= rhs.y;
28}
29
30///
31/// ```
32/// use gfxmath_vec2::Vec2;
33/// 
34/// let mut v1 = Vec2::new(1.0, 3.0);
35/// let v2 = (2.0, 5.0);
36/// v1 *= v2;
37/// 
38/// assert_eq!(2.0, v1.x);
39/// assert_eq!(15.0, v1.y);
40/// 
41/// let mut v1 = Vec2::new(9.0, 5.0);
42/// let v2 = (3.5, 2.0);
43/// 
44/// *(&mut v1) *= v2;
45/// 
46/// assert_eq!(31.5, v1.x);
47/// assert_eq!(10.0, v1.y);
48/// ```
49impl <T> MulAssign<(T, T)> for Vec2<T> where T: MulAssign {
50    #[inline]
51    fn mul_assign(&mut self, rhs: (T, T)) {
52        self.x *= rhs.0;
53        self.y *= rhs.1;
54    }
55}
56
57///
58/// ```
59/// use gfxmath_vec2::Vec2;
60///  
61/// let mut v1 = Vec2::new(9.0, 5.0);
62/// 
63/// v1 *= 2.0;
64/// 
65/// assert_eq!(18.0, v1.x);
66/// assert_eq!(10.0, v1.y);
67/// ```
68#[opimps::impl_op_assign(MulAssign)]
69#[inline]
70fn mul_assign<T>(self: Vec2<T>, rhs: T) where T: MulAssign<T> + Copy {
71    self.x *= rhs;
72    self.y *= rhs;
73}