8
8
#include < cmath>
9
9
#include < ostream>
10
10
#include < string>
11
+ #include < type_traits>
11
12
12
13
#include " impeller/geometry/scalar.h"
13
14
#include " impeller/geometry/size.h"
@@ -121,8 +122,9 @@ struct TPoint {
121
122
return {x - static_cast <Type>(s.width ), y - static_cast <Type>(s.height )};
122
123
}
123
124
124
- constexpr TPoint operator *(Scalar scale) const {
125
- return {x * scale, y * scale};
125
+ template <class U , class = std::enable_if_t <std::is_arithmetic_v<U>>>
126
+ constexpr TPoint operator *(U scale) const {
127
+ return {static_cast <Type>(x * scale), static_cast <Type>(y * scale)};
126
128
}
127
129
128
130
constexpr TPoint operator *(const TPoint& p) const {
@@ -134,7 +136,10 @@ struct TPoint {
134
136
return {x * static_cast <Type>(s.width ), y * static_cast <Type>(s.height )};
135
137
}
136
138
137
- constexpr TPoint operator /(Scalar d) const { return {x / d, y / d}; }
139
+ template <class U , class = std::enable_if_t <std::is_arithmetic_v<U>>>
140
+ constexpr TPoint operator /(U d) const {
141
+ return {static_cast <Type>(x / d), static_cast <Type>(y / d)};
142
+ }
138
143
139
144
constexpr TPoint operator /(const TPoint& p) const {
140
145
return {x / p.x , y / p.y };
@@ -175,11 +180,13 @@ struct TPoint {
175
180
return {x / length, y / length};
176
181
}
177
182
178
- constexpr Scalar Cross (const TPoint& p) const {
179
- return (x * p.y ) - (y * p.x );
180
- }
183
+ constexpr Type Cross (const TPoint& p) const { return (x * p.y ) - (y * p.x ); }
181
184
182
- constexpr Scalar Dot (const TPoint& p) const { return (x * p.x ) + (y * p.y ); }
185
+ constexpr Type Dot (const TPoint& p) const { return (x * p.x ) + (y * p.y ); }
186
+
187
+ constexpr TPoint Reflect (const TPoint& axis) const {
188
+ return *this - axis * this ->Dot (axis) * 2 ;
189
+ }
183
190
184
191
constexpr bool IsZero () const { return x == 0 && y == 0 ; }
185
192
};
@@ -226,6 +233,18 @@ constexpr TPoint<F> operator/(const TPoint<I>& p1, const TPoint<F>& p2) {
226
233
return {static_cast <F>(p1.x ) / p2.x , static_cast <F>(p1.y ) / p2.y };
227
234
}
228
235
236
+ // RHS algebraic operations with arithmetic types.
237
+
238
+ template <class T , class U , class = std::enable_if_t <std::is_arithmetic_v<U>>>
239
+ constexpr TPoint<T> operator *(U s, const TPoint<T>& p) {
240
+ return p * s;
241
+ }
242
+
243
+ template <class T , class U , class = std::enable_if_t <std::is_arithmetic_v<U>>>
244
+ constexpr TPoint<T> operator /(U s, const TPoint<T>& p) {
245
+ return {static_cast <T>(s) / p.x , static_cast <T>(s) / p.y };
246
+ }
247
+
229
248
// RHS algebraic operations with TSize.
230
249
231
250
template <class T , class U >
0 commit comments