gfxmath_vec2/impls/div/divassign.rs
1use core::ops::DivAssign;
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!(0.5, v1.x);
13/// assert_eq!(0.6, v1.y);
14///
15/// let mut v1 = Vec2::new(9.0, 5.0);
16/// let v2 = Vec2::new(2.5, 2.0);
17///
18/// *(&mut v1) /= v2;
19///
20/// assert_eq!(3.6, v1.x);
21/// assert_eq!(2.5, v1.y);
22/// ```
23#[opimps::impl_ops_assign(DivAssign)]
24#[inline]
25fn div_assign<T>(self: Vec2<T>, rhs: Vec2<T>) where T: DivAssign<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!(0.5, v1.x);
39/// assert_eq!(0.6, v1.y);
40///
41/// let mut v1 = Vec2::new(9.0, 5.0);
42/// let v2 = (2.5, 2.0);
43///
44/// *(&mut v1) /= v2;
45///
46/// assert_eq!(3.6, v1.x);
47/// assert_eq!(2.5, v1.y);
48/// ```
49impl <T> DivAssign<(T, T)> for Vec2<T> where T: DivAssign {
50 #[inline]
51 fn div_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!(4.5, v1.x);
66/// assert_eq!(2.5, v1.y);
67/// ```
68#[opimps::impl_op_assign(DivAssign)]
69#[inline]
70fn div_assign<T>(self: Vec2<T>, rhs: T) where T: DivAssign<T> + Copy {
71 self.x /= rhs;
72 self.y /= rhs;
73}