gfxmath_vec2/impls/mul/
mul.rs

1use core::ops::Mul;
2use crate::Vec2;
3
4/// ```
5/// use gfxmath_vec2::Vec2;
6/// 
7/// let mut a = Vec2::<f32>::new(1.5, 2.5);
8/// let b = Vec2::<f32>::new(4.0, 2.0);
9/// let c = &a * &b;
10/// 
11/// a.x = 2.0;
12/// 
13/// assert_eq!( 6.0, c.x);
14/// assert_eq!( 5.0, c.y);
15/// 
16/// let c = a * b;
17///
18/// assert_eq!( 8.0, c.x);
19/// assert_eq!( 5.0, c.y);
20/// ```
21#[opimps::impl_ops(Mul)]
22#[inline]
23fn mul<T>(self: Vec2<T>, rhs: Vec2<T>) -> Vec2<T> where T: Mul<Output = T> + Copy {
24    Vec2 { x: self.x * rhs.x, y: self.y * rhs.y }
25}
26
27/// Scalar multiplication with vector
28/// 
29/// ```
30/// use gfxmath_vec2::Vec2;
31/// 
32/// let a = Vec2::<f32>::new(0.5, 2.5);
33/// let b = Vec2::from(a * 2.0);
34/// 
35/// assert_eq!( 1.0, b.x);
36/// assert_eq!( 5.0, b.y);
37/// ```
38#[opimps::impl_ops_rprim(Mul)]
39#[inline]
40fn mul<T>(self: Vec2<T>, rhs: T) -> Vec2<T> where T: Mul<Output = T> + Copy {
41    Vec2 { x: self.x * rhs, y: self.y * rhs}
42}
43
44/// Scalar multiplication with vector
45/// 
46/// ```
47/// use gfxmath_vec2::Vec2;
48/// 
49/// let a = Vec2::<f32>::new(0.5, 2.5);
50/// let b = 2.0 * a;
51/// 
52/// assert_eq!( 1.0, b.x);
53/// assert_eq!( 5.0, b.y);
54/// ```
55#[opimps::impl_ops_lprim(Mul)]
56#[inline]
57fn mul(self: f32, rhs: Vec2<f32>) -> Vec2<f32> {
58    Vec2 { x: self * rhs.x, y: self * rhs.y }
59}
60
61/// Scalar multiplication with vector
62/// 
63/// ```
64/// use gfxmath_vec2::Vec2;
65/// 
66/// let a = Vec2::<f64>::new(0.5, 2.5);
67/// let b = 2.0 * a;
68/// 
69/// assert_eq!( 1.0, b.x);
70/// assert_eq!( 5.0, b.y);
71/// ```
72#[opimps::impl_ops_lprim(Mul)]
73#[inline]
74fn mul(self: f64, rhs: Vec2<f64>) -> Vec2<f64> {
75    Vec2 { x: self * rhs.x, y: self * rhs.y }
76}
77
78/// Scalar multiplication with vector
79/// 
80/// ```
81/// use gfxmath_vec2::Vec2;
82/// 
83/// let a = Vec2::<i32>::new(5, 2);
84/// let b = 2 * a;
85/// 
86/// assert_eq!( 10, b.x);
87/// assert_eq!( 4, b.y);
88/// ```
89#[opimps::impl_ops_lprim(Mul)]
90#[inline]
91fn mul(self: i32, rhs: Vec2<i32>) -> Vec2<i32> {
92    Vec2 { x: self * rhs.x, y: self * rhs.y }
93}
94
95/// Scalar multiplication with vector
96/// 
97/// ```
98/// use gfxmath_vec2::Vec2;
99/// 
100/// let a = Vec2::<i64>::new(5, 2);
101/// let b = 2 * a;
102/// 
103/// assert_eq!( 10, b.x);
104/// assert_eq!( 4, b.y);
105/// ```
106#[opimps::impl_ops_lprim(Mul)]
107#[inline]
108fn mul(self: i64, rhs: Vec2<i64>) -> Vec2<i64> {
109    Vec2 { x: self * rhs.x, y: self * rhs.y }
110}