88#include < cmath>
99#include < ostream>
1010#include < string>
11+ #include < type_traits>
1112
1213#include " impeller/geometry/scalar.h"
1314#include " impeller/geometry/size.h"
@@ -121,8 +122,9 @@ struct TPoint {
121122 return {x - static_cast <Type>(s.width ), y - static_cast <Type>(s.height )};
122123 }
123124
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)};
126128 }
127129
128130 constexpr TPoint operator *(const TPoint& p) const {
@@ -134,7 +136,10 @@ struct TPoint {
134136 return {x * static_cast <Type>(s.width ), y * static_cast <Type>(s.height )};
135137 }
136138
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+ }
138143
139144 constexpr TPoint operator /(const TPoint& p) const {
140145 return {x / p.x , y / p.y };
@@ -175,11 +180,13 @@ struct TPoint {
175180 return {x / length, y / length};
176181 }
177182
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 ); }
181184
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+ }
183190
184191 constexpr bool IsZero () const { return x == 0 && y == 0 ; }
185192};
@@ -226,6 +233,18 @@ constexpr TPoint<F> operator/(const TPoint<I>& p1, const TPoint<F>& p2) {
226233 return {static_cast <F>(p1.x ) / p2.x , static_cast <F>(p1.y ) / p2.y };
227234}
228235
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+
229248// RHS algebraic operations with TSize.
230249
231250template <class T , class U >
0 commit comments