1
1
// Take a look at the license at the top of the repository in the LICENSE file.
2
2
3
- use std:: fmt;
3
+ use std:: { fmt, ops } ;
4
4
5
5
use glib:: translate:: * ;
6
6
@@ -52,3 +52,83 @@ impl Default for Vec2 {
52
52
Self :: zero ( )
53
53
}
54
54
}
55
+
56
+ // addition/subtraction
57
+ impl ops:: Add < Vec2 > for Vec2 {
58
+ type Output = Vec2 ;
59
+
60
+ fn add ( self , rhs : Vec2 ) -> Self :: Output {
61
+ ( & self ) . add ( & rhs)
62
+ }
63
+ }
64
+ impl ops:: AddAssign < Vec2 > for Vec2 {
65
+ fn add_assign ( & mut self , rhs : Vec2 ) {
66
+ * self = * self + rhs;
67
+ }
68
+ }
69
+ impl ops:: Sub < Vec2 > for Vec2 {
70
+ type Output = Vec2 ;
71
+
72
+ fn sub ( self , rhs : Vec2 ) -> Self :: Output {
73
+ ( & self ) . subtract ( & rhs)
74
+ }
75
+ }
76
+ impl ops:: SubAssign < Vec2 > for Vec2 {
77
+ fn sub_assign ( & mut self , rhs : Vec2 ) {
78
+ * self = * self - rhs;
79
+ }
80
+ }
81
+ impl ops:: Neg for Vec2 {
82
+ type Output = Vec2 ;
83
+
84
+ fn neg ( self ) -> Self :: Output {
85
+ ( & self ) . negate ( )
86
+ }
87
+ }
88
+
89
+ // scalar multiplication
90
+ impl ops:: Mul < f32 > for Vec2 {
91
+ type Output = Vec2 ;
92
+
93
+ fn mul ( self , rhs : f32 ) -> Self :: Output {
94
+ ( & self ) . scale ( rhs)
95
+ }
96
+ }
97
+ impl ops:: MulAssign < f32 > for Vec2 {
98
+ fn mul_assign ( & mut self , rhs : f32 ) {
99
+ * self = * self * rhs;
100
+ }
101
+ }
102
+ impl ops:: Mul < Vec2 > for f32 {
103
+ type Output = Vec2 ;
104
+
105
+ fn mul ( self , rhs : Vec2 ) -> Self :: Output {
106
+ rhs * self
107
+ }
108
+ }
109
+
110
+ // Component-wise multiplication/division
111
+ impl ops:: Mul < Vec2 > for Vec2 {
112
+ type Output = Vec2 ;
113
+
114
+ fn mul ( self , rhs : Vec2 ) -> Self :: Output {
115
+ ( & self ) . multiply ( & rhs)
116
+ }
117
+ }
118
+ impl ops:: MulAssign < Vec2 > for Vec2 {
119
+ fn mul_assign ( & mut self , rhs : Vec2 ) {
120
+ * self = * self * rhs;
121
+ }
122
+ }
123
+ impl ops:: Div < Vec2 > for Vec2 {
124
+ type Output = Vec2 ;
125
+
126
+ fn div ( self , rhs : Vec2 ) -> Self :: Output {
127
+ ( & self ) . divide ( & rhs)
128
+ }
129
+ }
130
+ impl ops:: DivAssign < Vec2 > for Vec2 {
131
+ fn div_assign ( & mut self , rhs : Vec2 ) {
132
+ * self = * self / rhs;
133
+ }
134
+ }
0 commit comments